template-argument-deduction相关内容
因此
..
我需要使用模板来实现一个类,例如“ MyClass”。 template class MyClass { public: T var1; T1 var2; }; 有两个成员变量var1和var2。如果类模板参数“ T”是基本类型(例如:float,double或long double),则变量var1和var2的类型应与模板参
..
这是在成员变量和函数参数的模板类型推论 我的.h文件包含以下几行。 #include #include #include 模板 class MyClass { 模板 struct myTypeTraits {使用type =
..
我具有此功能: template void f(Args ... args,int last) { } 如果没有显式模板参数就调用模板推导将失败: f(2,2); //候选人期望有1个参数,而2个提供了 但是为参数包提供显式模板参数是可行的: f(2,2); //编译良好
..
以下是由标准完美定义的吗? #include 模板 void f(Types& ... values) { std :: cout(3); 返回0; }
..
我了解到,给定一个初始化转发/通用引用的表达式,就可以推断出左值是 T& 类型,而右值是 T类型(而不是 T& )。 因此,仅允许右值,则需要编写 模板 >,OtherConds ...> =是> void foo(T& x){} 而不是 template
..
在以下情况下,我很难理解扣除的原理: template 结构AImpl {}; template struct AHelper { using type = AImpl
..
我正在尝试推导用户定义的类的模板参数的值( http:// wg21。 link / p0732r2 ),使用带有-std = c ++ 2a的GCC 9.1。 struct user_type { int a; constexpr user_type(int a):a(a){} }; 模板结构值{}; 模板 vo
..
当您可以从C ++ 17获得类模板参数推导时,为什么不能推导std :: unique_ptr的模板参数呢?例如,这给了我一个错误: std :: unique_ptr smp(new D); 上面写着“类模板的参数列表丢失”。 模板参数(至少是指针类型)不是可推论的吗? 请参阅以下内容: 任何指定初始化的声明变量和 变量模板
..
我具有以下模板化功能(在编译器中启用了C ++最新标准-但也许17足够了。) #include< ; functional> template void MyFunction(const std :: function&回调); int main()
..
请考虑以下代码: #include #include 模板 struct custom_wrapper { template custom_wrapper(Arg arg):data(arg){} T数据; }; 模板 custom_wrappe
..
请考虑以下简化示例,也可以在 https://godbolt.org/g/Et56cm : #include 模板结构成功 { T值; constexpr success(T& v) :value(std :: move(v)) { } constexpr success(const T& v) :价值(v) { } };
..
考虑以下类定义和 推导指南 : 模板 struct foo:Ts ... { template foo(Us&& ... us):Ts {us} ... {} }; 模板 foo(Us&& ... us)-> foo
..
考虑以下代码: template 结构列表 { template list(Args ...) { static_assert(sizeof ...(Types)> 0); } }; 模板 list(Args ...)-> list
..
考虑以下代码: #include template 结构体外部{ 结构体内部{}; }; template std :: ostream&运算符 :: inner const& value){ std ::
..
阅读C ++ 11标准后,我无法完全理解以下语句的含义。例子非常受欢迎。 使用两组类型来确定部分排序。对于涉及的每个模板 ,都有原始函数类型和 转换后的函数类型。 [注意:在14.5.6.2中描述了转换类型 的创建。推导过程使用 转换后的类型作为参数模板,并使用 其他模板的原始类型作为参数模板。对于部分排序比较中涉及的每种类型,此过程执行两次 :一次使用 将转换后的templa
..
我正试图将函数std::max作为模板参数传递给模板化函数,但是由于某些原因,编译器会打印无法推断出函数类型的错误.一个简单的例子也重现了同样的问题.它可以与自己的max2函数一起使用,但不能与STL std::max: 一起使用 #include template T max2(const T& a, const T& b) { return s
..
我知道,给定一个初始化初始化程序,auto会推断出std::initializer_list的类型,而模板类型的推导将失败: auto var = { 1, 2, 3 }; // type deduced as std::initializer_list template void f(T parameter); f({ 1, 2, 3 });
..
我用一个额外的模板参数创建了一个简单的舍入模板函数,该参数定义了返回前需要将舍入值转换为类型的类型. template T round(U val) { T result; if (val >= 0) result = (T)(floor(val + (U)(.5))); else re
..
假设我具有函数copy: template void copy( Buf&& input_buffer, Buf& output_buffer) {} 其中input_buffer是通用引用,而output_buffer是l值引用. Reference collapsing rules确保input_buffer确实是真的,而不考虑B
..