部分的な特殊化を行いながら、内部クラスの実装を分離することに問題があります。これが私の問題を説明するサンプルコードです:
#include <type_traits>
template <typename T>
using enable_if_copyable = std::enable_if_t<std::is_copy_constructible<T>::value>;
template <typename T>
using enable_if_not_copyable = std::enable_if_t<!std::is_copy_constructible<T>::value>;
template <typename T, typename Enabled=void>
struct Foo;
template <typename T>
struct Foo<T, enable_if_copyable<T>>
{
struct Bar
{
Bar();
};
};
template <typename T>
struct Foo<T, enable_if_not_copyable<T>> {
struct Bar
{
Bar();
};
};
template <>
struct Foo<void,void>
{
struct Bar
{
Bar();
//Bar() {} This compiles, but it is not what I want.
};
};
template <typename T>
Foo<T, enable_if_copyable<T>>::Bar::Bar()
{}
template <typename T>
Foo<T, enable_if_not_copyable<T>>::Bar::Bar()
{}
template <>
Foo<void, void>::Bar::Bar() // this does not compile
{}
int main() {
Foo<int>::Bar b;
Foo<void>::Bar v;
}
依存関係があるためBar
、宣言の外部のc'torを実装する必要があります。私の問題は、すべてのコンパイラ(Clang、gcc、Visual Studio 2015)Foo<void, void>::Bar::Bar() {}
がの宣言の外側の実装について文句を言うことですclass Foo<void, void>
。スペシャライゼーションBar
内のc'torを実装すればvoid
、問題ありません。これは実行不可能ですか、それとも私の問題を見つけるのを手伝ってくれる人がいますか?よろしくお願いします!
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加