名前空間
変種
操作

std::rel_ops::operator!=,>,<=,>=

提供: cppreference.com
< cpp‎ | utility

 
 
ユーティリティライブラリ
支援を入力します (basic types, RTTI, type traits)
動的なメモリ管理
エラー処理
プログラムユーティリティ
可変個引数関数
日付と時刻
関数オブジェクト
initializer_list(C++11)
bitset
hash(C++11)
関係演算子
Original:
Relational operators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
rel_ops::operator!=
rel_ops::operator>
rel_ops::operator<=
rel_ops::operator>=
ペアとタプル
Original:
Pairs and tuples
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
pair
tuple(C++11)
piecewise_construct_t(C++11)
piecewise_construct(C++11)
フォワード、スワップ、および移動
Original:
Swap, forward and move
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
swap
forward(C++11)
move(C++11)
move_if_noexcept(C++11)
declval(C++11)
 
Defined in header <utility>
template< class T >
bool operator!=( const T& lhs, const T& rhs );
(1)
template< class T >
bool operator>( const T& lhs, const T& rhs );
(2)
template< class T >
bool operator<=( const T& lhs, const T& rhs );
(3)
template< class T >
bool operator>=( const T& lhs, const T& rhs );
(4)
与えられたユーザー定義operator==operator<タイプTのオブジェクトに対して、他の比較演算子の通常のセマンティクスを実装しています.
Original:
Given a user-defined operator== and operator< for objects of type T, implements the usual semantics of other comparison operators.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
1)
operator!=の面でoperator==を実装しています.
Original:
Implements operator!= in terms of operator==.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
2)
operator>の面でoperator<を実装しています.
Original:
Implements operator> in terms of operator<.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
3)
operator<=の面でoperator<を実装しています.
Original:
Implements operator<= in terms of operator<.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
4)
operator>=の面でoperator<を実装しています.
Original:
Implements operator>= in terms of operator<.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

目次

[編集] パラメータ

lhs -
左辺の引数
Original:
left-hand argument
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
rhs -
右側の引数
Original:
right-hand argument
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 値を返します

1)
truelhsへ'等しくないかの戻りrhs.
Original:
Returns true if lhs is not equal to rhs.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
2)
戻りtrue場合lhsですrhsより大きい.
Original:
Returns true if lhs is greater than rhs.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
3)
戻りtruelhsrhs'です小さいか等しい場合.
Original:
Returns true if lhs is less or equal to rhs.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
4)
戻りtrue場合lhsrhs大きいか等しいです.
Original:
Returns true if lhs is greater or equal to rhs.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 可能な実装

First version
namespace rel_ops {
    template< class T >
    bool operator!=( const T& lhs, const T& rhs ) 
    {
        return !(lhs == rhs);
    }
}
Second version
namespace rel_ops {
    template< class T >
    bool operator>( const T& lhs, const T& rhs ) 
    {
        return rhs < lhs;
    }
}
Third version
namespace rel_ops {
    template< class T >
    bool operator<=( const T& lhs, const T& rhs ) 
    {
        return !(rhs < lhs);;
    }
}
Fourth version
namespace rel_ops {
    template< class T >
    bool operator>=( const T& lhs, const T& rhs ) 
    {
        return !(lhs < rhs);
    }
}

[編集]

#include <iostream>
#include <utility>
 
struct Foo {
    int n;
};
 
bool operator==(const Foo& lhs, const Foo& rhs)
{
    return lhs.n == rhs.n;
}
 
bool operator<(const Foo& lhs, const Foo& rhs)
{
    return lhs.n < rhs.n;
}
 
int main()
{
    Foo f1 = {1};
    Foo f2 = {2};
    using namespace std::rel_ops;
 
    std::cout << std::boolalpha;
    std::cout << "not equal?     : " << (bool) (f1 != f2) << '\n';
    std::cout << "greater?       : " << (bool) (f1 > f2) << '\n';
    std::cout << "less equal?    : " << (bool) (f1 <= f2) << '\n';
    std::cout << "greater equal? : " << (bool) (f1 >= f2) << '\n';
}

Output:

not equal?     : true
greater?       : false
less equal?    : true
greater equal? : false