Consider the following code that tries to determine the existence of a nested typedef.
#include<type_traits>
struct foo;
template<class T>
struct seq
{
using value_type = T;
};
struct no_type{};
template<class T>
struct check_type : std::true_type{};
template<>
struct check_type<no_type> :std::false_type{};
template<class T>
struct has_value_type
{
template<class U>
static auto check(U const&)-> typename U:: value_type;
static auto check(...)->no_type;
static bool const value = check_type<decltype(check(std::declval<T>()))>::value;
using type = has_value_type;
};
int main()
{
char c[has_value_type<seq<foo>>::value?1:-1];
(void)c;
}
The call has_value_type<seq>::valuecauses a compilation error as an invalid use of an incomplete type seq<foo>::value_type.
decltypeneed a full type of expression? If not, how to remove the error? I am using gcc 4.7 to compile.
source
share