Boost.Hana: boost::hana::map< Pairs > Struct Template Reference

| Boost.Hana 1.7.1 Your standard library for metaprogramming |

Synopsis of associated functions | Friends | Public Member Functions | List of all members
boost::hana::map< Pairs > Struct Template Reference
Data types

## Description

### template<typename ... Pairs>
struct boost::hana::map< Pairs >

Basic associative container requiring unique, `Comparable` and `Hashable` keys.

The order of the elements of the map is unspecified. Also, all the keys must be `Hashable`, and any two keys with equal hashes must be `Comparable` with each other at compile-time.

Note
  The actual representation of a `hana::map` is an implementation detail. As such, one should not assume anything more than what is explicitly documented as being part of the interface of a map, such as:
  - the presence of additional constructors
  - the presence of additional assignment operators
  - the fact that `hana::map<Pairs...>` is, or is not, a dependent type
  In particular, the last point is very important; `hana::map<Pairs...>` is basically equivalent to
  decltype(hana::make_pair(std::declval<Pairs>()...))
  which is not something that can be pattern-matched on during template argument deduction, for example. More details in the tutorial.

## Modeled concepts

1. `Comparable`
   Two maps are equal iff all their keys are equal and are associated to equal values.
   // 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 <boost/hana/assert.hpp>
   #include <boost/hana/integral_constant.hpp>
   #include <boost/hana/map.hpp>
   #include <boost/hana/pair.hpp>
   #include <boost/hana/type.hpp>
   #include <string>
   namespace hana = boost::hana;
   using namespace std::literals;
   int main() {
   BOOST_HANA_RUNTIME_CHECK(
   hana::make_map(
   hana::make_pair(hana::char_c<'a'>, "foobar"s),
   hana::make_pair(hana::type_c<int&&>, nullptr)
   )
   ==
   hana::make_map(
   hana::make_pair(hana::type_c<int&&>, (void*)0),
   hana::make_pair(hana::char_c<'a'>, "foobar"s)
   )
   );
   }
   assert.hpp
   Defines macros to perform different kinds of assertions.
   BOOST_HANA_RUNTIME_CHECK
   #define BOOST_HANA_RUNTIME_CHECK(...)
   Equivalent to BOOST_HANA_RUNTIME_ASSERT, but not influenced by the BOOST_HANA_CONFIG_DISABLE_ASSERTIO...
   Definition: assert.hpp:209
   integral_constant.hpp
   Defines boost::hana::integral_constant.
   map.hpp
   Defines boost::hana::map.
   boost::hana
   Namespace containing everything in the library.
   Definition: accessors.hpp:20
   pair.hpp
   Defines boost::hana::pair.
   type.hpp
   Defines boost::hana::type and related utilities.
2. `Searchable`
   A map can be searched by its keys with a predicate yielding a compile-time `Logical`. Also note that `operator[]` can be used instead of `at_key`.
   // 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 <boost/hana/assert.hpp>
   #include <boost/hana/at_key.hpp>
   #include <boost/hana/equal.hpp>
   #include <boost/hana/find.hpp>
   #include <boost/hana/integral_constant.hpp>
   #include <boost/hana/map.hpp>
   #include <boost/hana/optional.hpp>
   #include <boost/hana/pair.hpp>
   #include <boost/hana/type.hpp>
   namespace hana = boost::hana;
   constexpr auto m = hana::make_map(
   hana::make_pair(hana::type_c<int>, 'i'),
   hana::make_pair(hana::type_c<float>, 'f')
   );
   static_assert(hana::find(m, hana::type_c<int>) == hana::just('i'), "");
   static_assert(hana::find(m, hana::type_c<float>) == hana::just('f'), "");
   BOOST_HANA_CONSTANT_CHECK(hana::find(m, hana::type_c<void>) == hana::nothing);
   BOOST_HANA_CONSTANT_CHECK(hana::find(m, hana::int_c<3>) == hana::nothing);
   // operator[] is equivalent to at_key
   static_assert(m[hana::type_c<int>] == 'i', "");
   static_assert(m[hana::type_c<float>] == 'f', "");
   int main() { }
   at_key.hpp
   Defines boost::hana::at_key.
   equal.hpp
   Defines boost::hana::equal.
   find.hpp
   Defines boost::hana::find.
   boost::hana::find
   constexpr auto find
   Finds the value associated to the given key in a structure.
   Definition: find.hpp:44
   BOOST_HANA_CONSTANT_CHECK
   #define BOOST_HANA_CONSTANT_CHECK(...)
   Equivalent to BOOST_HANA_CONSTANT_ASSERT, but not influenced by the BOOST_HANA_CONFIG_DISABLE_ASSERTI...
   Definition: assert.hpp:239
   optional.hpp
   Defines boost::hana::optional.
3. `Foldable`
   Folding a map is equivalent to folding a list of the key/value pairs it contains. In particular, since that list is not guaranteed to be in any specific order, folding a map with an operation that is not both commutative and associative will yield non-deterministic behavior.
   // 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 <boost/hana/assert.hpp>
   #include <boost/hana/first.hpp>
   #include <boost/hana/fold_left.hpp>
   #include <boost/hana/insert.hpp>
   #include <boost/hana/integral_constant.hpp>
   #include <boost/hana/map.hpp>
   #include <boost/hana/pair.hpp>
   #include <boost/hana/second.hpp>
   #include <boost/hana/type.hpp>
   namespace hana = boost::hana;
   int main() {
   // Given a map of (key, value) pairs, returns a map of (value, key) pairs.
   // This requires both the keys and the values to be compile-time Comparable.
   auto invert = [](auto map) {
   return hana::fold_left(map, hana::make_map(), [](auto map, auto pair) {
   return hana::insert(map, hana::make_pair(hana::second(pair), hana::first(pair)));
   });
   };
   auto m = hana::make_map(
   hana::make_pair(hana::type_c<int>, hana::int_c<1>),
   hana::make_pair(hana::type_c<float>, hana::int_c<2>),
   hana::make_pair(hana::int_c<3>, hana::type_c<void>)
   );
   BOOST_HANA_CONSTANT_CHECK(invert(m) ==
   hana::make_map(
   hana::make_pair(hana::int_c<1>, hana::type_c<int>),
   hana::make_pair(hana::int_c<2>, hana::type_c<float>),
   hana::make_pair(hana::type_c<void>, hana::int_c<3>)
   )
   );
   }
   first.hpp
   Defines boost::hana::first.
   fold_left.hpp
   Defines boost::hana::fold_left.
   boost::hana::first
   constexpr auto first
   Returns the first element of a pair.
   Definition: first.hpp:33
   boost::hana::second
   constexpr auto second
   Returns the second element of a pair.
   Definition: second.hpp:32
   boost::hana::insert
   constexpr insert_t insert
   Insert a value at a given index in a sequence.
   Definition: insert.hpp:29
   insert.hpp
   Defines boost::hana::insert.
   second.hpp
   Defines boost::hana::second.
   boost::hana::map::map
   constexpr map()=default
   Default-construct a map. This constructor only exists when all the elements of the map are default-co...

## Conversion from any <tt>Foldable</tt>

Any `Foldable` of `Product`s can be converted to a `hana::map` with `hana::to<hana::map_tag>` or, equivalently, `hana::to_map`. If the `Foldable` contains duplicate keys, only the value associated to the first occurence of each key is kept.

// 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 <boost/hana/assert.hpp>
#include <boost/hana/core/to.hpp>
#include <boost/hana/map.hpp>
#include <boost/hana/pair.hpp>
#include <boost/hana/tuple.hpp>
#include <boost/hana/type.hpp>
#include <string>
namespace hana = boost::hana;
using namespace std::literals;
int main() {
auto xs = hana::make_tuple(
hana::make_pair(hana::type_c<int>, "abcd"s),
hana::make_pair(hana::type_c<void>, 1234),
hana::make_pair(hana::type_c<int>, nullptr)
);
BOOST_HANA_RUNTIME_CHECK(
hana::to<hana::map_tag>(xs) == hana::make_map(
hana::make_pair(hana::type_c<int>, "abcd"s),
hana::make_pair(hana::type_c<void>, 1234)
)
);
}
to.hpp
Defines boost::hana::to and related utilities.
tuple.hpp
Defines boost::hana::tuple.

## Example

// Copyright Louis Dionne 2013-2017
// Distributed under the Boost Software License, Version 1.0.
#include <boost/hana/assert.hpp>
#include <boost/hana/at_key.hpp>
#include <boost/hana/contains.hpp>
#include <boost/hana/map.hpp>
#include <boost/hana/pair.hpp>
#include <boost/hana/string.hpp>
#include <functional>
#include <string>
#include <vector>
namespace hana = boost::hana;
template <typename ...Events>
struct event_system {
using Callback = std::function<void()>;
hana::map<hana::pair<Events, std::vector<Callback>>...> map_;
template <typename Event, typename F>
void on(Event e, F handler) {
auto is_known_event = hana::contains(map_, e);
static_assert(is_known_event,
"trying to add a handler to an unknown event");
map_[e].push_back(handler);
}
template <typename Event>
void trigger(Event e) const {
auto is_known_event = hana::contains(map_, e);
static_assert(is_known_event,
"trying to trigger an unknown event");
for (auto& handler : this->map_[e])
handler();
}
};
template <typename ...Events>
event_system<Events...> make_event_system(Events ...events) {
return {};
}
int main() {
auto events = make_event_system(
BOOST_HANA_STRING("foo"),
BOOST_HANA_STRING("bar"),
BOOST_HANA_STRING("baz")
);
std::vector<std::string> triggered_events;
events.on(BOOST_HANA_STRING("foo"), [&] {
triggered_events.push_back("foo:1");
});
events.on(BOOST_HANA_STRING("foo"), [&] {
triggered_events.push_back("foo:2");
});
events.on(BOOST_HANA_STRING("bar"), [&] {
triggered_events.push_back("bar:1");
});
events.on(BOOST_HANA_STRING("baz"), [&] {
triggered_events.push_back("baz:1");
});
events.trigger(BOOST_HANA_STRING("foo"));
events.trigger(BOOST_HANA_STRING("bar"));
events.trigger(BOOST_HANA_STRING("baz"));
BOOST_HANA_RUNTIME_CHECK(triggered_events == std::vector<std::string>{
"foo:1", "foo:2", "bar:1", "baz:1"
});
}
contains.hpp
Defines boost::hana::contains and boost::hana::in.
boost::hana::contains
constexpr auto contains
Returns whether the key occurs in the structure.
Definition: contains.hpp:42
boost::hana::on
constexpr auto on
Invoke a function with the result of invoking another function on each argument.
Definition: on.hpp:54
string.hpp
Defines boost::hana::string.

## Synopsis of associated functions
template<>
constexpr auto | make< map_tag >
| Function object for creating a `hana::map`. More...
constexpr auto | make_map = make<map_tag>
| Alias to `make<map_tag>`; provided for convenience. More...
constexpr auto | to_map = to<map_tag>
| Equivalent to `to<map_tag>`; provided for convenience.
constexpr auto | keys
| Returns a `Sequence` of the keys of the map, in unspecified order. More...
constexpr auto | values
| Returns a `Sequence` of the values of the map, in unspecified order. More...
constexpr auto | insert
| Inserts a new key/value pair in a map. More...
constexpr auto | erase_key
| Removes a key/value pair from a map. More...
constexpr auto | union_
| Returns the union of two maps. More...
constexpr auto | intersection
| Returns the intersection of two maps. More...
constexpr auto | difference
| Returns the difference of two maps. More...
constexpr auto | symmetric_difference
| Returns the symmetric set-theoretic difference of two maps. More...

## Friends
template<typename X , typename Y >
constexpr friend auto | operator== (X &&x, Y &&y)
| Equivalent to `hana::equal`
template<typename X , typename Y >
constexpr friend auto | operator!= (X &&x, Y &&y)
| Equivalent to `hana::not_equal`

## Public Member Functions
constexpr | map ()=default
| Default-construct a map. This constructor only exists when all the elements of the map are default-constructible.
constexpr | map (map const &other)=default
| Copy-construct a map from another map. This constructor only exists when all the elements of the map are copy-constructible.
constexpr | map (map &&other)=default
| Move-construct a map from another map. This constructor only exists when all the elements of the map are move-constructible.
template<typename ... P>
constexpr | map (P &&...pairs)
| Construct the map from the provided pairs. `P...` must be pairs of the same type (modulo ref and cv-qualifiers), and in the same order, as those appearing in `Pairs...`. The pairs provided to this constructor are emplaced into the map's storage using perfect forwarding.
constexpr map & | operator= (map const &other)
| Assign a map to another map with the exact same type. Only exists when all the elements of the map are copy-assignable.
constexpr map & | operator= (map &&other)
| Move-assign a map to another map with the exact same type. Only exists when all the elements of the map are move-assignable.
template<typename Key >
constexpr decltype(auto) | operator[] (Key &&key)
| Equivalent to `hana::at_key`

## Associated functions

## ◆ make< map_tag >

template<typename ... Pairs>
template<>

constexpr auto make< map_tag >
| related

Initial value:
= [](auto&& ...pairs) {
return map<implementation_defined>{forwarded(pairs)...};
}

Function object for creating a `hana::map`.

Given zero or more `Product`s representing key/value associations, `make<map_tag>` returns a `hana::map` associating these keys to these values.

`make<map_tag>` requires all the keys to be unique and to have different hashes. If you need to create a map with duplicate keys or with keys whose hashes might collide, use `hana::to_map` or insert `(key, value)` pairs to an empty map successively. However, be aware that doing so will be much more compile-time intensive than using `make<map_tag>`, because the uniqueness of keys will have to be enforced.

## Example

// 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 <boost/hana/assert.hpp>
#include <boost/hana/core/make.hpp>
#include <boost/hana/integral_constant.hpp>
#include <boost/hana/map.hpp>
#include <boost/hana/pair.hpp>
#include <boost/hana/type.hpp>
#include <string>
namespace hana = boost::hana;
using namespace std::literals;
int main() {
BOOST_HANA_RUNTIME_CHECK(
hana::make_map(
hana::make_pair(hana::int_c<1>, "foobar"s),
hana::make_pair(hana::type_c<void>, 1234)
)
==
hana::make<hana::map_tag>(
hana::make_pair(hana::int_c<1>, "foobar"s),
hana::make_pair(hana::type_c<void>, 1234)
)
);
}
make.hpp
Defines boost::hana::make.

## ◆ make_map

template<typename ... Pairs>

constexpr auto make_map = make<map_tag>
| related

Alias to `make<map_tag>`; provided for convenience.

## Example

// 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 <boost/hana/assert.hpp>
#include <boost/hana/core/make.hpp>
#include <boost/hana/integral_constant.hpp>
#include <boost/hana/map.hpp>
#include <boost/hana/pair.hpp>
#include <boost/hana/type.hpp>
#include <string>
namespace hana = boost::hana;
using namespace std::literals;
int main() {
BOOST_HANA_RUNTIME_CHECK(
hana::make_map(
hana::make_pair(hana::int_c<1>, "foobar"s),
hana::make_pair(hana::type_c<void>, 1234)
)
==
hana::make<hana::map_tag>(
hana::make_pair(hana::int_c<1>, "foobar"s),
hana::make_pair(hana::type_c<void>, 1234)
)
);
}

## ◆ keys

template<typename ... Pairs>

constexpr auto keys
| related

Initial value:
= [](auto&& map) {
return implementation_defined;
}

Returns a `Sequence` of the keys of the map, in unspecified order.

## Example

// 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 <boost/hana/assert.hpp>
#include <boost/hana/contains.hpp>
#include <boost/hana/integral_constant.hpp>
#include <boost/hana/keys.hpp>
#include <boost/hana/map.hpp>
#include <boost/hana/pair.hpp>
#include <boost/hana/permutations.hpp>
#include <boost/hana/tuple.hpp>
#include <boost/hana/type.hpp>
#include <string>
namespace hana = boost::hana;
using namespace std::literals;
int main() {
auto m = hana::make_map(
hana::make_pair(hana::int_c<1>, "foobar"s),
hana::make_pair(hana::type_c<void>, 1234)
);
// The order of the keys is unspecified.
BOOST_HANA_CONSTANT_CHECK(
hana::keys(m) ^hana::in^ hana::permutations(hana::make_tuple(hana::int_c<1>, hana::type_c<void>))
);
}
boost::hana::in
constexpr auto in
Return whether the key occurs in the structure.
Definition: contains.hpp:70
boost::hana::permutations
constexpr auto permutations
Return a sequence of all the permutations of the given sequence.
Definition: permutations.hpp:34
boost::hana::keys
constexpr keys_t keys
Returns a Sequence containing the name of the members of the data structure.
Definition: keys.hpp:29
keys.hpp
Defines boost::hana::keys.
permutations.hpp
Defines boost::hana::permutations.

## ◆ values

template<typename ... Pairs>

constexpr auto values
| related

Initial value:
= [](auto&& map) -> decltype(auto) {
return implementation_defined;
}

Returns a `Sequence` of the values of the map, in unspecified order.

## Example

// 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 <boost/hana/assert.hpp>
#include <boost/hana/contains.hpp>
#include <boost/hana/integral_constant.hpp>
#include <boost/hana/map.hpp>
#include <boost/hana/pair.hpp>
#include <boost/hana/permutations.hpp>
#include <boost/hana/tuple.hpp>
#include <boost/hana/type.hpp>
#include <string>
namespace hana = boost::hana;
using namespace std::literals;
int main() {
auto m = hana::make_map(
hana::make_pair(hana::int_c<1>, "foobar"s),
hana::make_pair(hana::type_c<void>, 1234)
);
// The order of the values is unspecified.
BOOST_HANA_RUNTIME_CHECK(
hana::values(m) ^hana::in^ hana::permutations(hana::make_tuple("foobar"s, 1234))
);
}

## ◆ insert

template<typename ... Pairs>

constexpr auto insert
| related

Initial value:
= [](auto&& map, auto&& pair) {
return tag-dispatched;
}

Inserts a new key/value pair in a map.

Given a `(key, value)` pair, `insert` inserts this new pair into a map. If the map already contains this key, nothing is done and the map is returned as-is.

Parameters

  map | The map in which to insert a `(key,value)` pair.
  pair | An arbitrary `Product` representing a `(key, value)` pair to insert in the map. The `key` must be compile-time `Comparable`.

## Example

// 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 <boost/hana/assert.hpp>
#include <boost/hana/insert.hpp>
#include <boost/hana/map.hpp>
#include <boost/hana/pair.hpp>
#include <boost/hana/type.hpp>
#include <string>
namespace hana = boost::hana;
using namespace std::literals;
int main() {
auto m = hana::make_map(
hana::make_pair(hana::type_c<int>, "abcd"s),
hana::make_pair(hana::type_c<void>, 1234)
);
BOOST_HANA_RUNTIME_CHECK(
hana::insert(m, hana::make_pair(hana::type_c<float>, 'x')) ==
hana::make_map(
hana::make_pair(hana::type_c<int>, "abcd"s),
hana::make_pair(hana::type_c<void>, 1234),
hana::make_pair(hana::type_c<float>, 'x')
)
);
BOOST_HANA_RUNTIME_CHECK(hana::insert(m, hana::make_pair(hana::type_c<void>, 'x')) == m);
}

## ◆ erase_key

template<typename ... Pairs>

constexpr auto erase_key
| related

Initial value:
= [](auto&& map, auto&& key) {
return tag-dispatched;
}

Removes a key/value pair from a map.

Returns a new `hana::map` containing all the elements of the original, except for the `(key, value)` pair whose `key` compares `equal` to the given key. If the map does not contain such an element, a new map equal to the original is returned.

Parameters

  map | The map in which to erase a `key`.
  key | A key to remove from the map. It must be compile-time `Comparable`.

## Example

// 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 <boost/hana/assert.hpp>
#include <boost/hana/erase_key.hpp>
#include <boost/hana/map.hpp>
#include <boost/hana/pair.hpp>
#include <boost/hana/string.hpp>
#include <boost/hana/type.hpp>
#include <string>
namespace hana = boost::hana;
using namespace std::literals;
int main() {
auto m = hana::make_map(
hana::make_pair(hana::type_c<int>, "abcd"s),
hana::make_pair(hana::type_c<void>, 1234),
hana::make_pair(BOOST_HANA_STRING("foobar!"), hana::type_c<char>)
);
BOOST_HANA_RUNTIME_CHECK(
hana::erase_key(m, BOOST_HANA_STRING("foobar!")) ==
hana::make_map(
hana::make_pair(hana::type_c<int>, "abcd"s),
hana::make_pair(hana::type_c<void>, 1234)
)
);
BOOST_HANA_RUNTIME_CHECK(hana::erase_key(m, hana::type_c<char>) == m);
}
erase_key.hpp
Defines boost::hana::erase_key.

## ◆ union_

template<typename ... Pairs>

constexpr auto union_
| related

Initial value:
= [](auto&& xs, auto&& ys) {
return tag-dispatched;
}

Returns the union of two maps.

Given two maps `xs` and `ys`, `hana::union_(xs, ys)` is a new map containing all the elements of `xs` and all the elements of `ys`, without duplicates. If both `xs` and `ys` contain an element with the same `key`, the one in `ys` is taken. Functionally, `hana::union_(xs, ys)` is equivalent to

hana::fold_left(xs, ys, hana::insert)

Parameters

  xs,ys | The two maps to compute the union of.

## Example

// 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 <boost/hana/assert.hpp>
#include <boost/hana/equal.hpp>
#include <boost/hana/integral_constant.hpp>
#include <boost/hana/string.hpp>
#include <boost/hana/map.hpp>
#include <boost/hana/type.hpp>
#include <boost/hana/union.hpp>
#include <string>
namespace hana = boost::hana;
using namespace hana::literals;
static auto m1 = hana::make_map(
hana::make_pair(BOOST_HANA_STRING("key1"), hana::type_c<std::string>),
hana::make_pair(BOOST_HANA_STRING("key2"), hana::type_c<std::string>)
);
static auto m2 = hana::make_map(
hana::make_pair(BOOST_HANA_STRING("key3"), hana::type_c<std::string>),
hana::make_pair(BOOST_HANA_STRING("key4"), hana::type_c<std::string>),
hana::make_pair(BOOST_HANA_STRING("key5"), hana::type_c<std::string>)
);
BOOST_HANA_CONSTANT_CHECK(hana::union_(m1, m2) == hana::make_map(
hana::make_pair(BOOST_HANA_STRING("key1"), hana::type_c<std::string>),
hana::make_pair(BOOST_HANA_STRING("key2"), hana::type_c<std::string>),
hana::make_pair(BOOST_HANA_STRING("key3"), hana::type_c<std::string>),
hana::make_pair(BOOST_HANA_STRING("key4"), hana::type_c<std::string>),
hana::make_pair(BOOST_HANA_STRING("key5"), hana::type_c<std::string>)
));
constexpr auto m3 = hana::make_map(
hana::make_pair(hana::type_c<int>, hana::int_c<1>),
hana::make_pair(hana::type_c<bool>, hana::bool_c<true>)
);
constexpr auto m4 = hana::make_map(
hana::make_pair(hana::type_c<char>, hana::char_c<'c'>),
hana::make_pair(hana::type_c<bool>, hana::bool_c<false>)
);
BOOST_HANA_CONSTANT_CHECK(hana::union_(m3, m4) == hana::make_map(
hana::make_pair(hana::type_c<int>, hana::int_c<1>),
hana::make_pair(hana::type_c<bool>, hana::bool_c<false>),
hana::make_pair(hana::type_c<char>, hana::char_c<'c'>)
));
int main() { }
union.hpp
Defines boost::hana::union.

## ◆ intersection

template<typename ... Pairs>

constexpr auto intersection
| related

Initial value:
= [](auto&& xs, auto&& ys) {
return tag-dispatched;
}

Returns the intersection of two maps.

Given two maps `xs` and `ys`, `intersection(xs, ys)` is a new map containing exactly those (key, value) pairs from xs, for which key is present in `ys`. In other words, the following holds for any object `pair(k, v)`:

pair(k, v) ^in^ intersection(xs, ys) if and only if (k, v) ^in^ xs && k ^in^ keys(ys)
boost::hana::map::keys
constexpr auto keys
Returns a Sequence of the keys of the map, in unspecified order.
Definition: map.hpp:186
boost::hana::map::intersection
constexpr auto intersection
Returns the intersection of two maps.
Definition: map.hpp:315

Note
  This function is not commutative, i.e. `intersection(xs, ys)` is not necessarily the same as `intersection(ys, xs)`. Indeed, the set of keys in `intersection(xs, ys)` is always the same as the set of keys in `intersection(ys, xs)`, but the value associated to each key may be different. `intersection(xs, ys)` contains values present in `xs`, and `intersection(ys, xs)` contains values present in `ys`.

Parameters

  xs,ys | Two maps to intersect.

## Example

// 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 <boost/hana/assert.hpp>
#include <boost/hana/equal.hpp>
#include <boost/hana/intersection.hpp>
#include <boost/hana/map.hpp>
#include <boost/hana/string.hpp>
#include <string>
namespace hana = boost::hana;
using namespace hana::literals;
static auto m1 = hana::make_map(
hana::make_pair(BOOST_HANA_STRING("key1"), hana::type_c<std::string>),
hana::make_pair(BOOST_HANA_STRING("key2"), hana::type_c<std::string>)
);
static auto m2 = hana::make_map(
hana::make_pair(BOOST_HANA_STRING("key3"), hana::type_c<std::string>),
hana::make_pair(BOOST_HANA_STRING("key4"), hana::type_c<std::string>),
hana::make_pair(BOOST_HANA_STRING("key5"), hana::type_c<std::string>)
);
BOOST_HANA_CONSTANT_CHECK(hana::intersection(m1, m2) == hana::make_map());
static auto m3 = hana::make_map(
hana::make_pair(hana::type_c<int>, hana::int_c<1>),
hana::make_pair(hana::type_c<bool>, hana::bool_c<true>),
hana::make_pair(hana::type_c<std::string>, BOOST_HANA_STRING("hana")),
hana::make_pair(hana::type_c<float>, hana::int_c<100>)
);
static auto m4 = hana::make_map(
hana::make_pair(hana::type_c<char>, hana::char_c<'c'>),
hana::make_pair(hana::type_c<bool>, hana::bool_c<false>),
hana::make_pair(hana::type_c<std::string>, BOOST_HANA_STRING("boost"))
);
BOOST_HANA_CONSTANT_CHECK(hana::intersection(m3, m4) == hana::make_map(
hana::make_pair(hana::type_c<bool>, hana::bool_c<true>),
hana::make_pair(hana::type_c<std::string>, BOOST_HANA_STRING("hana"))
));
int main() { }
intersection.hpp
Defines boost::hana::intersection.

## ◆ difference

template<typename ... Pairs>

constexpr auto difference
| related

Initial value:
= [](auto&& xs, auto&& ys) {
return tag-dispatched;
}

Returns the difference of two maps.

Given two maps `xs` and `ys`, `difference(xs, ys)` is a new map containing exactly those (key, value) pairs from xs, for which key is not present in `keys(ys)`. In other words, the following holds for any object `pair(k, v)`:

pair(k, v) ^in^ difference(xs, ys) if and only if (k, v) ^in^ xs && k ^not in^ keys(ys)
boost::hana::map::difference
constexpr auto difference
Returns the difference of two maps.
Definition: map.hpp:349

Note
  This function is not commutative, i.e. `difference(xs, ys)` is not necessarily the same as `difference(ys, xs)`. Indeed, consider the case where `xs` is empty and `ys` isn't. In that case, `difference(xs, ys)` is empty, but `difference(ys, xs)` is equal to `ys`. For symmetric version of this operation, see `symmetric_difference`.

Parameters

  xs,ys | Two maps to compute the difference of.

## Example

// 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 <boost/hana/assert.hpp>
#include <boost/hana/equal.hpp>
#include <boost/hana/intersection.hpp>
#include <boost/hana/map.hpp>
#include <boost/hana/string.hpp>
#include <string>
namespace hana = boost::hana;
using namespace hana::literals;
static auto m1 = hana::make_map(
hana::make_pair(BOOST_HANA_STRING("key1"), hana::type_c<std::string>),
hana::make_pair(BOOST_HANA_STRING("key2"), hana::type_c<std::string>)
);
static auto m2 = hana::make_map(
hana::make_pair(BOOST_HANA_STRING("key3"), hana::type_c<std::string>),
hana::make_pair(BOOST_HANA_STRING("key4"), hana::type_c<std::string>),
hana::make_pair(BOOST_HANA_STRING("key5"), hana::type_c<std::string>)
);
BOOST_HANA_CONSTANT_CHECK(hana::intersection(m1, m2) == hana::make_map());
static auto m3 = hana::make_map(
hana::make_pair(hana::type_c<int>, hana::int_c<1>),
hana::make_pair(hana::type_c<bool>, hana::bool_c<true>),
hana::make_pair(hana::type_c<std::string>, BOOST_HANA_STRING("hana")),
hana::make_pair(hana::type_c<float>, hana::int_c<100>)
);
static auto m4 = hana::make_map(
hana::make_pair(hana::type_c<char>, hana::char_c<'c'>),
hana::make_pair(hana::type_c<bool>, hana::bool_c<false>),
hana::make_pair(hana::type_c<std::string>, BOOST_HANA_STRING("boost"))
);
BOOST_HANA_CONSTANT_CHECK(hana::intersection(m3, m4) == hana::make_map(
hana::make_pair(hana::type_c<bool>, hana::bool_c<true>),
hana::make_pair(hana::type_c<std::string>, BOOST_HANA_STRING("hana"))
));
int main() { }

## ◆ symmetric_difference

template<typename ... Pairs>

constexpr auto symmetric_difference
| related

Initial value:
= [](auto&& xs, auto&& ys) {
return tag-dispatched;
}

Returns the symmetric set-theoretic difference of two maps.

Given two sets `xs` and `ys`, `symmetric_difference(xs, ys)` is a new map containing all the elements of `xs` whose keys are not contained in `keys(ys)`, and all the elements of `ys` whose keys are not contained in `keys(xs)`. The symmetric difference of two maps satisfies the following:

symmetric_difference(xs, ys) == union_(difference(xs, ys), difference(ys, xs))
boost::hana::map::symmetric_difference
constexpr auto symmetric_difference
Returns the symmetric set-theoretic difference of two maps.
Definition: map.hpp:374
boost::hana::map::union_
constexpr auto union_
Returns the union of two maps.
Definition: map.hpp:281

Parameters

  xs,ys | Two maps to compute the symmetric difference of.

## Example

// 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 <boost/hana/assert.hpp>
#include <boost/hana/map.hpp>
#include <boost/hana/symmetric_difference.hpp>
namespace hana = boost::hana;
constexpr auto m1 = hana::make_map(
hana::make_pair(hana::type_c<int>, 1),
hana::make_pair(hana::type_c<bool>, hana::true_c)
);
constexpr auto m2 = hana::make_map(
hana::make_pair(hana::type_c<float>, 1.0),
hana::make_pair(hana::type_c<long long>, 2LL),
hana::make_pair(hana::type_c<int>, 3)
);
constexpr auto result_m = hana::make_map(
hana::make_pair(hana::type_c<bool>, hana::true_c),
hana::make_pair(hana::type_c<float>, 1.0),
hana::make_pair(hana::type_c<long long>, 2LL)
);
int main() {
BOOST_HANA_RUNTIME_CHECK(
hana::symmetric_difference(m1, m2) == result_m
);
}
symmetric_difference.hpp
Defines boost::hana::symmetric_difference.