From 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 20:24:20 +0200 Subject: Adding upstream version 14.2.21. Signed-off-by: Daniel Baumann --- src/boost/libs/hana/test/comparable.cpp | 70 +++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/boost/libs/hana/test/comparable.cpp (limited to 'src/boost/libs/hana/test/comparable.cpp') diff --git a/src/boost/libs/hana/test/comparable.cpp b/src/boost/libs/hana/test/comparable.cpp new file mode 100644 index 00000000..0c968a35 --- /dev/null +++ b/src/boost/libs/hana/test/comparable.cpp @@ -0,0 +1,70 @@ +// Copyright Louis Dionne 2013-2017 +// 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 +#include +#include +#include +#include + +#include +#include + +#include +namespace hana = boost::hana; + + +// Minimal EqualityComparable types +struct eq1 { int value; }; +struct eq2 { + int value; + constexpr operator eq1() const { return {value}; } +}; + +template {} || std::is_same{}) && + (std::is_same{} || std::is_same{}) +>> +constexpr bool operator==(T a, U b) +{ return a.value == b.value; } + +template {} || std::is_same{}) && + (std::is_same{} || std::is_same{}) +>> +constexpr bool operator!=(T a, U b) +{ return !(a == b); } + + +int main() { + // equal + { + // Two objects of different data types are unequal by default, + // and no model is provided for two objects of the same data type. + struct Random1 { }; struct Random2 { }; + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::equal(Random1{}, Random2{}))); + static_assert(!hana::Comparable::value, ""); + static_assert(!hana::Comparable::value, ""); + + // Provided model for EqualityComparable types + BOOST_HANA_CONSTEXPR_CHECK(hana::equal(eq1{0}, eq1{0})); + BOOST_HANA_CONSTEXPR_CHECK(hana::not_(hana::equal(eq1{0}, eq1{1}))); + BOOST_HANA_CONSTEXPR_CHECK(hana::not_(hana::equal(eq1{1}, eq1{0}))); + + BOOST_HANA_CONSTEXPR_CHECK(hana::equal(eq1{0}, eq2{0})); + BOOST_HANA_CONSTEXPR_CHECK(hana::not_(hana::equal(eq1{0}, eq2{1}))); + BOOST_HANA_CONSTEXPR_CHECK(hana::not_(hana::equal(eq1{1}, eq2{0}))); + + BOOST_HANA_CONSTEXPR_CHECK(hana::equal(eq2{0}, eq1{0})); + BOOST_HANA_CONSTEXPR_CHECK(hana::not_(hana::equal(eq2{0}, eq1{1}))); + BOOST_HANA_CONSTEXPR_CHECK(hana::not_(hana::equal(eq2{1}, eq1{0}))); + } + + // laws + hana::test::TestComparable{hana::make_tuple(0,1,2,3,4,5)}; + hana::test::TestComparable{hana::make_tuple(0u,1u,2u,3u,4u,5u)}; + hana::test::TestComparable{hana::make_tuple(0l,1l,2l,3l,4l,5l)}; + hana::test::TestComparable{hana::make_tuple(0ul,1ul,2ul,3ul,4ul,5ul)}; + hana::test::TestComparable{hana::make_tuple(eq1{0}, eq1{1}, eq1{2}, eq1{3}, eq1{4})}; +} -- cgit v1.2.3