首页 > TAG信息列表 > enable-if

c-通过参数启用std :: enabled_if时如何工作

我正在尝试了解enable_if的工作原理,并且我几乎了解除了场景3中的所有内容 https://en.cppreference.com/w/cpp/types/enable_if template<class T> void destroy(T* t, typename std::enable_if<std::is_trivially_destructible<T>::value>::type* = 0) { std::c

c – enable_if和转换运算符?

有没有机会将enable_if与类型转换运算符一起使用?看起来很棘手,因为返回类型和参数列表都是隐式的.解决方法:dixit documentation: 似乎没有办法为转换运算符指定启用码.但是,转换构造函数可以将启用程序作为额外的默认参数.

c – template中的enable_if参数创建模板重定义错误

在this answer我真正想要做的是在我的模板参数中定义一个typename,可以在cast和return中使用. 所以这: template <typename T> typename std::enable_if<sizeof(unsigned char) == sizeof(T), unsigned char>::type caster(T value){ return reinterpret_cast<unsigned char&>(valu

c – 为什么SFINAE(enable_if)不适用于类模板的成员函数?

#include <type_traits> struct A{}; struct B{}; template <typename T> struct Foo { typename std::enable_if<std::is_same<T, A>::value>::type bar() {} typename std::enable_if<std::is_same<T, B>::value>::

带有std :: is_reference的c – std :: enable_if无法编译

就像std :: reference_wrapper使用封面下的指针来存储“引用”一样,我试图用以下代码做类似的事情. #include <type_traits> struct Foo { void* _ptr; template<typename T> Foo(T val, typename std::enable_if < std::is_re

c – 如何使用默认模板参数分隔模板化类的声明和实现?

我喜欢将我的类的声明和实现分开.我知道类模板和函数的实现也必须进入头文件,这不是问题. 我在实现这个课时遇到了麻烦: template <size_t S, std::enable_if_t<(S > 0), int> = 0> class Foo { public: Foo(); } 到目前为止,我尝试过: template<size_t S> Foo<S>::Foo() {}

c – 使用enable_if将数字作为函数参数进行匹配

我想使用std :: enable_if来构造匹配数字的构造函数.我尝试了以下代码,但找不到构造函数.主要功能有我想要如何使用它的例子.我应该改变什么来使这项工作? #include <type_traits> #include <string> class A { public: A(const std::wstring&, const std::wstring&) {}

C boost enable_if问题

我有什么方法可以简化以下陈述吗? (可能,使用boost :: enable_if). 我有一个简单的类结构 – 基础类,Derived1,Derived2继承自Base. 我有以下代码: template <typename Y> struct translator_between<Base, Y> { typedef some_translator<Base, Y> type; }; template <typename

c – 如何使这个boost :: enable_if代码编译(SFINAE)?

我很困惑为什么以下使用boost :: enable_if的代码无法编译.它检查类型T是否具有成员函数hello,如果是这种情况则调用它: #include <iostream> #include <boost/utility/enable_if.hpp> #include <boost/static_assert.hpp> // Has_hello<T>::value is true if T has a hello funct