I have a problem similar to this one: SFINAE tried with bool gives compiler error: "template argument ‘T::value’ involves template parameter"
I want to define a trait that tells if a complex representation is an array of structs, where real values are never AoS hence no user defined specilization should be required, but for complex you'd always need one:
/**
* Evaluates to a true type if the given complex type is an Array of Structs, false otherwise
* Defaults to false for Real values
*/
template< typename T, bool T_isComplex = IsComplex<T>::value >
struct IsAoS: std::false_type{};
/**
* Undefined for (unknown) complex types
*/
template< typename T >
struct IsAoS< T, true >;
Specializations are done in the std-way by deriving from std::true/false_type.
The problem is: With this implementation I get the "template argument involves template parameter(s)" error (which is explained in the linked question) but if i switch to types (ommit "::value" in first template and change true to true_type in 2nd) Complex types won't match the 2nd template anymore because the only derive from std::true_type and ARE NOT std::true_type.
Only solution I can think of is using expression SFINAE and change the 2nd parameter of the main template to default void and an enable_if for the real case (isComplex==false). Anything better?
struct IsAoS< std::complex<T> >
and use the default template argument of the primary template to fill in the second argument for that partial specialization, because that depends onT
and so is not allowed. (The code snippet that causes an error should really be in your question.) What's the desired behavior - defaults tofalse_type
, unlessIsComplex<T>::value
istrue
, in which case it should be an error unless the user provides a specialization?