ここで例を考えてみましょうstd::rel_ops
:
http://en.cppreference.com/w/cpp/utility/rel_ops/operator_cmp
#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';
}
(bool)
キャストの目的は何ですか?(f1 != f2)
まだタイプではありませんbool
か?