草庐IT

string-comparison-functions

全部标签

c++ - to_string 不是 std 的成员,g++ (mingw)

我正在制作一个小型词汇内存程序,其中会随机闪现单词以了解含义。正如BjarneStroustroup告诉我们的那样,我想使用标准C++库,但我一开始就遇到了一个看似奇怪的问题。我想将一个long整数更改为std::string以便能够将其存储在文件中。为此,我使用了to_string()。问题是,当我用g++(版本4.7.0,如其--‍version标志中所述)编译它时,它说:PSC:\Users\Anurag\SkyDrive\College\Programs>g++-std=c++0xttd.cppttd.cpp:Infunction'intmain()':ttd.cpp:11:2

c++ - 从 boost::shared_ptr<string> 返回 C 字符串

我将一些C++代码包装在函数中,以便使C++方法在C中可用。C++API方法返回boost::shared_ptr通常的对象。我在C++中导出的函数如下所示:extern"C"constchar*Hazelcast_Map_get_int_string(Hazelcast_Client_t*hazelcastClient,constchar*mapName,intkey,char**errptr){IMapmap=hazelcastClient->client->getMap(mapName);boost::shared_ptrvalue=map.get(key);string*str

c++ - std::function 参数列表和 typedef

我有一个类似这样的typedef:typedefstd::functionMyFunction;在我的代码中某处是这样使用的:MyFunctionfunc=[](intarg1,floatarg2){/*dosometing*/};问题是,每次我更改函数的参数数量(例如,我添加第三个参数chararg3)时,我都被迫在我使用MyFunction的所有代码中更新它(即使这些根本不使用参数。而且我懒得那样做。有没有办法从它的类型中获取std::function的参数列表?(我的意思是)这样函数创建看起来像那样?:MyFunctionfunc=[](MyFunction::args){/*d

c++ - 调用时为 std::function 分配新值

inti=9;struct_variable.f=[i](Tstruct_variable&){do_something_with_capture_variable(i);...struct_variable.f=another_compatible_std_function;//dosomethingelse,butneverusecapturedvariableafterhere...};struct_variable.f(struct_variable);lambda函数被保存为成员struct_variable.f(也是类型std::function),在回调中,struct_

c++ - 为什么可以将 std::bind 分配给参数不匹配的 std::function?

我有如下代码:#include#includeusingnamespacestd;voidF(intx){coutf1=std::bind(F,std::placeholders::_1);f1(100);//Thisworks,willprint100.intx=0;std::functionf2=std::bind(F,x);f2();//Thisworks,willprint0.std::functionf3=std::bind(F,x);f3(200);//BUTWHYTHISWORKS??????Itprints0.return0;}我的编译器信息是:AppleLLVM版本6

c++ - 错误 C2893 : Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&...) noexcept(<expr>)'

下面是一个给出编译时错误的程序。这主要与D类中的Boo函数有关。我最终尝试使用多个线程来调用solve方法,但目前这对我来说似乎不太有效,无法做到这一点。错误是:1>d:\dummy\project1\trash.cpp(37):warningC4101:'d':unreferencedlocalvariable1>c:\programfiles(x86)\microsoftvisualstudio\2017\community1\vc\tools\msvc\14.11.25503\include\thr\xthread(240):errorC2672:'std::invoke':no

c++ - 为什么按值传递 string_view?为什么 Visual Studio 不能对此进行优化?

根据我的直觉,我假设新的string_view需要通过引用传递,因为这样效率更高(只传递指针而不是完整的类)。然而,一些消息来源表明最好按值传递它,避免“别名”问题。C++viewtypes:passbyconst&orbyvalue?https://abseil.io/tips/1在尝试几种替代方案时,我证实了我的直觉,如果该函数只是转发string_view(所有源均使用/Ox编译),那么通过引用传递会更快比如这段代码externautootherMethodByReference(conststd::string_view&input)->void;autothisMethodB

c++ - 如何从移动捕获 lambda 表达式创建 std::function?

我正在尝试创建一个std::function来自移动捕获lambda表达式。请注意,我可以毫无问题地创建移动捕获lambda表达式;仅当我尝试将其包装在std::function中时我得到一个错误。例如:autopi=std::make_unique(0);//noproblemshere!autofoo=[q=std::move(pi)]{*q=5;std::coutbar=foo;std::functionbar{foo};std::functionbar{std::move(foo)};std::functionbar=std::move(foo);std::functionba

c++ - 获取 UTF-8 编码的 std::string 的实际长度?

我的std::string是utf-8编码的,很明显,str.length()返回了错误的结果。我找到了此信息,但不确定如何使用它来执行此操作:Thefollowingbytesequencesareusedtorepresentacharacter.ThesequencetobeuseddependsontheUCScodenumberofthecharacter:0x00000000-0x0000007F:0xxxxxxx0x00000080-0x000007FF:110xxxxx10xxxxxx0x00000800-0x0000FFFF:1110xxxx10xxxxxx10xxx

c++ - boost::function 如何支持不同长度模板参数的模板类

我想使用boost预处理器来声明具有不同模板变量长度的模板类,基本上就像boost::function所做的那样。#if!BOOST_PP_IS_ITERATING#ifndefD_EXAMPLE_H#defineD_EXAMPLE_H#include#include#defineBOOST_PP_ITERATION_PARAMS_1(3,(1,2,"example.h"))#includeBOOST_PP_ITERATE()#elsetemplateclassExample{boost::functionfunc;};#endif上面的代码显然不会工作,因为它在同一个头文件中声明了具