The code is below (it compiles fine with clang and gcc). The question is, does this code violate the C ++ 03 standard, or is it a VS 2005 error? And if it's a mistake, any work around?
Update: I found a workaround using a forward declaration:
//forward declaration template<typename T, bool IsAcceptedType = Filter::template Acceptor<T>::IsAccepted> struct FilteredConstructor; //implementation template<typename T> class FilteredConstructor<T, true> {/*code here*/};
But the question of whether this code is valid or invalid according to the standard is still here
namespace { struct CoreTypesFilter { template<typename T> struct Acceptor { static const bool IsAccepted = false; }; }; } template<class Filter> class QVariantConstructor { template<typename T, bool IsAcceptedType = Filter::template Acceptor<T>::IsAccepted> struct FilteredConstructor { FilteredConstructor(const QVariantConstructor &tc) {} }; template<typename T> struct FilteredConstructor<T, /* IsAcceptedType = */ false> { FilteredConstructor(const QVariantConstructor &tc) {} }; public: template<typename T> void delegate(const T*) { FilteredConstructor<T> tmp(*this); } };
Compilation errors of the VS 2005 compiler:
error C2976: 'QVariantConstructor :: FilteredConstructor': too few template arguments
1> with
1> [
1> Filter = `anonymous-namespace ':: CoreTypesFilter
1>]
1> see declaration of 'QVariantConstructor :: FilteredConstructor'
1> with
1> [
1> Filter = `anonymous-namespace ':: CoreTypesFilter
1>]
1> see reference to function template instantiation 'void QVariantConstructor :: delegate (const T *)' being compiled
1> with
1> [
1> Filter = `anonymous-namespace ':: CoreTypesFilter,
1> T = char
1>]
1> error C2514: 'QVariantConstructor :: FilteredConstructor': class has no constructors
1> with
1> [
1> Filter = `anonymous-namespace ':: CoreTypesFilter
1>]
1> see declaration of 'QVariantConstructor :: FilteredConstructor'
1> with
1> [
1> Filter = `anonymous-namespace ':: CoreTypesFilter
1>]
source share