• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright Louis Dionne 2013-2017
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/equal.hpp>
7 #include <boost/hana/remove_if.hpp>
8 #include <boost/hana/tuple.hpp>
9 #include <boost/hana/type.hpp>
10 
11 #include <string>
12 namespace hana = boost::hana;
13 
14 
15 struct Cat { std::string name; };
16 struct Dog { std::string name; };
17 struct Fish { std::string name; };
18 
operator ==(Cat const & a,Cat const & b)19 bool operator==(Cat const& a, Cat const& b) { return a.name == b.name; }
operator !=(Cat const & a,Cat const & b)20 bool operator!=(Cat const& a, Cat const& b) { return a.name != b.name; }
operator ==(Dog const & a,Dog const & b)21 bool operator==(Dog const& a, Dog const& b) { return a.name == b.name; }
operator !=(Dog const & a,Dog const & b)22 bool operator!=(Dog const& a, Dog const& b) { return a.name != b.name; }
operator ==(Fish const & a,Fish const & b)23 bool operator==(Fish const& a, Fish const& b) { return a.name == b.name; }
operator !=(Fish const & a,Fish const & b)24 bool operator!=(Fish const& a, Fish const& b) { return a.name != b.name; }
25 
main()26 int main() {
27     hana::tuple<Cat, Fish, Dog, Fish> animals{
28         Cat{"Garfield"}, Fish{"Jaws"}, Dog{"Beethoven"}, Fish{"Nemo"}
29     };
30 
31     auto mammals = hana::remove_if(animals, [](auto const& a) {
32         return hana::typeid_(a) == hana::type<Fish>{};
33     });
34 
35     BOOST_HANA_RUNTIME_CHECK(mammals == hana::make_tuple(Cat{"Garfield"}, Dog{"Beethoven"}));
36 }
37