小编ell*_*sis的帖子

为什么不选择模板专业化?

我写了以下代码:

#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;
}
Run Code Online (Sandbox Code Playgroud)

当我跑它,我得到0 0.但我期待0 1.

有任何想法吗?

c++ sfinae c++11

13
推荐指数
1
解决办法
603
查看次数

标签 统计

c++ ×1

c++11 ×1

sfinae ×1