草庐IT

expression-templates

全部标签

c++ - Curiously Recurring Template Pattern (CRTP) 是正确的解决方案吗?

场景考虑一个Logger类,它有一个为标准C++类型重载的成员函数write(),还有一些方便的函数模板,比如writeLine()内部调用write():classLogger{public:voidwrite(intx){...}voidwrite(doublex){...}...templatevoidwriteLine(Tx){write(x);...}...};进一步考虑一个子类FooLogger,它为特定于域的类型添加了额外的write()重载(我们称其中两个为FooType1和FooType2):classFooLogger:publicLogger{public:usi

c++ - 错误 : use of deleted function for overloaded template

我正在尝试模板特化,但无法确定为什么charconst*const无法在下面解析(尽管是有效类型)的原因。templateBfoo(A)=delete;templatevoidfoo(char*){}templatevoidfoo(charconst*const){}intmain(){{//typesOKcharconst*consta=nullptr;char*b=nullptr;}char*data;foo(data);//OKfoo(data);//ERRORreturn0;}错误error:useofdeletedfunction‘Bfoo(A)[withA=constcha

c++ - Visual Studio 2008 Express MFC 支持

许多人可能都知道,VisualStudio2008的Express版本不包括对MFC和编译大量Windows程序所需的其他一些包的支持。所以,这是我的问题:我有完整版的VisualStudio2005。我一直用它来编译我的一个friend正在做的一个项目,这样我就可以为他测试它并继续跟踪错误和其他事情。最近,他将该项目升级到我没有的VS2008。所以,我下载了express版本,希望我可以简单地用它编译,但没有运气,它提示左右缺少标题。在我看来,因为我已经拥有完整版本的VS2005,所以我肯定至少拥有他的项目需要编译的相关文件的某些(可能是旧版本)版本。有没有一种方法可以说服VS200

c++ - 在 Visual Studio 2008 Express 中链接 libcURL

我的第一个问题:我在C++项目中使用libcURL时遇到问题。我什至没有把它联系起来。我使用的是WindowsXP和VisualC++2008ExpressEdition。这就是我所做的:已下载libcURL:curl-7.19.5-devel-mingw32.zip在VC++中打开了新的命令行项目将文件夹“lib”和“include”包含到我的新项目中(可能微不足道,但花了我一段时间;-)在Properties->C/C++->General中:将文件夹“include”添加到“additionalfolderstoinclude”在“属性”->“链接器”->“常规”中:将文件夹“l

c++ - 使用表达式模板的中间结果

C++模板元编程:来自Boost及其他的概念、工具和技术...Onedrawbackofexpressiontemplatesisthattheytendtoencouragewritinglarge,complicatedexpressions,becauseevaluationisonlydelayeduntiltheassignmentoperatorisinvoked.Ifaprogrammerwantstoreusesomeintermediateresultwithoutevaluatingitearly,shemaybeforcedtodeclareacomplicate

c++ - "run time templates"

我很确定答案是“你不能使用模板,你必须使用虚函数(动态多态性)”,但如果我走那条路,我似乎必须复制很多代码.这是设置:我目前有两个类,ColorImageSegmentation和GrayscaleImageSegmentation。他们做的事情本质上是一样的,但是有3个区别-它们对不同类型(ColorImage和GrayscaleImage)进行操作-一个参数,直方图的维度(3vs1)不同-PixelDifference函数根据图像类型不同如果我创建一个类templateclassImageSegmentation{};我会保持良好的状态。但是,我想让这个对象成为另一个类的成员:cl

c++ - 为什么 std::basic_string 不支持通过表达式模板进行连接?

Qt的QString可以通过operator%连接起来,它使用表达式模板预先计算结果字符串的大小并优化对operator+的多个链式调用.参见thisquestionofmine了解更多信息。为什么std::basic_string没有采用类似的结构?C++11甚至允许这样做吗?我只看到优点,很明显,库实现者可以在需要时破坏ABI兼容性(C++11甚至为libstdc++提供了一个很好的理由)。 最佳答案 因为没有人提出标准;除非有人提出建议,否则它不会进入。还因为它可能会破坏现有代码(如果他们使用operator+就是这样)。此外

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++ - 表达式模板不适用于 clang 下的原始类型重载

我有一个CRTP基类如下:templateclassBase{public://hereisIthinkwheretheproblemisinlineconstDerived&self()const{return*static_cast(this);}};那么派生类定义为templateclassDerived:publicBase,sizeof...(Rest)>{public:Derived()=default;//ThisconstructorbindsanyarbitraryexpressiontoDerivedtemplateinlineDerived(constBase&s

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

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