如果您遇到了void_t包装器导致的编译错误,您可以使用回退方法来解决它。以下是示例代码:
#include
template
using void_t = void;
template>
struct has_typedef : std::false_type {};
template
struct has_typedef> : std::true_type {};
struct A { using typedef_name = int; };
struct B {};
static_assert(has_typedef::value, "A should have the typedef_name");
static_assert(!has_typedef::value, "B should not have the typedef_name");
template
struct has_member : std::false_type {};
template
struct has_member> : std::true_type {};
struct C { int member; };
struct D {};
static_assert(has_member::value, "C should have the member");
static_assert(!has_member::value, "D should not have the member");
在这里,我们使用了void_t包装器来帮助确定是否具有typedef_name和member成员。但是,如果void-t包装器导致了编译时错误,则使用回退方法。在这个示例中,如果void_t未导致编译时错误,则void_t将被使用。