jjzjj

less-loader

全部标签

c++ - SFINAE 检查 std::less 是否有效

在我的代码中,如果一个对象小于另一个对象,我希望一个操作先于另一个操作发生。但是,如果类型不可比较,则顺序无关紧要。为此,我尝试使用SFINAE:template>()(std::declval(),std::declval()))>boolComparableAndLessThan(constT&lhs,constT&rhs){returnstd::less()(lhs,rhs);}boolComparableAndLessThan(...){returnfalse;}structfoo{};intmain(){fooa,b;if(ComparableAndLessThan(a,b)

c++ - std::less<> 不适用于我的 std::map

我想用我自己的结构“Point2”作为键创建一个map,但是我收到错误并且我不知道是什么导致了它,因为我为Point2结构声明了一个“operator代码:std::mapm_Props_m;std::mapm_Orders;structPoint2{unsignedintPoint2::x;unsignedintPoint2::y;Point2&Point2::operator=(constPoint2&b){if(this!=&b){x=b.x;y=b.y;}return*this;}boolPoint2::operator==(constPoint2&b){return(x==b

c++ - 为什么 C++ STL 容器使用 "less than"operator< 而不是 "equal equal"operator== 作为比较器?

在std::map的自定义类中实现比较运算符时,我遇到了这个问题,但看不到任何被问到的地方。除了上述问题,也有兴趣简要了解,如何operator适用于std::map.问题来源:structAddress{longm_IPv4Address;boolisTCP;booloperator 最佳答案 std::map需要能够排序。默认情况下使用std::less,对于非指针使用1。使用您对用户的要求最少的规则,它从综合“等价”当它需要它时(!(a表示a和b是等价的,即两者都不小于另一个)。这使得编写用作map的关键组件的类变得更加容易,

c++ - std::map unique std::less<> 函数,用于 2D 点作为键

好吧,经过四个小时的调试,尽管我很困惑,但我找到了问题的原因......我正在制作一些程序,在std::map中保存一些点并在我的窗口中呈现这些点。但奇怪的是,有些点未能进入map。std::mapm_Props_m;voidAddProp(std::pairp){m_Props_m.insert(p);}structPoint2{unsignedintPoint2::x;unsignedintPoint2::y;//--------Point2::Point2():x(0),y(0){}boolPoint2::operator(constPoint2&b)const{return(x

c++ - std::less 枚举

标准是否保证std::less会订MyEnumType好像值为MyEnumType被转换为适当大小的整数类型?enumMyEnumType{E1=0,E2=6,E3=3}; 最佳答案 是的,std::less::operator()定义为(§20.8.5/5):operator()returnsx对于在枚举类型上使用关系运算符,声明如下(§5.9/2):Theusualarithmeticconversionsareperformedonoperandsofarithmeticorenumerationtype.对于无作用域的枚举类

c++ - "less than"ifstream 与 GCC 4 与 6 的比较

我偶然发现了这段代码:std::stringexport_str="/path/to/file";std::ofstreamexport(export_str.c_str());if(export这可以在GCC4.9.3上正常编译和运行,但在GCC6.1.1上会出现此错误:error:nomatchfor‘operator}’and‘int’)if(export我尝试使用GCC6:-std=c++98(编译)-std=c++03(编译)-std=c++11(不编译)编辑:但是,在GCC4中,它仍然使用-std=c++11进行编译。.这个具体事实也在下面的答案中解释。:)所以我猜这方面的

c++ - map 在运行时选择 `std::greater` 或 `std::less`

这一行:std::map>current_book;我想用以下逻辑等价物替换它:intSide=...if(Side==1){std::map>current_book;}else{std::map>current_book;} 最佳答案 您可以为此使用std::function:usingmymap=std::map>;autom=Side?mymap(std::less()):mymap(std::greater());liveexample 关于c++-map在运行时选择`std:

c++ - std::greater<double> 和 std::less<double> 使用安全吗?

比较double时C++中的值,使用,=,!=运算符,我们不能总是确定结果的正确性。这就是为什么我们使用其他技术来比较doubles,例如,我们可以通过测试它们的差异是否真的接近于零来比较两个doublea和b。我的问题是,C++标准库是否实现了std::less和std::greater使用这些技术,还是仅使用不安全的比较运算符? 最佳答案 您可以100%确定这些运算符结果的正确性。只是先前的计算可能导致截断,因为double不是无限的。所以运算符非常好,只是您的操作数不是您期望的那样。因此,您使用什么进行比较并不重要。

c++ - std::set<K, C>::operator<(const std::set<K, C>&) 不使用 C() 但 std::less()

无法删除我自己的问题,所以改写它... 最佳答案 这实际上不是实现中的错误,尽管它可以说是标准中的错误:23.2.1Generalcontainerrequirements[container.requirements.general]13Table98listsoperationsthatareprovidedforsometypesofcontainersbutnotothers.Thosecontainersforwhichthelistedoperationsareprovidedshallimplementtheseman

c++ - 使用折叠表达式为数组实现 less 运算符

我正在使用最新的clang++在c++17中使用折叠表达式。我尝试使用它为数组实现less运算符,我想将其用于固定大小的字符串。这是我到达的地方。有没有更好的方法来做到这一点,尤其是避免在表达式中分配索引?使用“clang++test_fold_expr_less.cpp-otest_fold_expr_less-std=c++1z”编译它,输出在这里。prompt$./test_fold_expr_less===less===010010000111#include#includestd::uint64_tarr1[8]={1,7,2,4,8,9,3,6};std::uint64_t