草庐IT

template-auto

全部标签

c++ - 了解 "template argument is invalid"错误消息

考虑代码:#include#includestructtest1{voidInvoke(){};};structtest2{templatevoidInvoke(){};};enumclassInvokableKind{NOT_INVOKABLE,INVOKABLE_FUNCTION,INVOKABLE_FUNCTION_TEMPLATE};templatestructget_invokable_kind{conststaticInvokableKindvalue=InvokableKind::NOT_INVOKABLE;};templatestructget_invokable_ki

c++ - template<> 用于成员枚举的显式特化

根据17.7.3[temp.expl.spec]第5段(N4659),...Membersofanexplicitlyspecializedclasstemplatearedefinedinthesamemannerasmembersofnormalclasses,andnotusingthetemplatesyntax.Thesameistruewhendefiningamemberofanexplicitlyspecializedmemberclass.However,templateisusedindefiningamemberofanexplicitlyspecializedm

c++ - 为什么auto y = reference_to_x的地址和x的地址不一样?

假设您有以下代码:long&fn2(long&another_var1,longanother_var2){another_var1=another_var1+another_var2;another_var2=another_var2+another_var1;returnanother_var1;}intmain(){cout在您到达第2行之前,一切都按预期进行,其中返回false。当你autoresult时,它应该是一个引用变量到another_var1,它是对var1的引用,即它们都应该有相同的地址——它们只是同一内存的别名。查看第1行,返回15,给人一种它们都一样的错觉。然后

c++ - 想要 : a C++ template idea to catch an issue, 但在编译时?

我们有一个常量结构数组,像这样:staticconstSettingsSuT_table[]={{5,1},{1,2},{1,1},etc};结构如下:size_bytes:num_items:其他“元数据”成员所以“总大小”是单个元素的size_bytes*num_items。所有这些信息都在const数组中,在编译时可用。但是,请注意,_table的总大小与EEPROM本身的大小无关。_table不镜像EEPROM,它只描述了布局、用途和我们需要的其他“元数据”类型的信息。但是,您可以使用此元数据来确定我们正在使用的EEPROM的数量。数组简单地描述了存储在外部EEPROM中的数据

web前端之使用弹性和外边距进行网页布局、非常有用的小技巧、flex、margin、auto

MENU效果图htmlcss解析效果图图中效果只需要flex和margin便可以实现。htmldivclass="w_100_d_fh_168p_6bc_c0c0c0">divclass="w_50h_50bc_e75f57m_a">div>div>divclass="w_100_d_fp_6mt_20bc_c0c0c0">divclass="w_50h_50bc_e75f57">div>divclass="w_50h_50bc_f2b64c">div>divclass="w_50h_50bc_55bd4cml_a">div>div>divclass="w_100_d_fp_6mt_20bc_

c++ - 错误 C2995 : function template has already been defined

此代码产生17错误C2995:函数模板已被定义;在添加#include"set.h"header之前存在一组单独的错误。有一个与此关联的私有(private).cpp和.h文件。/**File:private/set.cpp*LastmodifiedonThuJun1109:34:082009byeroberts*-----------------------------------------------------*Thisfilecontainstheimplementationoftheset.hinterface.*BecauseofthewayC++compilestemp

c++ - 函数中auto_ptr的返回值

我遇到过这样的代码。MyClassMyClass::get_information(constsome_datastructure*record){auto_ptrvariable(newMyClass());variable->set_article_id(record->article_id);return*variable.get();}我知道这会返回一个(拷贝?)MyClass类型的对象。最初,我认为它正在返回对我来说没有意义的auto_ptr对象(?)因为我认为auto_ptr对象在超出范围时会被销毁。无论如何,上面的代码可以吗?对象*variable.get()在函数返回时

c++ - 两阶段查找 : is it possible to easily mix inheritence and templates

简介:C++标准区分依赖模板参数的符号名称和不依赖模板参数的名称,这称为两阶段名称查找(参见here)。定义模板时,会尽快解析非相关名称。另一方面,从属名称仅在模板实例化时解析。示例:templatestructBase{typedefTtype;staticconstintn=3;virtualintf()=0;intf(intx){returnx*2;}};//doesn'tcompile!templatestructDerived:Base{typefield;//Thecompilerdoesn'tknowBase::typeyet!intf(){returnn;}//thec

c++ - 成员函数中的 decltype(auto) 忽略无效主体,decltype(expr) 失败

我有一个简单的模板化包装器结构,其成员函数在其模板类型的对象上调用.error()。templatestructWrapper{Tt;decltype(auto)f(){returnt.error();//calls.error()}};如果我用一个没有error()成员函数的类型实例化它,只要我不调用它就没问题。这就是我想要的行为。Wrapperw;//noproblemhere//w.error();//uncommentedcausescompilationfailure如果我使用我认为是具有尾随返回类型的语义等价物,它会在变量声明上出错templatestructWrapper

c++ - 为什么 `auto&` 不能绑定(bind)到 volatile 右值表达式?

考虑下面的代码:intmain(){inti{};auto&c=static_cast(i);//(1)auto&v=static_cast(i);//(2)}(1)编译成功,(2)不被接受:error:volatilelvaluereferencetotype'volatileint'cannotbindtoatemporaryoftype'volatileint'为什么auto不能变成volatileint?为什么auto&可以变成constint并绑定(bind)到constint&&?是因为auto&实际上绑定(bind)到一个在赋值右侧创建的临时对象吗?但是,为什么auto&