这段检测默认运算符的代码为什么从来不选择特化部分是有原因的吗?

问题描述 投票:0回答:0

此代码始终打印 0,我不明白为什么。我错过了什么吗?

#include<iostream>
#include<type_traits>

template <class T, typename = void>
        struct has_default_operator: std::false_type {};

template <typename T>
        struct has_default_operator<T, std::void_t<decltype(std::declval<T>()())>> : std::true_type {};


class Entity{
public:
    Entity() = default;
};

int main(){
    std::cout<< has_default_operator<Entity>::value;
}

当有默认操作符时,代码应该打印 1

template-meta-programming default-constructor partial-specialization class-template
© www.soinside.com 2019 - 2024. All rights reserved.