惯用的std :: rel_ops [英] Idiomatic use of std::rel_ops
问题描述
使用std :: rel_ops将一整套关系运算符添加到类中的首选方法是什么?
What is the preferred method of using std::rel_ops to add the full set of relational operators to a class?
此文档建议使用命名空间std :: rel_ops 的,但这似乎是深入有缺陷的,因为这意味着包括以这种方式实现的类的头部也将向所有其他类添加完全关系运算符,和operator ==,即使不是所希望的。这有可能以令人惊讶的方式改变代码的意义。
This documentation suggests a using namespace std::rel_ops
, but this seems to be deeply flawed, as it would mean that including the header for the class implemented in this way would also add full relational operators to all other classes with a defined operator< and operator==, even if that was not desired. This has the potential to change the meaning of code in surprising ways.
另外,我一直在使用 Boost.Operators 来执行此操作,但我仍然对标准库感兴趣。
As a side note - I have been using Boost.Operators to do this, but I am still curious about the standard library.
推荐答案
我认为首选的技术不是在
all使用 std :: rel_ops
在 boost :: operator
中使用的技术似乎是通常的
解决方案。
I think that the preferred technique is not to use std::rel_ops
at
all. The technique used in boost::operator
seems to be the usual
solution.
这篇关于惯用的std :: rel_ops的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!