std ::有条件的编译时间继承与std :: enable_if for编译时间方法
我想设计一个模板类,其中有两个参数,这些参数是根据模板参数在汇编时间上的两个参数,这是两个相互排斥的基类之一。 我想对我来说很简单,所以提出…
了解C++ 98中的Enable_if实现
我已经将其视为 enable_if for c ++ 98 的自称实现: template struct enable_if { typedef T type; }; template struct enable_if {}; 但是,我个人…
为什么在enable_if模板构造函数中的可选参数可以帮助编译器推断模板参数?
最小的例子很短: #include #include #include struct Foo{ //template //Foo(C col, typename std::enable_if::type* = 0){ // std::cout << "option…
为什么使用Sfinae代码编译错误,即使有一个可以匹配的模板
代码如下。 #include #include template struct Vec { using value_type = T; static constexpr size_t size() { return Type::size; } }; template s…
如何在enable_if中使用多个条件?
我有以下代码: #include #include using namespace std; enum class a : uint16_t { x, y }; template using isUint16ScopedEnum = std::integral_co…
C&#x2B;&#x2B;通过CRTP检测朋友课的私人成员
我有一个 CRTP 基类 (Bar),它由未指定的类继承。此派生类可能有也可能没有特定成员 (internal_foo),并且该特定成员可能有也可能没有其他成员 (test(…
C++模板 type_trait enable_if 类是映射
#include #include #include #include #include #include using namespace std; // enable_if_t = MapType implements .find(KeyType key), .begin(),…
为什么enable_if_t需要有数据类型标识符和默认值?
我无法理解下面代码片段中的 2 个注释代码行与它们前面的行有何不同?有没有一种简单的方法可以理解注释行的含义与它们前面的行的含义?我无法在脑海…
输入具有特定成员函数的重载函数
我试图根据传入的序列容器是否将 push_back 作为成员函数来重载函数。 #include #include #include #include #include template, int> = 0> void has_…
不应该定义的enable_if函数
作为一个实验,我试图创建一个没有参数的 void 成员函数,根据类模板参数更改行为: #include #include template class MyClass { public: void MyFun…
类模板的成员模板函数上的enable_if
这似乎是 MSVC10 中的一个错误? #include template struct A{ template typename std::enable_if::type t(){} }; int main(){ A().t(); //error C277…
根据模板参数在编译时安排类结构
C++ 中是否可以根据模板参数包含/排除成员变量? 这是一个例子: template class RealNumber { T real; }; template class ComplexNumber { T real; T…
enable_if :模板库的模板化方法继承多次的情况
如果我有一个带有模板方法的模板基类: template class S { public: template void f(U p, typename enable_if >::type*dummy = 0) { std::cout << p …
我可以使用像enable_if这样的隐式转换运算符吗?
我有一个(基本上完成的)矩阵类(在这篇文章的后面)。如果矩阵是 1x1 矩阵,那么我希望隐式转换为支持类型(例如 1x1 浮点矩阵应转换为浮点)。 有…