2012-09-18

機能的に同一だが、同一ではない関数テンプレート

テンプレート仮引数が関数テンプレートの仮引数リストや戻り値の型の式の中で参照されている場合、式は関数テンプレートのシグネチャの一部となる。

template < int I >
struct X { } ;

template < int I, int J >
X< I + J > f( X<I>, X<J> ) ; // #1の宣言

template < int K, int L >
X< K + L > f( X<K>, X<L> ) ; // #1の再宣言

template < int I, int J >
X< I - J > f( X<I>, X<J> ) ; // #2、これは#1とは異なる宣言

この時、式を評価した結果が同じだが、式が同一ではないものを、「機能的に同一だが同一ではない」という。機能的に同一だが同一ではない二つの宣言がある場合、ill-formedとなる。no diagnostic is required.

template < int I >
struct X { } ;

template < int I >
void f( X< I + 10 > ) ;

template < int I >
void f( X< I + 1 + 2 + 3 + 4 > ) ; // ill-formed

規格にもあるように、これを判定したり、エラー表示したり警告を出したりする必要はない。私の知る限り、これを判定するC++コンパイラーはない。

No comments:

Post a Comment

You can use some HTML elements, such as <b>, <i>, <a>, also, some characters need to be entity referenced such as <, > and & Your comment may need to be confirmed by blog author. Your comment will be published under GFDL 1.3 or later license with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.