草庐IT

argument-less

全部标签

c++ - "template argument deduction for class templates"是否应该为可变类模板推导出空参数包?

“类模板的模板参数推导”提案(P0091R2)包含以下示例:templatestructX{X(Ts...)};Xx1{1};//OKXXx11;//OKX(除了构造函数定义缺少主体这一事实之外),该示例似乎表明用零参数构造的可变参数类模板将被推导为一个空的参数包。很遗憾,最新版本的g++不同意:intmain(){Xx1{1};Xx11;}Infunction'intmain()':error:invaliduseoftemplate-name'X'withoutanargumentlistXx11;^note:classtemplateargumentdeductionrequir

std::greater 和 std::less 上的 C++11 条件表达式出现不同类型的错误

以下与条件表达式相关的代码:typedefunsignedcharuchar;uchardata[100];//assignsomethingtoarray[]hereuchar*start=data;uchar*end=data+100;boolcond=f();//f()couldreturntrueorfalseuchar*itr=std::upper_bound(start,end,uchar(20),cond?std::greater():std::less());遇到这样的错误:error:operandsto?:havedifferenttypes‘std::greate

c++ - 为什么 std::less 比 "<"好?

C++入门,第5期,14.8.2,将库函数对象与算法结合使用:vectornameTable;//vectorofpointers//error:thepointersinnameTableareunrelated,so());然后我检查了std::less实现:templatestructless:publicbinary_function{booloperator()(const_Tp&__x,const_Tp&__y)const{return__x我发现std::less也使用运算符 最佳答案 因为并不总是operator.只

c++ - Argument Dependent Lookup 的逆向解决方法?

C++具有ADL(参数相关查找),正如其名称所描述的那样,函数的上下文(命名空间)可以从(任何)参数的上下文(命名空间)中隐含。fun(a);//ifthetypeofaisinnamespacensdeducens::fifavailable我的问题是,是否也可以通过某种技术进行反向操作?我所说的反向是指上下文(命名空间)是否可以从被调用函数的上下文中推导出来。某种“功能相关查找”(FDL)。假代码:ns::fun(a);//deducens::aifavailable我想不出这样做的方法。对于用于对函数选项进行编码的enum,此限制尤其烦人。我想知道是否有一种技术可以模拟此功能(C

c++ - 关于 std::less 行为的问题

那里发生了什么?#includenamespaceA{structClass{};}booloperator()(A::Class(),A::Class());return0;}这是编译好的。但如果我使用。#include我有错误:g++test.cc-otestInfileincludedfrom/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/include/g++-v4/bits/stl_tree.h:64:0,from/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/include/g++-v4/set:60,fromlo

c++ - 错误 : passing 'const T' as 'this' argument of 'bool T::operator<(T)' discards qualifiers

#include#include#includeclassMyData{public:intm_iData;booloperatormyvector(2,MyData());myvector[0].m_iData=2;myvector[1].m_iData=4;std::sort(myvector.begin(),myvector.end());}尝试编译这个给出:error:passing'constMyData'as'this'argumentof'boolMyData::operator 最佳答案 比较运算符将在类实例的常量引

android - 找不到参数的方法 cppFlags() arguments()

我正在尝试使用std::function但是编译器报错Error:(50,10)error:notypenamed'function'innamespace'std'我试过修改build.gradle文件externalNativeBuild{ndkBuild{path"src/main/jni/Android.mk"}cmake{cppFlags"-std=c++11"arguments"-DANDROID_STL=gnustl_static"path'src/main/jni/CMakeLists.txt'}}但它不接受path以外的参数并抛出以下错误Error:(28,0)Cou

c++ - GCC 优化 : how can less operations be slower?

在尝试对我的代码的某些选项进行基准测试时(使用或不使用128位整数),我观察到一种我无法理解的行为。任何人都可以阐明这一点吗?#include#include#includeintmain(inta,char**b){printf("Runningtests\n");clock_tstart=clock();unsigned__int128t=13;for(unsignedlongi=0;i(注意这里有printf,这样gcc就不会优化for循环)在我的系统上,这可靠地产生了以下输出:u128,+25,took2.411922su128,no+,took1.799805su64,+25

c++ - "Template argument for template template parameter must be a class template or type alias template"

templatestructList{};templateclass>structListHelper;templatestructListHelper>{};^/*Error:Templateargumentfortemplatetemplateparametermustbeaclasstemplateortypealiastemplate*/怎么了?我正在使用clang++SVN。 最佳答案 您有一个模板模板参数。您必须传递一个模板作为其参数。您改为将模板实例化作为其参数传递-这是一个具体类,而不是模板(其所有参数均已绑定(bi

c++ - std::is_sorted 和 strictly less 比较?

我不太明白std::is_sorted算法及其默认行为。如果我们查看cppreference,它表示默认情况下std::is_sorted使用运算符(operator)。相反,我发现使用会很自然。但我的问题是,对于以下数字列表:123345它将返回true,即使3应该是false.这怎么可能?编辑:它似乎比我想象的更糟糕,因为通过了std::less_equal在这种情况下将返回false...当我传递比较器函数时应用的条件是什么? 最佳答案 根据25.4/5:Asequenceissortedwithrespecttoacompa