13 #ifndef TINYMPL_FUSED_VALUE_MAP_HPP
14 #define TINYMPL_FUSED_VALUE_MAP_HPP
17 #include <tinympl/algorithm_variadic.hpp>
21 template<
class KeyType,
class ValueType,KeyType... Keys>
22 struct fused_value_map
24 static_assert( variadic::is_unique< std::integral_constant<KeyType,Keys>...>::type::value,
"There are duplicate keys");
26 typedef ValueType value_type;
27 typedef value_type* pointer;
28 typedef const value_type* const_pointer;
29 typedef value_type& reference;
30 typedef const value_type& const_reference;
31 typedef value_type* iterator;
32 typedef const value_type* const_iterator;
33 typedef std::size_t size_type;
34 typedef std::ptrdiff_t difference_type;
35 typedef std::reverse_iterator<iterator> reverse_iterator;
36 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
39 static constexpr size_type size() noexcept {
return sizeof ... (Keys); }
40 static constexpr size_type max_size() {
return size(); }
41 static constexpr
bool empty() noexcept {
return size() == 0; }
43 void fill(
const value_type& __u) { std::fill_n(begin(), size(), __u); }
44 void swap(fused_value_map& __other) noexcept(noexcept(swap(std::declval<reference>(), std::declval<reference>())))
45 { std::swap_ranges(begin(), end(), __other.begin()); }
47 iterator begin() noexcept
48 {
return iterator(data()); }
50 const_iterator begin() const noexcept
51 {
return const_iterator(data()); }
53 iterator end() noexcept
54 {
return iterator(data() + size()); }
56 const_iterator end() const noexcept
57 {
return const_iterator(data() + size()); }
59 reverse_iterator rbegin() noexcept
60 {
return reverse_iterator(end()); }
62 const_reverse_iterator rbegin() const noexcept
63 {
return const_reverse_iterator(end()); }
65 reverse_iterator rend() noexcept
66 {
return reverse_iterator(begin()); }
68 const_reverse_iterator rend() const noexcept
69 {
return const_reverse_iterator(begin()); }
71 const_iterator cbegin() const noexcept
72 {
return const_iterator(data()); }
74 const_iterator cend() const noexcept
75 {
return const_iterator(data() + size()); }
77 const_reverse_iterator crbegin() const noexcept
78 {
return const_reverse_iterator(end()); }
80 const_reverse_iterator crend() const noexcept
81 {
return const_reverse_iterator(begin()); }
85 enum {value = variadic::find<
86 std::integral_constant<KeyType,k>,
87 std::integral_constant<KeyType,Keys>...>::type::value};
88 static_assert( value < size(),
"Key not present in map");
93 const_reference at()
const {
94 enum {value = variadic::find<
95 std::integral_constant<KeyType,k>,
96 std::integral_constant<KeyType,Keys>...>::type::value};
97 static_assert( value < size(),
"Key not present in map");
101 pointer data() noexcept {
return std::addressof( elems_[0] ); }
102 const_pointer data() const noexcept {
return std::addressof( elems_[0] ); }
104 value_type elems_[ size() > 0 ? size() : 1 ];
106 inline friend bool operator==(
const fused_value_map & lhs,
const fused_value_map & rhs)
107 {
return std::equal(lhs.begin(), lhs.end(), rhs.begin()); }
109 inline friend bool operator!=(
const fused_value_map & lhs,
const fused_value_map & rhs)
110 {
return !(lhs == rhs); }
112 inline friend bool operator<(
const fused_value_map & lhs,
const fused_value_map & rhs)
113 {
return std::lexicographical_compare(lhs.begin(), lhs.end(),rhs.begin(), rhs.end()); }
114 inline friend bool operator>(
const fused_value_map & lhs,
const fused_value_map & rhs)
115 {
return rhs < lhs; }
117 inline friend bool operator<=(
const fused_value_map & lhs,
const fused_value_map & rhs)
118 {
return !(lhs > rhs); }
120 inline friend bool operator>=(
const fused_value_map & lhs,
const fused_value_map & rhs)
121 {
return !(lhs < rhs); }
126 #endif // TINYMPL_FUSED_VALUE_MAP_HPP