2
0
mirror of https://github.com/boostorg/hana.git synced 2026-02-21 03:02:11 +00:00
Files
hana/example/core/operators.cpp
2014-08-07 21:05:38 -04:00

52 lines
1.3 KiB
C++

/*
@copyright Louis Dionne 2014
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
*/
#include <boost/hana/comparable/equal_mcd.hpp>
#include <boost/hana/core/datatype.hpp>
#include <boost/hana/detail/assert.hpp>
#include <string>
using namespace boost::hana;
// Provided via a template parameter.
template <typename = operators<Comparable>>
struct Person_ {
std::string name;
};
using Person = Person_<>;
// Provided via inheritance. Unfortunately, we lose PODness even though
// `operators<...>` is empty.
struct Employee : operators<Comparable> {
explicit Employee(std::string n) : name{n} { }
std::string name;
};
namespace boost { namespace hana {
template <>
struct Comparable::instance<Person, Person> : Comparable::equal_mcd {
static bool equal_impl(Person x, Person y) {
return x.name == y.name;
}
};
template <>
struct Comparable::instance<Employee, Employee> : Comparable::equal_mcd {
static bool equal_impl(Employee x, Employee y) {
return x.name == y.name;
}
};
}}
int main() {
Person john{"John"}, bill{"Bill"};
BOOST_HANA_RUNTIME_ASSERT(john == john && john != bill);
Employee bob{"Bob"}, alice{"Alice"};
BOOST_HANA_RUNTIME_ASSERT(bob != alice);
}