]>
Commit | Line | Data |
---|---|---|
f51cf556 | 1 | // Copyright Louis Dionne 2013-2022 |
7c673cae FG |
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/assert.hpp> | |
6 | #include <boost/hana/comparing.hpp> | |
7 | #include <boost/hana/equal.hpp> | |
8 | #include <boost/hana/tuple.hpp> | |
9 | #include <boost/hana/type.hpp> | |
10 | #include <boost/hana/unique.hpp> | |
11 | ||
12 | #include <string> | |
13 | namespace hana = boost::hana; | |
14 | using namespace std::literals; | |
15 | ||
16 | ||
17 | // unique without a predicate | |
18 | constexpr auto types = hana::tuple_t<int, float, float, char, int, int, int, double>; | |
19 | BOOST_HANA_CONSTANT_CHECK( | |
20 | hana::unique(types) == hana::tuple_t<int, float, char, int, double> | |
21 | ); | |
22 | ||
23 | int main() { | |
24 | // unique with a predicate | |
25 | auto objects = hana::make_tuple(1, 2, "abc"s, 'd', "efg"s, "hij"s, 3.4f); | |
26 | BOOST_HANA_RUNTIME_CHECK( | |
27 | hana::unique(objects, [](auto const& t, auto const& u) { | |
28 | return hana::typeid_(t) == hana::typeid_(u); | |
29 | }) | |
30 | == hana::make_tuple(1, "abc"s, 'd', "efg"s, 3.4f) | |
31 | ); | |
32 | ||
33 | // unique.by is syntactic sugar | |
34 | BOOST_HANA_RUNTIME_CHECK( | |
35 | hana::unique.by(hana::comparing(hana::typeid_), objects) == | |
36 | hana::make_tuple(1, "abc"s, 'd', "efg"s, 3.4f) | |
37 | ); | |
38 | } |