是std :: equal_to保证调用operator ==默认吗? [英] Is std::equal_to guaranteed to call operator== by default?

查看:717
本文介绍了是std :: equal_to保证调用operator ==默认吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直认为标准需要 std :: equal_to< T> 的非专用模板来调用 T :: operator = = ,但我注意到 cppreference.com上的说明几乎暗示它是另一种方式;当然没有提到它作为一个要求。我也检查了C ++ 11草案标准N3337,也找不到任何保证。

I had always thought that the standard required the non-specialized template for std::equal_to<T> to call T::operator==, but I noticed the description at cppreference.com almost implies it's the other way around; certainly it doesn't mention it as a requirement. I also checked the C++11 draft standard N3337 and couldn't find any guarantees there either.

如果你创建一个带有运算符的类==

我不能老实想出一种实现<$ c

I can't honestly think of a way to implement std::equal_to that wouldn't work this way, but am I missing something?

推荐答案

$ c> std :: equal_to


默认情况下,std :: equal_to是否保证调用运算符==

Is std::equal_to guaranteed to call operator == by default?

如果不是特殊的, equal_to 的调用操作符将调用 operator == 。从C ++ 11标准的第20.8.5节:

If not specialized, equal_to's call operator will invoke operator ==. From Paragraph 20.8.5 of the C++11 Standard:


1库为所有比较运算符提供了基本的函数对象类

1 The library provides basic function object classes for all of the comparison operators in the language (5.9, 5.10).



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




2 / code>返回 x == y

2 operator() returns x == y.

这篇关于是std :: equal_to保证调用operator ==默认吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆