新しい質問
編集
このバグはこれと同じようです:
MSVC は次のコードを拒否します。
template <template <typename T, typename T::mytype x> class X>
struct z
{};
template <typename T, typename T::mytype xx>
struct x
{};
z<x> zz;
エラー C3201: クラス テンプレート 'x' のテンプレート パラメーター リストが、テンプレート パラメーター 'X' のテンプレート パラメーター リストと一致しません
ただし、クラス テンプレート x には、パラメーター X と同じ一連のテンプレート パラメーターがあります。
地獄!このバグ レポートは 2012 年 4 月のものですか?!
と
ステータス: 延期としてクローズ
:(
マイクロソフト、残念です TT
編集の編集
私の場合 (以下)、自分のやりたいことをハックすることができますが、それは醜いです:
//Library code
struct Boundary {
double sup, inf;
};
template <
class UserBoundaries,
template <size_t, bool...> class LocalInfo,
size_t hack>
struct Space_LocalParameters : LocalInfo<hack> {};
//User code
struct Boundaries_Problem7 {
Boundary b1, b2, b3;
};
template <size_t, bool...>
struct LocalInfo_Problem7 {};
template <size_t hack, bool... args>
struct Problem7_Functions
: Space_LocalParameters < Boundaries_Problem7, LocalInfo_Problem7, hack, args...> {};
int main() {}
使用する:
//Compute the offset of member b2 in Boundaries_Problem7
const size_t hack = (size_t)(&((Boundaries_Problem7*)0)->b2);
if (...)
problem.functions[k].SetFunction(&Problem7_Functions<hack, true, false>::f);
else if (...)
problem.functions[k].SetFunction(&Problem7_Functions<hack, false, true>::f);
else problem.functions[k].SetFunction(&Problem7_Functions<hack, false, false>::f);
//Later in that function
if (boundary_Inf) {
value += this->points[0].coef
* ((Boundary*)((char*)&domain.boundaries + hack))->inf;
}
if (boundary_Sup) {
value += this->points[N-1].coef
* ((Boundary*)((char*)&domain.boundaries + hack))->sup;
}
コンパイラは、最適化中にメンバーのオフセットを変更できますか?
編集の終わり
新しい質問
以下はhttp://coliru.stacked-crooked.com/a/be088e06861f9349で問題なくコンパイルされます
//Library code
struct Boundary {};
template <
class UserBoundaries,
template <Boundary UserBoundaries::*> class LocalInfo,
Boundary UserBoundaries::*m_ptr>
struct Space_LocalParameters : LocalInfo<m_ptr> {};
//User code
struct Boundaries_Problem7 {
Boundary b1, b2, b3;
};
template <Boundary Boundaries_Problem7::*m_ptr>
struct LocalInfo_Problem7 {};
template <Boundary Boundaries_Problem7::*ptr>
struct Problem7_Functions
: Space_LocalParameters < Boundaries_Problem7, LocalInfo_Problem7, ptr> {}; // <-- C3201
int main() {}
しかし、Visual Studio 2013 では次のエラーが表示されます。
エラー C3201: クラス テンプレート 'LocalInfo_Problem7' のテンプレート パラメーター リストが、テンプレート パラメーター 'LocalInfo' のテンプレート パラメーター リストと一致しません
これは VS コンパイラのバグですか? それとも私のコードが間違っていますか?
これがバグである場合、どうすればこれを機能させることができますか?
ご協力いただきありがとうございます。
古い質問
少し複雑なテンプレート「typedef」に問題があります。
問題をできるだけ単純化して、私はこれを思いつきました:
template <class A, template <A*> class B, A* ptr>
struct Foo : B<ptr> {};
template <class, class AA, template <AA*> class BB, AA* ptr>
using Bar = Foo<AA, BB, ptr>; // <-- C3201
Visual Studio 2013 でエラー C3201: クラス テンプレート 'BB' のテンプレート パラメーター リストがテンプレート パラメーター 'B' のテンプレート パラメーター リストと一致しません
何が悪いのかわかりません。
Foo<AA, BB, ptr>
「に展開します」template <class AA, template <AA*> class BB, AA* ptr> struct Foo : BB<ptr> {}
理論的には、次のように定義すると (実際には以下をコンパイルしようとはしませんでした):
class MyClass {} myClass_instance;
template <MyClass*> class MyTemplateClass {};
それで
Bar<whatever, MyClass, MyTemplateClass, &myClass_instance>
のエイリアスにする必要があります
Foo<MyClass, MyTemplateClass, &myClass_instance> : MyTemplateClass<&myClass_instance>
これは私には問題ないように見えます。
興味深いことに、次の 2 つのバリエーションは正常にコンパイルされます。
1/着替えtemplate <A*>
てtemplate <AA*>
とtemplate <Z*>
class Z;
template <class A, template <Z*> class B, A* ptr>
struct Foo : B<ptr> {};
template <class, class AA, template <Z*> class BB, AA* ptr>
using Bar = Foo<AA, BB, ptr>;
この回避策により、私のプログラムは正常に実行されましたが、これは私のテンプレート アプローチの目的を無効にします。
または 2/ Bar の最初のテンプレート パラメータを削除する
template <class A, template <A*> class B, A* ptr>
struct Foo : B<ptr> {};
template <class AA, template <AA*> class BB, AA* ptr>
using Bar = Foo<AA, BB, ptr>;
では、コンパイラによって言及された不一致は何ですか?
Bar の最初のテンプレート パラメータを削除すると、どのように問題が解決するのでしょうか?
ご協力いただきありがとうございます。