tinympl  0.2
mini MPL library for C++11
fused_map.hpp
1 // Copyright (C) 2013, Ennio Barbaro.
2 //
3 // Use, modification, and distribution is subject to the Boost Software
4 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // See http://sbabbi.github.io/tinympl for documentation.
8 //
9 // You are welcome to contact the author at:
10 // enniobarbaro@gmail.com
11 //
12 
13 #ifndef TINYMPL_FUSED_MAP_HPP
14 #define TINYMPL_FUSED_MAP_HPP
15 
16 #include <tinympl/variadic/all_of.hpp>
17 #include <tinympl/variadic/is_unique.hpp>
18 #include <tinympl/map.hpp>
19 #include <algorithm>
20 
21 namespace tinympl {
22 
23 template<class ... KeyValuePairs>
24 struct fused_map : std::tuple<typename KeyValuePairs::second_type ... >
25 {
26  static_assert( variadic::all_of< is_pair, KeyValuePairs...>::type::value, "All the arguments of a map must be key/value pairs");
27  static_assert( variadic::is_unique<typename KeyValuePairs::first_type ...>::type::value,"Duplicate keys in the map");
28 
29  typedef std::tuple<typename KeyValuePairs::second_type ... > base_type;
30  typedef map<KeyValuePairs...> map_type;
31 
32  using base_type::base_type;
33 
34  template<class Key>
35  typename map_type::template at<Key>::type & at()
36  {
37  return std::get< map_type::template at<Key>::index >(*this);
38  }
39 
40  template<class Key>
41  typename map_type::template at<Key>::type const & at() const
42  {
43  return std::get< map_type::template at<Key>::index >(*this);
44  }
45 
46  enum {size = map_type::size};
47  enum {empty = map_type::empty};
48 
49  template<class Key>
50  using count = typename map_type::template count<Key>;
51 };
52 
53 }
54 
55 #endif // TINYMPL_FUSED_MAP_HPP
The number of elements contained in the map.
Definition: map.hpp:77
Determines whether the map is empty.
Definition: map.hpp:82