6#include <bond/core/config.h>
8#include "container_interface.h"
11#include <boost/utility/enable_if.hpp>
25template <
typename Key>
26[[noreturn]]
void ElementNotFoundException(
const Key& key);
29template<
typename T,
typename A>
struct
30is_string<std::basic_string<char, T, A> >
35template<
typename T,
typename A>
struct
36is_wstring<std::basic_string<wchar_t, T, A> >
41template <
typename T>
struct
43 : std::integral_constant<bool,
44 is_string<typename std::remove_const<T>::type>::value
45 || is_wstring<typename std::remove_const<T>::type>::value> {};
49template <
typename T,
typename A>
struct
50is_list_container<std::list<T, A> >
55template <
typename T,
typename A>
struct
56is_list_container<std::vector<T, A> >
61template <
typename A>
struct
62require_modify_element<std::vector<bool, A> >
67template <
typename T,
typename C,
typename A>
struct
68is_set_container<std::set<T, C, A> >
73template <
typename K,
typename T,
typename C,
typename A>
struct
74is_map_container<std::map<K, T, C, A> >
79template <
typename K,
typename T,
typename C,
typename A>
struct
80element_type<std::map<K, T, C, A> >
82 typedef typename std::pair<K, T> type;
87template<
typename C,
typename T,
typename A>
89const C* string_data(
const std::basic_string<C, T, A>& str)
95template<
typename C,
typename T,
typename A>
97C* string_data(std::basic_string<C, T, A>& str)
103 return str.size() ? &*str.begin() : &c;
108template<
typename C,
typename T,
typename A>
110uint32_t string_length(
const std::basic_string<C, T, A>& str)
112 return static_cast<uint32_t
>(str.length());
117template<
typename C,
typename T,
typename A>
119void resize_string(std::basic_string<C, T, A>& str, uint32_t size)
128uint32_t container_size(
const T& list)
130 return static_cast<uint32_t
>(list.size());
135template <
typename T,
typename Enable =
void>
struct
136use_container_allocator_for_elements
137 : std::false_type {};
140template <
typename T>
struct
141use_container_allocator_for_elements<T,
typename boost::enable_if_c<
142 std::uses_allocator<typename element_type<T>::type,
typename T::allocator_type>::value>::type>
149typename boost::disable_if_c<use_container_allocator_for_elements<T>::value,
typename element_type<T>::type>::type
152 return typename element_type<T>::type();
158typename boost::enable_if<use_container_allocator_for_elements<T>,
typename element_type<T>::type>::type
159make_element(T& container)
161 return typename element_type<T>::type(container.get_allocator());
168typename boost::disable_if<use_container_allocator_for_elements<T> >::type
169resize_list(T& list, uint32_t size)
171 list.resize(size, make_element(list));
177typename boost::enable_if<use_container_allocator_for_elements<T> >::type
178resize_list(T& list, uint32_t size)
181 list.resize(size, make_element(list));
186template <
typename A,
typename F>
188void modify_element(std::vector<bool, A>&,
189 typename std::vector<bool, A>::reference element,
200template <
typename T,
typename C,
typename A>
202void clear_set(std::set<T, C, A>& set)
209template <
typename T,
typename C,
typename A>
211void set_insert(std::set<T, C, A>& set,
const T& item)
218template <
typename K,
typename T,
typename C,
typename A>
220void clear_map(std::map<K, T, C, A>& map)
227template <
typename T,
typename Enable =
void>
struct
228use_map_allocator_for_keys
229 : std::false_type {};
232template <
typename T>
struct
233use_map_allocator_for_keys<T,
typename boost::enable_if<
234 std::uses_allocator<typename element_type<T>::type::first_type,
typename T::allocator_type> >::type>
241typename boost::disable_if<use_map_allocator_for_keys<T>,
typename element_type<T>::type::first_type>::type
244 return typename element_type<T>::type::first_type();
250typename boost::enable_if<use_map_allocator_for_keys<T>,
typename element_type<T>::type::first_type>::type
253 return typename element_type<T>::type::first_type(map.get_allocator());
258template <
typename T,
typename Enable =
void>
struct
259use_map_allocator_for_values
260 : std::false_type {};
263template <
typename T>
struct
264use_map_allocator_for_values<T,
typename boost::enable_if<
265 std::uses_allocator<typename element_type<T>::type::second_type,
typename T::allocator_type> >::type>
272typename boost::disable_if_c<use_map_allocator_for_values<T>::value,
273 typename element_type<T>::type::second_type>::type
276 return typename element_type<T>::type::second_type();
282typename boost::enable_if<use_map_allocator_for_values<T>,
typename element_type<T>::type::second_type>::type
285 return typename element_type<T>::type::second_type(map.get_allocator());
290template <
typename K,
typename T,
typename C,
typename A>
292T& mapped_at(std::map<K, T, C, A>& map,
const K& key)
294 return map.insert(
typename std::map<K, T, C, A>::value_type(key, make_value(map))).first->second;
297template <
typename K,
typename T,
typename C,
typename A>
299const T& mapped_at(
const std::map<K, T, C, A>& map,
const K& key)
301 typename std::map<K, T, C, A>::const_iterator it = map.find(key);
304 ElementNotFoundException(key);
312class const_enumerator
315 explicit const_enumerator(
const T& list)
325 typename T::const_reference
332 typename T::const_iterator it, end;
336class const_enumerator<
std::vector<bool, A> >
339 explicit const_enumerator(
const std::vector<bool, A>& list)
355 typename std::vector<bool, A>::const_iterator it, end;
362 explicit enumerator(T& list)
372 typename T::reference
379 typename T::iterator it, end;
383template <
typename K,
typename V>
384std::map<V, K> reverse_map(
const std::map<K, V>& map)
386 std::map<V, K> reversed;
388 for (
typename std::map<K, V>::const_iterator it = map.begin(); it != map.end(); ++it)
389 reversed[it->second] = it->first;
namespace bond
Definition: apply.h:17