13 #ifndef TINYMPL_MAP_HPP
14 #define TINYMPL_MAP_HPP
16 #include <tinympl/equal_to.hpp>
17 #include <tinympl/variadic/all_of.hpp>
18 #include <tinympl/variadic/is_unique.hpp>
19 #include <tinympl/variadic/find.hpp>
20 #include <tinympl/variadic/at.hpp>
21 #include <tinympl/variadic/left_fold.hpp>
22 #include <tinympl/variadic/remove_if.hpp>
23 #include <tinympl/unordered_equal.hpp>
24 #include <tinympl/sequence.hpp>
25 #include <type_traits>
33 template<
class T>
struct is_pair : std::false_type {};
35 template<
class FirstType,
class SecondType>
36 struct is_pair<std::pair<FirstType,SecondType> > : std::true_type
38 typedef FirstType first_type;
39 typedef SecondType second_type;
56 template<
class ... Args>
struct map
68 enum {index =
variadic::find<T,
typename Args::first_type ... >::type::value };
70 static_assert(index <
sizeof...(Args),
"Key T not present in the map");
72 typedef typename variadic::at<index,Args...>::type::second_type type;
90 using count = std::integral_constant<
98 template<
class Key,
class Value>
100 count<Key>::type::value == 0,
101 map<Args..., std::pair<Key,Value> >,
108 template<
class ... KeyValuePairs>
124 template<
class T>
using key_comparer = std::is_same<typename T::first_type,Key>;
133 template<
class ... As,
class ... Bs>
138 #endif // TINYMPL_MAP_HPP
Determines whether every element in the sequence satisfies the given predicate.
Definition: all_of.hpp:31
Calls insert many times to insert many Key/Value pairs.
Definition: map.hpp:109
Extract the i-th element of a variadic template.
Definition: at.hpp:27
Determines whether it is possible to reorder the sequence A to match exactly the sequence B ...
Definition: unordered_equal.hpp:40
Return a new map constructed by the current map removing the Key key, if present, otherwise return th...
Definition: map.hpp:122
Remove the elements from the input sequence if they satisfy a given predicate.
Definition: remove_if.hpp:39
Collapses a sequence starting from left using a functor.
Definition: left_fold.hpp:28
Determines whether the types A and B are equal.
Definition: equal_to.hpp:27
Get the number of elements of a sequence.
Definition: size.hpp:27
Compute the index of the first element in the sequence which is equal to the given type T...
Definition: find.hpp:38
std::integral_constant< std::size_t,(variadic::find< Key, typename Args::first_type... >::type::value==size?0:1)> count
Count the number of elements in the map with a given key.
Definition: map.hpp:92
Returns a new map with the new Key/Value pair, or this map if the key is already present in the map...
Definition: map.hpp:99
Return the value element with the given key.
Definition: map.hpp:66
A compile time map from a type to another This class represents a compile time mapping between types...
Definition: map.hpp:56
Determines whether the input sequence contains only unique elements.
Definition: is_unique.hpp:35
Determine whether a type is an std::pair
Definition: map.hpp:33
Determines whether the map is empty.
Definition: map.hpp:82