【发布时间】:2017-07-01 07:17:42
【问题描述】:
我写了以下代码:
#include <iostream>
#include <string>
#include <type_traits>
template<typename, typename = void>
struct is_incrementable : std::false_type {};
template<typename T>
struct is_incrementable<T, decltype( ++std::declval<T&>() )> : std::true_type {};
int main()
{
std::cout << is_incrementable<std::string>::value << std::endl;
std::cout << is_incrementable<int>::value << std::endl;
}
当我运行它时,我得到0 0。但我期待0 1。
有什么想法吗?
【问题讨论】:
-
这是std::void_t的地方。
-
此外,void_t 的文档恰好有这种类型的代码作为示例,请参阅en.cppreference.com/w/cpp/types/void_t
has_pre_increment_member的代码