summaryrefslogtreecommitdiff
path: root/boost/spirit/home/x3/support/traits/container_traits.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/spirit/home/x3/support/traits/container_traits.hpp')
-rw-r--r--boost/spirit/home/x3/support/traits/container_traits.hpp87
1 files changed, 46 insertions, 41 deletions
diff --git a/boost/spirit/home/x3/support/traits/container_traits.hpp b/boost/spirit/home/x3/support/traits/container_traits.hpp
index ed9213b68c..b05764969c 100644
--- a/boost/spirit/home/x3/support/traits/container_traits.hpp
+++ b/boost/spirit/home/x3/support/traits/container_traits.hpp
@@ -13,12 +13,11 @@
#include <boost/spirit/home/x3/support/unused.hpp>
#include <boost/detail/iterator.hpp>
#include <boost/fusion/include/deque.hpp>
-#include <boost/mpl/has_xxx.hpp>
-#include <boost/mpl/bool.hpp>
+#include <boost/tti/has_type.hpp>
+#include <boost/tti/has_member_function.hpp>
#include <boost/mpl/identity.hpp>
#include <vector>
-#include <map>
#include <string>
#include <iterator>
#include <algorithm>
@@ -31,20 +30,28 @@ namespace boost { namespace spirit { namespace x3 { namespace traits
namespace detail
{
- BOOST_MPL_HAS_XXX_TRAIT_DEF(value_type)
- BOOST_MPL_HAS_XXX_TRAIT_DEF(iterator)
- BOOST_MPL_HAS_XXX_TRAIT_DEF(size_type)
- BOOST_MPL_HAS_XXX_TRAIT_DEF(reference)
+ BOOST_TTI_HAS_TYPE(value_type)
+ BOOST_TTI_HAS_TYPE(iterator)
+ BOOST_TTI_HAS_TYPE(size_type)
+ BOOST_TTI_HAS_TYPE(reference)
+ BOOST_TTI_HAS_TYPE(key_type)
+ BOOST_TTI_HAS_MEMBER_FUNCTION(reserve)
}
- template <typename T, typename Enable = void>
- struct is_container
- : mpl::bool_<
- detail::has_value_type<T>::value &&
- detail::has_iterator<T>::value &&
- detail::has_size_type<T>::value &&
- detail::has_reference<T>::value>
- {};
+ template <typename T>
+ using is_container = mpl::bool_<
+ detail::has_type_value_type<T>::value &&
+ detail::has_type_iterator<T>::value &&
+ detail::has_type_size_type<T>::value &&
+ detail::has_type_reference<T>::value>;
+
+ template <typename T>
+ using is_associative = mpl::bool_<
+ detail::has_type_key_type<T>::value>;
+
+ template <typename T>
+ using is_reservable = mpl::bool_<
+ detail::has_member_function_reserve<T, void, mpl::vector<size_t>>::value>;
///////////////////////////////////////////////////////////////////////////
namespace detail
@@ -112,22 +119,10 @@ namespace boost { namespace spirit { namespace x3 { namespace traits
template <typename Container, typename Enable = void>
struct push_back_container
{
- template <typename Key, typename Value, typename Compare, typename Allocator, typename T>
- static void push_back(std::map<Key, Value, Compare, Allocator>& c, T&& val)
- {
- c.insert(std::move(val));
- }
-
- template <typename Container_, typename T>
- static void push_back(Container_& c, T&& val)
- {
- c.push_back(std::move(val));
- }
-
template <typename T>
static bool call(Container& c, T&& val)
{
- push_back(c, std::move(val));
+ c.insert(c.end(), std::move(val));
return true;
}
};
@@ -145,7 +140,7 @@ namespace boost { namespace spirit { namespace x3 { namespace traits
}
template <typename T>
- inline bool push_back(unused_type, T const&)
+ inline bool push_back(unused_type, T&&)
{
return true;
}
@@ -162,27 +157,37 @@ namespace boost { namespace spirit { namespace x3 { namespace traits
template <typename Container, typename Enable = void>
struct append_container
{
- // Not all containers have "reserve"
- template <typename Container_>
- static void reserve(Container_& c, std::size_t size) {}
+ private:
+ template <typename Iterator>
+ static void reserve(Container& c, Iterator first, Iterator last, mpl::false_)
+ {
+ // Not all containers have "reserve"
+ }
+
+ template <typename Iterator>
+ static void reserve(Container& c, Iterator first, Iterator last, mpl::true_)
+ {
+ c.reserve(c.size() + std::distance(first, last));
+ }
- template <typename T, typename Allocator>
- static void reserve(std::vector<T, Allocator>& c, std::size_t size)
+ template <typename Iterator>
+ static void insert(Container& c, Iterator first, Iterator last, mpl::false_)
{
- c.reserve(size);
+ c.insert(c.end(), first, last);
}
-
- template <typename Container_, typename Iterator>
- static void insert(Container_& c, Iterator first, Iterator last)
+
+ template <typename Iterator>
+ static void insert(Container& c, Iterator first, Iterator last, mpl::true_)
{
- std::copy(first, last, std::inserter(c, c.end()));
+ c.insert(first, last);
}
+ public:
template <typename Iterator>
static bool call(Container& c, Iterator first, Iterator last)
{
- reserve(c, c.size() + std::distance(first, last));
- insert(c, first, last);
+ reserve(c, first, last, is_reservable<Container>{});
+ insert(c, first, last, is_associative<Container>{});
return true;
}
};