Boost 范围-v3/排序混乱
我有点简单,因为我不太清楚下面标记错误的行上的错误原因 std::sort和boost::sort选择默认谓词,但ranges-v3由于某些原因没有选择。这是ranges-v3 0.36。clang 6/7和gcc 7/8上出现类似错误Boost 范围-v3/排序混乱,boost,range,c++17,range-v3,Boost,Range,C++17,Range V3,我有点简单,因为我不太清楚下面标记错误的行上的错误原因 std::sort和boost::sort选择默认谓词,但ranges-v3由于某些原因没有选择。这是ranges-v3 0.36。clang 6/7和gcc 7/8上出现类似错误 #include <range/v3/all.hpp> #include <algorithm> #include <boost/hana.hpp> #include <utility> #include <
#include <range/v3/all.hpp>
#include <algorithm>
#include <boost/hana.hpp>
#include <utility>
#include <vector>
#include <boost/range/algorithm.hpp>
namespace hana = boost::hana;
template< typename T = int>
struct point_t {
BOOST_HANA_DEFINE_STRUCT(point_t<T>, (T, x), (T, y));
constexpr bool operator<(const point_t<T> &b) const noexcept {
return hana::less(hana::to_tuple(*this), hana::to_tuple(b));
};
};
int main() {
std::vector<point_t<point_t<>>> all;
boost::sort(all); // OK
std::sort(std::begin(all), std::end(all)); //OK
ranges::sort(all, std::less<point_t<point_t<>>>()); // OK
ranges::sort(all, hana::less); // OK
ranges::sort(all); // error no matching function for call to object of type 'const with_braced_init_args<ranges::v3::sort_fn>'
return 0;
}
#包括
#包括
#包括
#包括
#包括
#包括
名称空间hana=boost::hana;
模板
结构点{
BOOST_HANA_DEFINE_STRUCT(点t,(t,x),(t,y));
constexpr bool操作员凯西通过电话迅速回答
以下是他的评论,作为要求的文本,而不是我放在这里的原始图像:
ranges::sort
如果没有comparator参数,则要求类型为
排序以模拟概念。这意味着
该类型必须定义所有的=
,!=
,
,=
,并使用
一致语义
我在那里回答说:
谢谢你这么快回来。我现在明白了。我必须说
有点令人失望,它与std::sort
和
boost::sort
需求。这是我们为range-v3
我想是可爱吧
再次感谢你,马特
不幸的是,这些要求比std::sort
和boost::sort
更高,因此这些代码不仅可以工作。我理解其动机
奇怪的是,std::rel_ops
和boost/operators
似乎干扰了我对可自省结构的聚合初始化支持的目标,所以我最终求助于宏(类似于下面),很遗憾
我将玩更多的游戏,寻找更好的静态多态解决方案
亲切问候,
--马特
#定义JEST结构(T)\
constexpr bool运算符==(const T&b)const noexcept{\
返回hana::equal(hana::to_tuple(*this),hana::to_tuple(b))\
}; \
\
constexpr bool运算符!=(const T&b)const noexcept{\
返回hana::not_equal(hana::to_tuple(*this),hana::to_tuple(b))\
}; \
\
constexpr bool运算符=(const T&b)const noexcept{\
返回hana::greater_equal(hana::to_tuple(*this),hana::to_tuple(b))\
}
是的,这既有礼貌又是个好主意。谢谢Nicol。改为参考github问题的文本,并针对这种特殊情况扩展了宏解决方案。不要失望。如果这些约束不能促进可靠性和等式推理,受约束的泛型库将不会成功。为什么要添加约束如果你不具备在更高层次上对代码语义进行推理的能力,那就没什么了?这应该是任何通用库设计的最终目标。明智的话。全功能的正确性对我们所有人来说都是一个崇高的目标。也适合过去,但我喜欢在一天结束时打破一切。当宇宙飞船着陆时会更好特别是喜欢GPU范围的工作。用范围整合内核操作是一件美妙的事情。谢谢Eric的工作和难以置信的坚持。
#define JEST_STRUCT(T) \
constexpr bool operator==(const T &b) const noexcept { \
return hana::equal(hana::to_tuple(*this), hana::to_tuple(b)); \
}; \
\
constexpr bool operator!=(const T &b) const noexcept { \
return hana::not_equal(hana::to_tuple(*this), hana::to_tuple(b)); \
}; \
\
constexpr bool operator<(const T &b) const noexcept { \
return hana::less(hana::to_tuple(*this), hana::to_tuple(b)); \
}; \
\
constexpr bool operator<=(const T &b) const noexcept { \
return hana::less_equal(hana::to_tuple(*this), hana::to_tuple(b)); \
}; \
\
constexpr bool operator>(const T &b) const noexcept { \
return hana::greater(hana::to_tuple(*this), hana::to_tuple(b)); \
}; \
\
constexpr bool operator>=(const T &b) const noexcept { \
return hana::greater_equal(hana::to_tuple(*this), hana::to_tuple(b)); \
}