草庐IT

string-comparison-functions

全部标签

c++ - 将 std::function 绑定(bind)到不同对象实例的相同函数

是否可以重新绑定(bind)std::function以指向相同的函数但具有不同的对象实例?如果我有一个对象,它有一个绑定(bind)到另一个函数的std::function,但是如果那个对象被复制到另一个实例,我想将std::function重新绑定(bind)到那个新实例而不是旧实例。#include"stdafx.h"#include#includeclassEventHandler{public:intNum;std::functionOnEvent;EventHandler(intinNum){Num=inNum;}EventHandler(constEventHandler

c++ - 如何为 string_view 创建 (VC14) 调试可视化工具?

我正在使用boost::string_view。(www.boost.org/doc/libs/1_61_0/boost/utility/string_view.hpp)它有一个constchar*ptr_和一个unsignedintlen_数据成员。当调试它很麻烦时,因为默认的可视化工具将显示字符ptr_的字符数多于长度(因为string_view不是空终止的)。我尝试通过查看std::string可视化工具来创建自己的可视化工具。如果我对长度进行硬编码(比如说4),我可以获得要显示的字符串,但是我无法让它使用实际的长度变量。任何帮助表示赞赏。损坏的例子:{ptr_,4}//work

c++ - 使用 boost::spirit::x3 解析为 vector<boost::string_view>

这是我的previousone的后续问题关于boost::spirit::x3和boost::string_view.虽然我可以解析成std::vector(liveexample),解析为std::vector失败并出现以下编译错误:#include#include#includenamespaceboost{namespacespirit{namespacex3{namespacetraits{templatevoidmove_to(Itb,Ite,boost::string_view&v){v=boost::string_view(b,std::size_t(std::dista

c++ - std::string not nothrow move assignable or comparable?

我在研究type_traits时,发现了std::string的这个奇怪属性:$cata.cpp#include#includestatic_assert(std::is_nothrow_move_assignable::value,"???");static_assert(noexcept(std::declval()==std::declval()),"???");$g++-std=c++14a.cppa.cpp:4:1:error:staticassertionfailed:???static_assert(std::is_nothrow_move_assignable::val

C++ 原子 : would function call act as memory barrier?

我正在阅读这篇文章MemoryOrderingatCompileTime从中说:Infact,themajorityoffunctioncallsactascompilerbarriers,whethertheycontaintheirowncompilerbarrierornot.Thisexcludesinlinefunctions,functionsdeclaredwiththepureattribute,andcaseswherelink-timecodegenerationisused.Otherthanthosecases,acalltoanexternalfunction

Invalid value type for attribute ‘factoryBeanObjectType‘: java.lang.String

ErrorstartingApplicationContext.Todisplaytheconditionevaluationreportre-runyourapplicationwith'debug'enabled.2024-01-05T17:04:00.527+08:00ERROR201118---[solve][main]o.s.boot.SpringApplication:Applicationrunfailedjava.lang.IllegalArgumentException:Invalidvaluetypeforattribute'factoryBeanObjectType':j

c++ - 为什么没有 std::string_view 的模板构造函数?

我正在阅读documentationforstd::string_view,我注意到这些是构造函数:constexprbasic_string_view()noexcept;constexprbasic_string_view(constbasic_string_view&other)noexcept=default;constexprbasic_string_view(constCharT*s,size_typecount);constexprbasic_string_view(constCharT*s);他们为什么不介绍这个?templateconstexprbasic_strin

c++ - 指针和 std::string - 奇怪的行为 - C++

我提前道歉,因为我在之前的帖子中问过同样的问题,但正如有人正确指出的那样,我没有发布真正的代码。因此,我再次问同样的问题,试图比以前更清楚。作为练习,我正在创建一个操作字符串的程序。特别是,我想删除包含在2个“*”之间的部分字符串。我必须强调,我已经使用库字符串的函数成功地创建了相同的程序;事实上,问题涉及使用char指针对给定字符串的操作。我将发布完整的代码并进行深入讨论。#include#includeusingnamespacestd;intmain(){stringfrase;getline(cin,frase);//Takesasinputthephraseintsize=f

c++ - 将整数类型转换为枚举 : functional cast vs initialization

假设有一个这样的枚举:enumfoo:int{first,second}然后我使用它如下:foof(1);//error:cannotinitializeavariableoftype'foo'withanrvalueoftype'int'foof=foo(1);//OK!我想知道这两者有什么区别?我知道第二个版本可以看作是函数式转换,但为什么这会有什么不同?例如,如果我这样做:classBar{};Barb=Bar(1);//nomatchingconversionforfunctional-stylecastfrom'int'to'Bar'我显然得到了一个有意义的错误。因此,这让我

C++17 <functional> 模板参数推导不适用于 Xcode 10.1

我一直在尝试使用C++17(及更高版本)进行模板参数推导,并试图从cppreference.com编译这个确切的示例#includeintfunc(double){return0;}intmain(){std::functionf{func};//guide#1deducesfunctioninti=5;std::functiong=[&](double){returni;};//guide#2deducesfunction}它在该页面上的基于Web的编译器中编译并运行良好,但是当我尝试在我的MacbookPro上编译它时,它失败了,说error:noviableconstructor