diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2016-10-06 10:38:45 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2016-10-06 10:39:52 +0900 |
commit | 5cde13f21d36c7224b0e13d11c4b49379ae5210d (patch) | |
tree | e8269ac85a4b0f7d416e2565fa4f451b5cb41351 /boost/spirit/home | |
parent | d9ec475d945d3035377a0d89ed42e382d8988891 (diff) | |
download | boost-5cde13f21d36c7224b0e13d11c4b49379ae5210d.tar.gz boost-5cde13f21d36c7224b0e13d11c4b49379ae5210d.tar.bz2 boost-5cde13f21d36c7224b0e13d11c4b49379ae5210d.zip |
Imported Upstream version 1.61.0
Change-Id: I96a1f878d1e6164f01e9aadd5147f38fca448d90
Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'boost/spirit/home')
24 files changed, 178 insertions, 102 deletions
diff --git a/boost/spirit/home/classic/core/non_terminal/impl/grammar.ipp b/boost/spirit/home/classic/core/non_terminal/impl/grammar.ipp index 1f18b3255c..002d221eeb 100644 --- a/boost/spirit/home/classic/core/non_terminal/impl/grammar.ipp +++ b/boost/spirit/home/classic/core/non_terminal/impl/grammar.ipp @@ -281,17 +281,19 @@ struct grammar_definition grammar_destruct(GrammarT* self) { #if !defined(BOOST_SPIRIT_SINGLE_GRAMMAR_INSTANCE) - typedef impl::grammar_helper_base<GrammarT> helper_base_t; typedef grammar_helper_list<GrammarT> helper_list_t; - typedef typename helper_list_t::vector_t::reverse_iterator iterator_t; helper_list_t& helpers = grammartract_helper_list::do_(self); # if defined(BOOST_INTEL_CXX_VERSION) + typedef typename helper_list_t::vector_t::reverse_iterator iterator_t; + for (iterator_t i = helpers.rbegin(); i != helpers.rend(); ++i) (*i)->undefine(self); # else + typedef impl::grammar_helper_base<GrammarT> helper_base_t; + std::for_each(helpers.rbegin(), helpers.rend(), std::bind2nd(std::mem_fun(&helper_base_t::undefine), self)); # endif diff --git a/boost/spirit/home/classic/core/non_terminal/impl/rule.ipp b/boost/spirit/home/classic/core/non_terminal/impl/rule.ipp index 9f10306f7c..137694ef2f 100644 --- a/boost/spirit/home/classic/core/non_terminal/impl/rule.ipp +++ b/boost/spirit/home/classic/core/non_terminal/impl/rule.ipp @@ -24,6 +24,7 @@ #include <boost/spirit/home/classic/core/non_terminal/parser_context.hpp> #include <boost/spirit/home/classic/core/non_terminal/parser_id.hpp> #include <boost/type_traits/is_base_and_derived.hpp> +#include <boost/mpl/if.hpp> /////////////////////////////////////////////////////////////////////////////// namespace boost { namespace spirit { diff --git a/boost/spirit/home/classic/core/non_terminal/impl/subrule.ipp b/boost/spirit/home/classic/core/non_terminal/impl/subrule.ipp index f6bdaaf40d..fc952fedea 100644 --- a/boost/spirit/home/classic/core/non_terminal/impl/subrule.ipp +++ b/boost/spirit/home/classic/core/non_terminal/impl/subrule.ipp @@ -10,6 +10,8 @@ #if !defined(BOOST_SPIRIT_SUBRULE_IPP) #define BOOST_SPIRIT_SUBRULE_IPP +#include <boost/mpl/if.hpp> + namespace boost { namespace spirit { BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN diff --git a/boost/spirit/home/classic/core/non_terminal/subrule.hpp b/boost/spirit/home/classic/core/non_terminal/subrule.hpp index 8b25d8d0e3..1d16d70aea 100644 --- a/boost/spirit/home/classic/core/non_terminal/subrule.hpp +++ b/boost/spirit/home/classic/core/non_terminal/subrule.hpp @@ -11,6 +11,9 @@ #include <boost/config.hpp> #include <boost/static_assert.hpp> +#include <boost/mpl/if.hpp> +#include <boost/mpl/bool.hpp> +#include <boost/type_traits/is_same.hpp> #include <boost/spirit/home/classic/namespace.hpp> #include <boost/spirit/home/classic/core/parser.hpp> diff --git a/boost/spirit/home/classic/iterator/position_iterator.hpp b/boost/spirit/home/classic/iterator/position_iterator.hpp index e352f883ae..5607047264 100644 --- a/boost/spirit/home/classic/iterator/position_iterator.hpp +++ b/boost/spirit/home/classic/iterator/position_iterator.hpp @@ -95,7 +95,7 @@ BOOST_SPIRIT_CLASSIC_NAMESPACE_END // This must be included here for full compatibility with old MSVC -#include "boost/spirit/home/classic/iterator/impl/position_iterator.ipp" +#include <boost/spirit/home/classic/iterator/impl/position_iterator.ipp> /////////////////////////////////////////////////////////////////////////////// namespace boost { namespace spirit { diff --git a/boost/spirit/home/classic/tree/parse_tree_utils.hpp b/boost/spirit/home/classic/tree/parse_tree_utils.hpp index 105d80eb13..b9e52e3a2d 100644 --- a/boost/spirit/home/classic/tree/parse_tree_utils.hpp +++ b/boost/spirit/home/classic/tree/parse_tree_utils.hpp @@ -59,6 +59,6 @@ BOOST_SPIRIT_CLASSIC_NAMESPACE_END } // namespace spirit } // namespace boost -#include "boost/spirit/home/classic/tree/impl/parse_tree_utils.ipp" +#include <boost/spirit/home/classic/tree/impl/parse_tree_utils.ipp> #endif // !defined(PARSE_TREE_UTILS_HPP) diff --git a/boost/spirit/home/qi/string/tst_map.hpp b/boost/spirit/home/qi/string/tst_map.hpp index a3208f2743..19f977ddce 100644 --- a/boost/spirit/home/qi/string/tst_map.hpp +++ b/boost/spirit/home/qi/string/tst_map.hpp @@ -11,14 +11,13 @@ #pragma once #endif +#include <boost/spirit/home/qi/string/tst.hpp> #include <boost/spirit/home/qi/string/detail/tst.hpp> #include <boost/unordered_map.hpp> #include <boost/pool/object_pool.hpp> namespace boost { namespace spirit { namespace qi { - struct tst_pass_through; // declared in tst.hpp - template <typename Char, typename T> struct tst_map { diff --git a/boost/spirit/home/support/extended_variant.hpp b/boost/spirit/home/support/extended_variant.hpp index 4d3ae599d6..bb2ea0d353 100644 --- a/boost/spirit/home/support/extended_variant.hpp +++ b/boost/spirit/home/support/extended_variant.hpp @@ -104,6 +104,11 @@ namespace boost { namespace spirit { return var; } + + void swap(extended_variant& rhs) BOOST_NOEXCEPT + { + var.swap(rhs.var); + } variant_type var; }; diff --git a/boost/spirit/home/support/terminal.hpp b/boost/spirit/home/support/terminal.hpp index 0497d5faf4..dd52da9c25 100644 --- a/boost/spirit/home/support/terminal.hpp +++ b/boost/spirit/home/support/terminal.hpp @@ -13,6 +13,7 @@ #pragma once #endif +#include <boost/config.hpp> #include <boost/spirit/include/phoenix_core.hpp> #include <boost/spirit/include/phoenix_function.hpp> #include <boost/proto/proto.hpp> @@ -261,6 +262,12 @@ namespace boost { namespace spirit : base_type(proto::terminal<Terminal>::type::make(t)) {} +#if defined(BOOST_MSVC) +#pragma warning(push) +// warning C4348: 'boost::spirit::terminal<...>::result_helper': redefinition of default parameter: parameter 3, 4 +#pragma warning(disable: 4348) +#endif + template < bool Lazy , typename A0 @@ -269,6 +276,10 @@ namespace boost { namespace spirit > struct result_helper; +#if defined(BOOST_MSVC) +#pragma warning(pop) +#endif + template < typename A0 > diff --git a/boost/spirit/home/x3/auxiliary/eol.hpp b/boost/spirit/home/x3/auxiliary/eol.hpp index 00e4488937..69a58ec60e 100644 --- a/boost/spirit/home/x3/auxiliary/eol.hpp +++ b/boost/spirit/home/x3/auxiliary/eol.hpp @@ -16,7 +16,7 @@ namespace boost { namespace spirit { namespace x3 { struct eol_parser : parser<eol_parser> { - typedef unused_type attribute_type; + typedef unused_type attribute_type; static bool const has_attribute = false; template <typename Iterator, typename Context, typename Attribute> diff --git a/boost/spirit/home/x3/binary/binary.hpp b/boost/spirit/home/x3/binary/binary.hpp index b3d3a79473..551e5b3865 100644 --- a/boost/spirit/home/x3/binary/binary.hpp +++ b/boost/spirit/home/x3/binary/binary.hpp @@ -30,6 +30,7 @@ namespace boost { namespace spirit { namespace x3 : parser<binary_lit_parser<V, T, endian, bits> > { static bool const has_attribute = false; + typedef unused_type attribute_type; binary_lit_parser(V n_) : n(n_) {} diff --git a/boost/spirit/home/x3/char/any_char.hpp b/boost/spirit/home/x3/char/any_char.hpp index 380645d2ff..6add7b6473 100644 --- a/boost/spirit/home/x3/char/any_char.hpp +++ b/boost/spirit/home/x3/char/any_char.hpp @@ -54,7 +54,7 @@ namespace boost { namespace spirit { namespace x3 template <typename Char> char_range<Encoding> operator()(Char (&from)[2], Char (&to)[2]) const { - return { from[0], to[0] }; + return { static_cast<char_type>(from[0]), static_cast<char_type>(to[0]) }; } template <typename Char> diff --git a/boost/spirit/home/x3/core/parse.hpp b/boost/spirit/home/x3/core/parse.hpp index 234903037f..63878e0756 100644 --- a/boost/spirit/home/x3/core/parse.hpp +++ b/boost/spirit/home/x3/core/parse.hpp @@ -106,6 +106,9 @@ namespace boost { namespace spirit { namespace x3 // calling this function. You need to supply at least a forward_iterator // instead. BOOST_CONCEPT_ASSERT((ForwardIterator<Iterator>)); + + static_assert(!std::is_same<Skipper, unused_type>::value, + "Error! Skipper cannot be unused_type."); // If you get an error no matching function for call to 'as_parser' // here, for either p or s, then p or s is not a parser or there is diff --git a/boost/spirit/home/x3/directive/expect.hpp b/boost/spirit/home/x3/directive/expect.hpp index 879d92c2df..fe4491a22e 100644 --- a/boost/spirit/home/x3/directive/expect.hpp +++ b/boost/spirit/home/x3/directive/expect.hpp @@ -9,6 +9,8 @@ #include <boost/spirit/home/x3/support/context.hpp> #include <boost/spirit/home/x3/core/parser.hpp> +#include <boost/spirit/home/x3/core/detail/parse_into_container.hpp> + #include <boost/throw_exception.hpp> #include <stdexcept> @@ -24,10 +26,10 @@ namespace boost { namespace spirit { namespace x3 , where_(where), which_(which) {} ~expectation_failure() throw() {} - + std::string which() const { return which_; } Iterator const& where() const { return where_; } - + private: Iterator where_; @@ -73,4 +75,30 @@ namespace boost { namespace spirit { namespace x3 auto const expect = expect_gen{}; }}} +namespace boost { namespace spirit { namespace x3 { namespace detail +{ + // Special case handling for expect expressions. + template <typename Subject, typename Context, typename RContext> + struct parse_into_container_impl<expect_directive<Subject>, Context, RContext> + { + template <typename Iterator, typename Attribute> + static bool call( + expect_directive<Subject> const& parser + , Iterator& first, Iterator const& last + , Context const& context, RContext& rcontext, Attribute& attr) + { + bool r = parse_into_container( + parser.subject, first, last, context, rcontext, attr); + + if (!r) + { + boost::throw_exception( + expectation_failure<Iterator>( + first, what(parser.subject))); + } + return r; + } + }; +}}}} + #endif diff --git a/boost/spirit/home/x3/directive/with.hpp b/boost/spirit/home/x3/directive/with.hpp index 359f5adf1c..153c236b22 100644 --- a/boost/spirit/home/x3/directive/with.hpp +++ b/boost/spirit/home/x3/directive/with.hpp @@ -72,7 +72,7 @@ namespace boost { namespace spirit { namespace x3 template <typename ID, typename T> struct with_context<ID, T, unused_type> { - typedef context<ID, T> const type; + typedef context<ID, T> type; }; template <typename ID, typename T> diff --git a/boost/spirit/home/x3/nonterminal/detail/rule.hpp b/boost/spirit/home/x3/nonterminal/detail/rule.hpp index 71dc4c549f..e07b067718 100644 --- a/boost/spirit/home/x3/nonterminal/detail/rule.hpp +++ b/boost/spirit/home/x3/nonterminal/detail/rule.hpp @@ -318,17 +318,18 @@ namespace boost { namespace spirit { namespace x3 { namespace detail //called inside the following scope. ; { - //Create a scope to cause the dbg variable below (within - //the #if...#endif) to call it's DTOR before any - //modifications are made to the attribute, attr_ passed - //to parse_rhs (such as might be done in - //traits::post_transform when, for example, - //ActualAttribute is a recursive variant). + // Create a scope to cause the dbg variable below (within + // the #if...#endif) to call it's DTOR before any + // modifications are made to the attribute, attr_ passed + // to parse_rhs (such as might be done in + // traits::post_transform when, for example, + // ActualAttribute is a recursive variant). #if defined(BOOST_SPIRIT_X3_DEBUG) - context_debug<Iterator, typename make_attribute::value_type> - dbg(rule_name, first, last, attr_, ok_parse); + typedef typename make_attribute::type dbg_attribute_type; + context_debug<Iterator, dbg_attribute_type> + dbg(rule_name, first, last, dbg_attribute_type(attr_), ok_parse); #endif - ok_parse=parse_rhs(rhs, first, last, context, attr_, attr_ + ok_parse = parse_rhs(rhs, first, last, context, attr_, attr_ , mpl::bool_ < ( RHS::has_action && !ExplicitAttrPropagation::value @@ -336,11 +337,11 @@ namespace boost { namespace spirit { namespace x3 { namespace detail >() ); } - if(ok_parse) + if (ok_parse) { // do up-stream transformation, this integrates the results // back into the original attribute value, if appropriate - traits::post_transform(attr, attr_); + traits::post_transform(attr, std::forward<transform_attr>(attr_)); } return ok_parse; } diff --git a/boost/spirit/home/x3/nonterminal/detail/transform_attribute.hpp b/boost/spirit/home/x3/nonterminal/detail/transform_attribute.hpp index b1929f8993..88ba3ea5bb 100644 --- a/boost/spirit/home/x3/nonterminal/detail/transform_attribute.hpp +++ b/boost/spirit/home/x3/nonterminal/detail/transform_attribute.hpp @@ -10,6 +10,7 @@ #include <boost/spirit/home/x3/support/traits/transform_attribute.hpp> #include <boost/spirit/home/x3/support/traits/move_to.hpp> +#include <utility> /////////////////////////////////////////////////////////////////////////////// namespace boost { namespace spirit { namespace x3 @@ -23,9 +24,9 @@ namespace boost { namespace spirit { namespace x3 static Transformed pre(Exposed&) { return Transformed(); } - static void post(Exposed& val, Transformed& attr) + static void post(Exposed& val, Transformed&& attr) { - traits::move_to(attr, val); + traits::move_to(std::forward<Transformed>(attr), val); } }; @@ -101,7 +102,8 @@ namespace boost { namespace spirit { namespace x3 { namespace traits template <typename Exposed, typename Transformed> void post_transform(Exposed& dest, Transformed&& attr) { - return transform_attribute<Exposed, Transformed, x3::parser_id>::post(dest, attr); + return transform_attribute<Exposed, Transformed, x3::parser_id> + ::post(dest, std::forward<Transformed>(attr)); } }}}} diff --git a/boost/spirit/home/x3/nonterminal/simple_trace.hpp b/boost/spirit/home/x3/nonterminal/simple_trace.hpp index dd369c811b..2b7969a71f 100644 --- a/boost/spirit/home/x3/nonterminal/simple_trace.hpp +++ b/boost/spirit/home/x3/nonterminal/simple_trace.hpp @@ -14,7 +14,7 @@ #include <boost/spirit/home/x3/nonterminal/debug_handler_state.hpp> #include <boost/fusion/include/out.hpp> #include <boost/type_traits/is_same.hpp> -#include <ostream> +#include <iostream> // The stream to use for debug output #if !defined(BOOST_SPIRIT_X3_DEBUG_OUT) diff --git a/boost/spirit/home/x3/operator/detail/sequence.hpp b/boost/spirit/home/x3/operator/detail/sequence.hpp index e54a8f6a9e..2c804cc78a 100644 --- a/boost/spirit/home/x3/operator/detail/sequence.hpp +++ b/boost/spirit/home/x3/operator/detail/sequence.hpp @@ -103,30 +103,30 @@ namespace boost { namespace spirit { namespace x3 { namespace detail } }; - template <typename Parser, typename Attribute> + template <typename Parser, typename Attribute, bool pass_through> struct pass_sequence_attribute_used : - mpl::if_< - traits::is_size_one_sequence<Attribute> + mpl::if_c< + (!pass_through && traits::is_size_one_sequence<Attribute>::value) , pass_sequence_attribute_front<Attribute> , pass_through_sequence_attribute<Attribute>>::type {}; - template <typename Parser, typename Attribute, typename Enable = void> + template <typename Parser, typename Attribute, bool pass_through = false, typename Enable = void> struct pass_sequence_attribute : mpl::if_< fusion::result_of::empty<Attribute> , pass_sequence_attribute_unused - , pass_sequence_attribute_used<Parser, Attribute>>::type {}; + , pass_sequence_attribute_used<Parser, Attribute, pass_through>>::type {}; - template <typename L, typename R, typename Attribute> - struct pass_sequence_attribute<sequence<L, R>, Attribute> + template <typename L, typename R, typename Attribute, bool pass_through> + struct pass_sequence_attribute<sequence<L, R>, Attribute, pass_through> : pass_through_sequence_attribute<Attribute> {}; template <typename Parser, typename Attribute> struct pass_sequence_attribute_subject : pass_sequence_attribute<typename Parser::subject_type, Attribute> {}; - template <typename Parser, typename Attribute> - struct pass_sequence_attribute<Parser, Attribute + template <typename Parser, typename Attribute, bool pass_through> + struct pass_sequence_attribute<Parser, Attribute, pass_through , typename enable_if_c<(Parser::is_pass_through_unary)>::type> : pass_sequence_attribute_subject<Parser, Attribute> {}; @@ -150,8 +150,8 @@ namespace boost { namespace spirit { namespace x3 { namespace detail typedef typename fusion::result_of::end<Attribute>::type r_end; typedef fusion::iterator_range<l_begin, l_end> l_part; typedef fusion::iterator_range<l_end, r_end> r_part; - typedef pass_sequence_attribute<L, l_part> l_pass; - typedef pass_sequence_attribute<R, r_part> r_pass; + typedef pass_sequence_attribute<L, l_part, false> l_pass; + typedef pass_sequence_attribute<R, r_part, false> r_pass; static l_part left(Attribute& s) { @@ -175,7 +175,7 @@ namespace boost { namespace spirit { namespace x3 { namespace detail typedef unused_type l_part; typedef Attribute& r_part; typedef pass_sequence_attribute_unused l_pass; - typedef pass_sequence_attribute<R, Attribute> r_pass; + typedef pass_sequence_attribute<R, Attribute, true> r_pass; static unused_type left(Attribute&) { @@ -195,7 +195,7 @@ namespace boost { namespace spirit { namespace x3 { namespace detail { typedef Attribute& l_part; typedef unused_type r_part; - typedef pass_sequence_attribute<L, Attribute> l_pass; + typedef pass_sequence_attribute<L, Attribute, true> l_pass; typedef pass_sequence_attribute_unused r_pass; static Attribute& left(Attribute& s) diff --git a/boost/spirit/home/x3/string/literal_string.hpp b/boost/spirit/home/x3/string/literal_string.hpp index c562721b2e..5066fe18a9 100644 --- a/boost/spirit/home/x3/string/literal_string.hpp +++ b/boost/spirit/home/x3/string/literal_string.hpp @@ -70,10 +70,10 @@ namespace boost { namespace spirit { namespace x3 } template <typename Char> - literal_string<Char const*, char_encoding::standard, unused_type> + literal_string<std::basic_string<Char>, char_encoding::standard, unused_type> lit(std::basic_string<Char> const& s) { - return { s.c_str() }; + return { s }; } } @@ -97,10 +97,10 @@ namespace boost { namespace spirit { namespace x3 return { s }; } - inline literal_string<wchar_t const*, char_encoding::standard_wide, unused_type> + inline literal_string<std::basic_string<wchar_t>, char_encoding::standard_wide, unused_type> lit(std::basic_string<wchar_t> const& s) { - return { s.c_str() }; + return { s }; } } @@ -125,10 +125,10 @@ namespace boost { namespace spirit { namespace x3 } template <typename Char> - literal_string<Char const*, char_encoding::ascii, unused_type> + literal_string<std::basic_string<Char>, char_encoding::ascii, unused_type> lit(std::basic_string<Char> const& s) { - return { s.c_str() }; + return { s }; } } @@ -153,10 +153,10 @@ namespace boost { namespace spirit { namespace x3 } template <typename Char> - literal_string<Char const*, char_encoding::iso8859_1, unused_type> + literal_string<std::basic_string<Char>, char_encoding::iso8859_1, unused_type> lit(std::basic_string<Char> const& s) { - return { s.c_str() }; + return { s }; } } diff --git a/boost/spirit/home/x3/string/symbols.hpp b/boost/spirit/home/x3/string/symbols.hpp index 2d00944be2..1846c57bad 100644 --- a/boost/spirit/home/x3/string/symbols.hpp +++ b/boost/spirit/home/x3/string/symbols.hpp @@ -198,6 +198,7 @@ namespace boost { namespace spirit { namespace x3 } private: + template <typename Iterator> value_type* find_impl(Iterator begin, Iterator end) { @@ -213,13 +214,14 @@ namespace boost { namespace spirit { namespace x3 } public: + template <typename Iterator, typename Context, typename Attribute> bool parse(Iterator& first, Iterator const& last , Context const& context, unused_type, Attribute& attr) const { x3::skip_over(first, last, context); - if (value_type* val_ptr + if (value_type const* val_ptr = lookup->find(first, last, get_case_compare<Encoding>(context))) { x3::traits::move_to(*val_ptr, attr); diff --git a/boost/spirit/home/x3/support/ast/variant.hpp b/boost/spirit/home/x3/support/ast/variant.hpp index 52e565d1d4..052e6e5f8a 100644 --- a/boost/spirit/home/x3/support/ast/variant.hpp +++ b/boost/spirit/home/x3/support/ast/variant.hpp @@ -214,6 +214,11 @@ namespace boost { namespace spirit { namespace x3 return var; } + void swap(variant& rhs) BOOST_NOEXCEPT + { + var.swap(rhs.var); + } + variant_type var; }; }}} 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; } }; diff --git a/boost/spirit/home/x3/support/traits/move_to.hpp b/boost/spirit/home/x3/support/traits/move_to.hpp index fd3d59d7e2..2e3665bd0b 100644 --- a/boost/spirit/home/x3/support/traits/move_to.hpp +++ b/boost/spirit/home/x3/support/traits/move_to.hpp @@ -23,7 +23,19 @@ namespace boost { namespace spirit { namespace x3 { namespace traits { template <typename Source, typename Dest> - void move_to(Source&& src, Dest& dest); + inline void move_to(Source&& src, Dest& dest); + + template <typename T> + inline void move_to(T& src, T& dest); + + template <typename T> + inline void move_to(T const& src, T& dest); + + template <typename T> + inline void move_to(T&& src, T& dest); + + template <typename Iterator, typename Dest> + inline void move_to(Iterator first, Iterator last, Dest& dest); template <typename Dest> inline void move_to(unused_type, Dest&) {} @@ -33,10 +45,6 @@ namespace boost { namespace spirit { namespace x3 { namespace traits inline void move_to(unused_type, unused_type) {} - template <typename Iterator, typename Dest> - void - move_to(Iterator first, Iterator last, Dest& dest); - template <typename Iterator> inline void move_to(Iterator, Iterator, unused_type) {} @@ -70,7 +78,7 @@ namespace boost { namespace spirit { namespace x3 { namespace traits is_size_one_sequence<Source> > is_single_element_sequence; - move_to_plain(std::move(src), dest, is_single_element_sequence); + move_to_plain(std::forward<Source>(src), dest, is_single_element_sequence); } template <typename Source, typename Dest> @@ -88,7 +96,7 @@ namespace boost { namespace spirit { namespace x3 { namespace traits >::type move_to(Source&& src, Dest& dest, tuple_attribute) { - fusion::move(std::move(src), dest); + fusion::move(std::forward<Source>(src), dest); } template <typename Source, typename Dest> @@ -97,7 +105,7 @@ namespace boost { namespace spirit { namespace x3 { namespace traits >::type move_to(Source&& src, Dest& dest, tuple_attribute) { - traits::move_to(src, fusion::front(dest)); + traits::move_to(std::forward<Source>(src), fusion::front(dest)); } template <typename Source, typename Dest> @@ -167,8 +175,7 @@ namespace boost { namespace spirit { namespace x3 { namespace traits } template <typename Source, typename Dest> - inline void - move_to(Source&& src, Dest& dest) + inline void move_to(Source&& src, Dest& dest) { detail::move_to(std::move(src), dest , typename attribute_category<Dest>::type()); @@ -191,13 +198,12 @@ namespace boost { namespace spirit { namespace x3 { namespace traits template <typename T> inline void move_to(T&& src, T& dest) { - if (&src != &dest) + if (boost::addressof(src) != boost::addressof(dest)) dest = std::move(src); } template <typename Iterator, typename Dest> - inline void - move_to(Iterator first, Iterator last, Dest& dest) + inline void move_to(Iterator first, Iterator last, Dest& dest) { // $$$ Use std::move_iterator when iterator is not a const-iterator $$$ detail::move_to(first, last, dest, typename attribute_category<Dest>::type()); |