| 1 | // Copyright Jason Rice 2020 |
|---|---|
| 2 | // Distributed under the Boost Software License, Version 1.0. |
| 3 | // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) |
| 4 | |
| 5 | #include <boost/hana/define_struct.hpp> |
| 6 | #include <boost/hana/equal.hpp> |
| 7 | #include <boost/hana/members.hpp> |
| 8 | #include <boost/hana/not_equal.hpp> |
| 9 | namespace hana = boost::hana; |
| 10 | |
| 11 | |
| 12 | struct SomeStruct { |
| 13 | BOOST_HANA_DEFINE_STRUCT(SomeStruct, (int, x)); |
| 14 | |
| 15 | constexpr bool operator==(SomeStruct const& other) const { |
| 16 | return hana::equal(hana::members(*this), hana::members(other)); |
| 17 | } |
| 18 | |
| 19 | constexpr bool operator!=(SomeStruct const& other) const { |
| 20 | return hana::not_equal(hana::members(*this), hana::members(other)); |
| 21 | } |
| 22 | }; |
| 23 | |
| 24 | int main() { |
| 25 | static_assert(SomeStruct{.x: 5} == SomeStruct{.x: 5}, ""); |
| 26 | static_assert(hana::equal(SomeStruct{.x: 5}, SomeStruct{.x: 5}), ""); |
| 27 | } |
| 28 |
