小编kov*_*val的帖子

libc ++对std :: map / set :: equal_range的实现产生了意外的结果

我注意到在clang的libc ++中std::set::equal_range(与相同std::map)给出的结果与libstdc ++不同。我一直认为equal_range应该返回std::make_pair(set.lower_bound(key), set.upper_bound(key))cppreference和libstdc ++所做的等效。但是在libc ++中,我有一个给出不同结果的代码。

#include <set>
#include <iostream>
#include <iterator>

struct comparator {
    using range_t = std::pair<int, int>;
    using is_transparent = std::true_type;
    bool operator()(int lhs, int rhs) const
    {
        return lhs < rhs;
    }
    bool operator()(int lhs, range_t rhs) const
    {
        return lhs < rhs.first;
    }
    bool operator()(range_t lhs, int rhs) const
    {
        return lhs.second < rhs;
    }
};

using range_set = std::set<int, comparator>;

int main()
{
    range_set set = …
Run Code Online (Sandbox Code Playgroud)

c++ libc++

6
推荐指数
1
解决办法
95
查看次数

标签 统计

c++ ×1

libc++ ×1