IT戦記 このページをアンテナに追加 RSSフィード

2008-10-05

テンプレートのメンバ関数がインスタンス化される箇所

以下のエントリで色々と勉強になりました

クラステンプレートの具現化の位置 - hattorix0の日記

ありがとうございます!

重要なのは以下の箇所

For a function template specialization, a member function template specialization, or a specialization for a member function or static data member of a class template, if the specialization is implicitly instantiated because it is referenced from within another template specialization and the context from which it is referenced depends on a template parameter, the point of instantiation of the specialization is the point of instantiation of the enclosing specialization. Otherwise, the point of instantiation for such a specialization immediately follows the namespace scope declaration or definition that refers to the specialization.

ISO/IEC 14882:1998(E) -- C++ -- Templates

ただ、この文章

For a function template specialization, a member function template specialization, or a specialization for a member function or static data member of a class template
    - if the specialization is implicitly instantiated because it is referenced from within another template specialization and the context from which it is referenced depends on a template parameter, the point of instantiation of the specialization is the point of instantiation of the enclosing specialization.
    - Otherwise, the point of instantiation for such a specialization immediately follows the namespace scope declaration or definition that refers to the specialization. 

という意味なのか

    - For a function template specialization, a member function template specialization, or a specialization for a member function or static data member of a class template, if the specialization is implicitly instantiated because it is referenced from within another template specialization and the context from which it is referenced depends on a template parameter, the point of instantiation of the specialization is the point of instantiation of the enclosing specialization. 
    - Otherwise, the point of instantiation for such a specialization immediately follows the namespace scope declaration or definition that refers to the specialization. 

という意味なのか

For a function template specialization, a member function template specialization, or a specialization for a member function or static data member of a class template

の文が、最初の文章だけにかかるのか、段落全体にかかるのか、が分からない。

その後に続く文章の感じからすると後者かなあ。

あ、ひょっとして

such a specialization

ってのが

For a function template specialization, a member function template specialization, or a specialization for a member function or static data member of a class template

のことなのか!なるほど!

such! such!

hattorix0hattorix0 2008/10/07 00:29 初めまして。
初エントリでまだ慣れていなく、あれこれいじっていたら
三つもトラックバックしてしまっていました。。。
すいません。

具現化の位置の仕様については、自分もこの内容と同じ理解です。
参考までに JIS X 3014:2003 から、同じ部分を抜粋しました〜。

「関数テンプレート特殊化,メンバ関数テンプレート特殊化 又は クラステンプレートのメンバ関数 若しくは クラステンプレートの静的データメンバの特殊化では,その特殊化が別のテンプレート特殊化の中で参照され,かつ,その文脈がテンプレート仮引数に従属しており,そのためそれが暗黙に具現された場合,その具現化の位置は,それを囲む特殊化の具現化の位置とする。そうでない場合,その特殊化の具現化の位置は,その特殊化を参照する,名前空間有効範囲の宣言 又は 定義の直後とする。」

amachangamachang 2008/10/07 09:11 コメントありがとうございます!
なるほど、日本語でも比較的分かり易く書かれていますね!

なるほどです。納得しました。

はてなユーザーのみコメントできます。はてなへログインもしくは新規登録をおこなってください。

トラックバック - http://d.hatena.ne.jp/amachang/20081005/1223225282