I have a Writer struct to do some serialization
template<typename T>
struct Writer {}; // only specialized version has ::wrap_t
template<>
struct Writer <int> {
typedef int wrap_t;
};
template <typename T>
using Writer_wrap_t = typename Writer<T>::wrap_t;
template<>
struct Writer<float> {
typedef float wrap_t;
};
And I want to know whether a type has a specialized Writer. The code does not work as expect:
template<typename T, typename U = Writer_wrap_t <T>>
struct has_writer : std::true_type {};
template<typename T>
struct has_writer<T, void> : std::false_type {};
int main() {
bool b = has_writer <double>::value;
// error C2794: 'wrap_t': is not a member of any direct or indirect base class of 'Writer<T>'
// error C2976: 'has_reflect': too few template arguments
// error C2938: 'Writer_wrap_t ' : Failed to specialize alias template
}
I suppose that has_writer<double> didn't use the specialized version struct has_writer<T, void> : std::false_type {};?
But now there is a substitution failure for the first one, shouldn't the compiler try to instantiate the second version?