相关疑难解决方法(0)

什么是透明比较器?

在C++ 14中,关联容器似乎已从C++ 11改变 - [associative.reqmts]/13说:

成员函数模板find,count,lower_bound,upper_bound,并且equal_range不得,除非类型参与重载决议Compare::is_transparent存在.

使比较器"透明"的目的是什么?

C++ 14还提供了这样的库模板:

template <class T = void> struct less {
    constexpr bool operator()(const T& x, const T& y) const;
    typedef T first_argument_type;
    typedef T second_argument_type;
    typedef bool result_type;
};

template <> struct less<void> {
    template <class T, class U> auto operator()(T&& t, U&& u) const
    -> decltype(std::forward<T>(t) < std::forward<U>(u));
    typedef *unspecified* is_transparent;
};
Run Code Online (Sandbox Code Playgroud)

因此,例如,std::set<T, std::less<T>>不会有一个透明的比较,而是std::set<T, std::less<>> …

c++ c++-faq c++14

101
推荐指数
4
解决办法
2万
查看次数

标签 统计

c++ ×1

c++-faq ×1

c++14 ×1