21
はこのC++ 11のプログラムを考えてみましょう。奇妙な振る舞い
標準的な動作ですか?標準では正確にどこを指定していますか(Wrap1
とWrap2
)?
この質問の一部は、this other questionからインスピレーションを受けています。
はこのC++ 11のプログラムを考えてみましょう。奇妙な振る舞い
標準的な動作ですか?標準では正確にどこを指定していますか(Wrap1
とWrap2
)?
この質問の一部は、this other questionからインスピレーションを受けています。
Wrap2クラスでは、 "クラスC"(デフォルトの "int"パラメータを含む)で指定されたすべてのパラメータが "class ... E"で置換されるため、 "Wrap2 w2"構造体Contのパラメータ。
パラメータパックはクラスCのすべてのパラメータを置き換えたので、Cのデフォルトパラメータはここでは機能しませんでした。
#include <iostream>
#include <typeinfo>
template <class A=char, class B = short, class C = int> struct MyTest
{
MyTest()
{
std::cout << sizeof(A) << " " << typeid(A).name() << " ";
std::cout << sizeof(B) << " " << typeid(B).name() << " ";
std::cout << sizeof(C) << " " << typeid(C).name() << std::endl;
}
};
template <template<class = double, class = double, class = double> class D, class E, class... F> class Wrap
{
D<E> de; // the parameters of D is: E + default parameters of D.
D<F...> df; // the parameters of D is: F... + default parameters of MyTest, the default parameter of D don't work, it will be replaced by pack F.
};
int main()
{
Wrap<MyTest, int, int> w;
}
//g++ 5.4.0
//output:
//4 i 8 d 8 d
//4 i 2 s 4 i
私は何が起こるか見ることができます、私は標準でこの動作が定義されているかを尋ねています。 –
ICCとMSVCが「44」を生成する。私はバグに行くつもりです。 –
コンパイラの実装に固有のものだとします。 –