相关疑难解决方法(0)

什么是模板推导中的部分排序程序

阅读C++ 11标准我无法完全理解以下语句的含义.例子非常受欢迎.

两组类型用于确定部分排序.对于涉及的每个模板,都有原始函数类型和转换后的函数类型.[注意:转换类型的创建在14.5.6.2中描述. - 结束注释]演绎过程使用变换后的类型作为参数模板,将另一个模板的原始类型用作参数模板.对于部分排序比较中涉及的每种类型,此过程完成两次:一次使用转换的模板-1作为参数模板,使用template-2作为参数模板,再次使用转换的模板-2作为参数模板和模板-1作为参数模板
- N3242 14.8.2.4.2

c++ templates partial-ordering c++11 template-argument-deduction

34
推荐指数
1
解决办法
3210
查看次数

为什么匹配模板类上的部分类模板特化与另一个没有模板匹配的部分专业模棱两可?

这个问题可能很难在标题中的句子中描述,但这是一个最小的示例:

#include <iostream>
#include <type_traits>

template <class T, class U, class Enabler>
struct my_trait : std::false_type
{};

template <class T, class U>
struct my_trait<T, U, 
                std::enable_if_t<std::is_same<T, U>::value>> : std::true_type
{};

template <class T>
class temped
{};

template <class T>
struct my_trait<temped<T>, temped<T>, void> : std::false_type
{};

template <class T, class U>
using trait_t = my_trait<T, U, void>;

int main()
{
    std::cout << std::boolalpha;
    std::cout << trait_t<int, float>::value << std::endl;   // false
    std::cout << trait_t<int, int>::value << std::endl;     // true

    // …
Run Code Online (Sandbox Code Playgroud)

c++ templates sfinae template-specialization

6
推荐指数
1
解决办法
99
查看次数