2
0
mirror of https://github.com/boostorg/hana.git synced 2026-01-22 17:22:30 +00:00
Files
hana/example/core/operators.cpp
2015-01-17 15:45:40 -05:00

54 lines
1.4 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/assert.hpp>
#include <boost/hana/comparable.hpp>
#include <boost/hana/core/operators.hpp>
#include <string>
using namespace boost::hana;
// Provided via a template parameter.
template <typename = operators::enable_adl>
struct Person_ {
std::string name;
struct hana { struct enabled_operators : Comparable { }; };
};
using Person = Person_<>;
// Provided via inheritance. Unfortunately, we lose PODness even though
// `operators::enable_adl` is empty.
struct Employee : operators::enable_adl {
explicit Employee(std::string n) : name{n} { }
std::string name;
struct hana { struct enabled_operators : Comparable { }; };
};
namespace boost { namespace hana {
template <>
struct equal_impl<Person, Person> {
static bool apply(Person x, Person y)
{ return x.name == y.name; }
};
template <>
struct equal_impl<Employee, Employee> {
static bool apply(Employee x, Employee y)
{ return x.name == y.name; }
};
}}
int main() {
Person john{"John"}, bill{"Bill"};
BOOST_HANA_RUNTIME_CHECK(john == john && john != bill);
Employee bob{"Bob"}, alice{"Alice"};
BOOST_HANA_RUNTIME_CHECK(bob != alice);
}