1 #ifndef fhiclcpp_stdmap_shims_h 2 #define fhiclcpp_stdmap_shims_h 10 #include <type_traits> 19 class Compare = std::less<Key>,
20 class Allocator = std::allocator<std::pair<const Key, T>>>
23 using mapmap_t = std::map<const Key, T, Compare, Allocator>;
24 using listmap_t = std::list<std::pair<const Key, T>, Allocator>;
26 static_assert(std::is_same_v<
typename mapmap_t::key_type,
27 typename listmap_t::value_type::first_type>,
28 "type mismatch for key_type");
29 static_assert(std::is_same_v<
typename mapmap_t::mapped_type,
30 typename listmap_t::value_type::second_type>,
31 "type mismatch for mapped_type");
32 static_assert(std::is_same_v<
typename mapmap_t::value_type,
33 typename listmap_t::value_type>,
34 "type mismatch for value_type");
35 static_assert(std::is_same_v<
typename mapmap_t::size_type,
36 typename listmap_t::size_type>,
37 "type mismatch for size_type");
47 template <
class Category,
49 class Distance = std::ptrdiff_t,
51 class Reference = TT&>
63 _iters.listmap_iter = it;
69 return isSnippetMode() ? *_iters.listmap_iter : *_iters.mapmap_iter;
75 return isSnippetMode() ? &*_iters.listmap_iter : &*_iters.mapmap_iter;
81 return isSnippetMode() ? &*_iters.listmap_iter : &*_iters.mapmap_iter;
88 *(_iters.mapmap_iter++);
95 _iters.listmap_iter ==
other._iters.listmap_iter :
96 _iters.mapmap_iter ==
other._iters.mapmap_iter;
105 template <
typename II>
106 std::enable_if_t<std::is_same_v<typename mapmap_t::iterator, II>, II>
109 return _iters.mapmap_iter;
112 template <
typename II>
113 std::enable_if_t<std::is_same_v<typename listmap_t::iterator, II>, II>
116 return _iters.listmap_iter;
119 template <
typename IIL,
typename IIR>
120 friend std::enable_if_t<
121 !std::is_same_v<IIL, IIR> &&
122 std::is_same_v<std::remove_const_t<typename IIL::type>,
123 std::remove_const_t<typename IIR::type>>,
127 template <
typename IIL,
typename IIR>
128 friend std::enable_if_t<
129 !std::is_same_v<IIL, IIR> &&
130 std::is_same_v<std::remove_const_t<typename IIL::type>,
131 std::remove_const_t<typename IIR::type>>,
152 if (stored_key == key)
210 [&key](
auto& element) {
return element.first == key; });
212 throw std::out_of_range(
"Key <" + key +
"> not found.");
220 at(Key
const& key)
const 223 auto it = std::find_if(
226 [&key](
auto const& element) {
return element.first == key; });
228 throw std::out_of_range(
"Key <" + key +
"> not found.");
241 return element.first == key;
257 [&key](
auto const& element) {
return element.first == key; });
259 return maps.
mapmap.find(key);
267 auto erase_count =
size_t{0};
272 if (key == i->first) {
317 template <
class... Args>
318 std::pair<iterator, bool>
322 _maps.
listmap.emplace_back(std::forward<Args>(args)...);
325 auto result =
_maps.
mapmap.emplace(std::forward<Args>(args)...);
326 return std::make_pair(
iterator{result.first}, result.second);
332 template <
typename IIL,
typename IIR>
333 std::enable_if_t<!std::is_same_v<IIL, IIR> &&
334 std::is_same_v<std::remove_const_t<typename IIL::type>,
335 std::remove_const_t<typename IIR::type>>,
340 left._iters.listmap_iter ==
right._iters.listmap_iter :
341 left._iters.mapmap_iter ==
right._iters.mapmap_iter;
344 template <
typename IIL,
typename IIR>
345 std::enable_if_t<!std::is_same_v<IIL, IIR> &&
346 std::is_same_v<std::remove_const_t<typename IIL::type>,
347 std::remove_const_t<typename IIR::type>>,
const_iterator cbegin() const noexcept
size_t erase(Key const &key)
TT const * operator->() const noexcept
iter(typename mapmap_t::iterator it) noexcept
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
bool operator!=(iter other) const noexcept
const_iterator end() const noexcept
listmap_t::iterator listmap_iter
Category iterator_category
TT * operator->() noexcept
std::pair< iterator, bool > emplace(Args &&...args)
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
iter(typename listmap_t::iterator it) noexcept
bool empty() const noexcept
std::enable_if_t< std::is_same_v< typename mapmap_t::iterator, II >, II > get(II)
size_type size() const noexcept
mapmap_t::iterator mapmap_iter
std::enable_if_t<!std::is_same_v< IIL, IIR > &&std::is_same_v< std::remove_const_t< typename IIL::type >, std::remove_const_t< typename IIR::type > >, bool > operator==(IIL left, IIR right) noexcept
std::enable_if_t<!std::is_same_v< IIL, IIR > &&std::is_same_v< std::remove_const_t< typename IIL::type >, std::remove_const_t< typename IIR::type > >, bool > operator!=(IIL left, IIR right) noexcept
T const & at(Key const &key) const
bool operator==(iter other) const noexcept
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
iterator erase(iterator it)
T & operator[](Key const &key)
iterator begin() noexcept
TT & operator*() noexcept
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
std::list< std::pair< const Key, T >, Allocator > listmap_t
bool isSnippetMode(bool m=false) noexcept
iterator find(Key const &key)
typename mapmap_t::size_type size_type
std::input_iterator_tag iterator_tag
std::map< const Key, T, Compare, Allocator > mapmap_t
iterator erase(const_iterator &it)
const_iterator cend() const noexcept
const_iterator find(Key const &key) const
const_iterator begin() const noexcept