From 3a968fa5ac41be9a62281cd655d61847787a7eaf Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Thu, 31 May 2012 22:28:58 +0900 Subject: [PATCH] add Sprout.Weed ->* Attribute-conversion --- sprout/array.hpp | 2 + sprout/cmath.hpp | 7 +- sprout/math/functions.hpp | 1 + sprout/pit.hpp | 2 + sprout/string.hpp | 1 + sprout/sub_array.hpp | 2 + sprout/tuple.hpp | 5 +- sprout/tuple/array.hpp | 15 ++-- sprout/tuple/fused.hpp | 67 +++++++++++++++ sprout/tuple/pit.hpp | 23 +++--- sprout/tuple/sscrisk/cel/array.hpp | 13 +-- sprout/tuple/sscrisk/cel/utility.hpp | 31 +++---- sprout/tuple/string.hpp | 14 ++-- sprout/tuple/sub_array.hpp | 23 +++--- sprout/tuple/tuple.hpp | 35 +++----- sprout/tuple/uuid.hpp | 14 ++-- sprout/type_traits/aliases.hpp | 1 - sprout/utility/pair.hpp | 21 ++--- sprout/uuid/uuid.hpp | 2 + sprout/weed/attr_cnv.hpp | 1 + sprout/weed/attr_cnv/bitwise_or.hpp | 2 +- sprout/weed/attr_cnv/mem_ptr.hpp | 22 +++++ sprout/weed/attr_cnv/result_of.hpp | 1 + sprout/weed/attr_cnv/result_of/mem_ptr.hpp | 23 ++++++ .../weed/context/parse_context/operator.hpp | 1 + .../parse_context/operator/mem_ptr.hpp | 81 +++++++++++++++++++ .../context/parse_context/terminal/parser.hpp | 4 + sprout/weed/expr/expr.hpp | 3 + sprout/weed/expr/expr_fwd.hpp | 16 ++++ sprout/weed/expr/tag.hpp | 1 + sprout/weed/operator.hpp | 1 + sprout/weed/operator/mem_ptr.hpp | 40 +++++++++ sprout/weed/traits/expr/expr_of.hpp | 2 +- sprout/weed/traits/expr/is_expr.hpp | 2 +- sprout/weed/traits/expr/terminal_of.hpp | 2 +- 35 files changed, 369 insertions(+), 112 deletions(-) create mode 100644 sprout/tuple/fused.hpp create mode 100644 sprout/weed/attr_cnv/mem_ptr.hpp create mode 100644 sprout/weed/attr_cnv/result_of/mem_ptr.hpp create mode 100644 sprout/weed/context/parse_context/operator/mem_ptr.hpp create mode 100644 sprout/weed/expr/expr_fwd.hpp create mode 100644 sprout/weed/operator/mem_ptr.hpp diff --git a/sprout/array.hpp b/sprout/array.hpp index cfff2b9c..d82403fb 100644 --- a/sprout/array.hpp +++ b/sprout/array.hpp @@ -308,4 +308,6 @@ namespace std { }; } // namespace std +#include + #endif // #ifndef SPROUT_ARRAY_HPP diff --git a/sprout/cmath.hpp b/sprout/cmath.hpp index 446929f0..61fbcbc4 100644 --- a/sprout/cmath.hpp +++ b/sprout/cmath.hpp @@ -2,6 +2,11 @@ #define SPROUT_CMATH_HPP #include -#include +#include +#include +#include +#include +#include +#include #endif // #ifndef SPROUT_CMATH_HPP diff --git a/sprout/math/functions.hpp b/sprout/math/functions.hpp index 5d2ef3c2..1b6bb004 100644 --- a/sprout/math/functions.hpp +++ b/sprout/math/functions.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include diff --git a/sprout/pit.hpp b/sprout/pit.hpp index 8a80edb1..e9841b80 100644 --- a/sprout/pit.hpp +++ b/sprout/pit.hpp @@ -245,4 +245,6 @@ namespace std { {}; } // namespace std +#include + #endif // #ifndef SPROUT_PIT_HPP diff --git a/sprout/string.hpp b/sprout/string.hpp index 37c60bae..201dea2e 100644 --- a/sprout/string.hpp +++ b/sprout/string.hpp @@ -15,5 +15,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_STRING_HPP diff --git a/sprout/sub_array.hpp b/sprout/sub_array.hpp index 56bf2e35..be629a7a 100644 --- a/sprout/sub_array.hpp +++ b/sprout/sub_array.hpp @@ -867,4 +867,6 @@ namespace std { {}; } // namespace std +#include + #endif // #ifndef SPROUT_SUB_ARRAY_HPP diff --git a/sprout/tuple.hpp b/sprout/tuple.hpp index 8b675190..8500c3ef 100644 --- a/sprout/tuple.hpp +++ b/sprout/tuple.hpp @@ -4,7 +4,8 @@ #include #include #include -#include -#include +#include +#include +#include #endif // #ifndef SPROUT_TUPLE_HPP diff --git a/sprout/tuple/array.hpp b/sprout/tuple/array.hpp index f191386d..62b31bcf 100644 --- a/sprout/tuple/array.hpp +++ b/sprout/tuple/array.hpp @@ -2,10 +2,8 @@ #define SPROUT_TUPLE_ARRAY_HPP #include -#include #include #include -#include #include namespace sprout { @@ -14,22 +12,25 @@ namespace sprout { // get // template - T& get(sprout::array& t) SPROUT_NOEXCEPT { + inline SPROUT_CONSTEXPR T& + get(sprout::array& t) SPROUT_NOEXCEPT { static_assert(I < N, "get: index out of range"); return t[I]; } template - SPROUT_CONSTEXPR T const& get(sprout::array const& t) SPROUT_NOEXCEPT { + inline SPROUT_CONSTEXPR T const& + get(sprout::array const& t) SPROUT_NOEXCEPT { static_assert(I < N, "get: index out of range"); return t[I]; } template - T&& get(sprout::array&& t) SPROUT_NOEXCEPT { - return std::move(sprout::tuples::get(t)); + inline SPROUT_CONSTEXPR T&& + get(sprout::array&& t) SPROUT_NOEXCEPT { + return sprout::move(sprout::tuples::get(t)); } } // namespace tuples using sprout::tuples::get; } // namespace sprout -#endif // #ifndef SPROUT_TUPLE_TUPLE_COMPARISON_HPP +#endif // #ifndef SPROUT_TUPLE_ARRAY_HPP diff --git a/sprout/tuple/fused.hpp b/sprout/tuple/fused.hpp new file mode 100644 index 00000000..054de1ea --- /dev/null +++ b/sprout/tuple/fused.hpp @@ -0,0 +1,67 @@ +#ifndef SPROUT_TUPLE_FUSED_HPP +#define SPROUT_TUPLE_FUSED_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace tuples { + // + // fused + // + template + class fused { + public: + typedef F functor_type; + private: + functor_type f_; + private: + template + SPROUT_CONSTEXPR auto + call(Tuple&& t, sprout::index_tuple) const + -> decltype(f_(sprout::tuples::get(sprout::forward(t))...)) + { + return f_(sprout::tuples::get(sprout::forward(t))...); + } + public: + fused() = default; + fused(fused const&) = default; + explicit SPROUT_CONSTEXPR fused(F f) + : f_(f) + {} + SPROUT_CONSTEXPR functor_type functor() const { + return f_; + } + template + SPROUT_CONSTEXPR auto + operator()(Tuple&& t) const + -> decltype(this->call( + sprout::forward(t), + sprout::index_range<0, sprout::tuples::tuple_size::type>::value>::make() + )) + { + return call( + sprout::forward(t), + sprout::index_range<0, sprout::tuples::tuple_size::type>::value>::make() + ); + } + }; + + // + // make_fused + // + template + inline SPROUT_CONSTEXPR sprout::tuples::fused + make_fused(F const& f) { + return sprout::tuples::fused(f); + } + } // namespace tuples + + using sprout::tuples::fused; + using sprout::tuples::make_fused; +} // namespace sprout + +#endif // #ifndef SPROUT_TUPLE_FUSED_HPP diff --git a/sprout/tuple/pit.hpp b/sprout/tuple/pit.hpp index 43c44ea2..12f84e50 100644 --- a/sprout/tuple/pit.hpp +++ b/sprout/tuple/pit.hpp @@ -2,10 +2,9 @@ #define SPROUT_TUPLE_PIT_HPP #include -#include #include #include -#include +#include #include namespace sprout { @@ -14,27 +13,23 @@ namespace sprout { // get // template - typename sprout::container_traits >::value_type& get( - sprout::pit& t - ) SPROUT_NOEXCEPT - { + inline SPROUT_CONSTEXPR typename sprout::container_traits >::value_type& + get(sprout::pit& t) SPROUT_NOEXCEPT { static_assert(I < sprout::container_traits >::static_size, "get: index out of range"); return t[I]; } template - SPROUT_CONSTEXPR typename sprout::container_traits >::value_type const& get( - sprout::pit const& t - ) SPROUT_NOEXCEPT - { + inline SPROUT_CONSTEXPR typename sprout::container_traits >::value_type const& + get(sprout::pit const& t) SPROUT_NOEXCEPT { static_assert(I < sprout::container_traits >::static_size, "get: index out of range"); return t[I]; } template - typename sprout::container_traits >::value_type&& get( - sprout::pit&& t - ) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::move(sprout::tuples::get(t)))) + inline SPROUT_CONSTEXPR typename sprout::container_traits >::value_type&& + get(sprout::pit&& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::move(sprout::tuples::get(t)))) { - return std::move(sprout::tuples::get(t)); + return sprout::move(sprout::tuples::get(t)); } } // namespace tuples diff --git a/sprout/tuple/sscrisk/cel/array.hpp b/sprout/tuple/sscrisk/cel/array.hpp index 018eec1b..f74229e2 100644 --- a/sprout/tuple/sscrisk/cel/array.hpp +++ b/sprout/tuple/sscrisk/cel/array.hpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include namespace sprout { @@ -13,18 +13,21 @@ namespace sprout { // get // template - T& get(sscrisk::cel::array& t) SPROUT_NOEXCEPT { + inline SPROUT_CONSTEXPR T& + get(sscrisk::cel::array& t) SPROUT_NOEXCEPT { static_assert(I < N, "get: index out of range"); return t[I]; } template - SPROUT_CONSTEXPR T const& get(sscrisk::cel::array const& t) SPROUT_NOEXCEPT { + inline SPROUT_CONSTEXPR T const& + get(sscrisk::cel::array const& t) SPROUT_NOEXCEPT { static_assert(I < N, "get: index out of range"); return t[I]; } template - T&& get(sscrisk::cel::array&& t) SPROUT_NOEXCEPT { - return std::move(sprout::tuples::get(t)); + inline SPROUT_CONSTEXPR T&& + get(sscrisk::cel::array&& t) SPROUT_NOEXCEPT { + return sprout::move(sprout::tuples::get(t)); } } // namespace tuples diff --git a/sprout/tuple/sscrisk/cel/utility.hpp b/sprout/tuple/sscrisk/cel/utility.hpp index d02cd0fe..3947ab4f 100644 --- a/sprout/tuple/sscrisk/cel/utility.hpp +++ b/sprout/tuple/sscrisk/cel/utility.hpp @@ -3,9 +3,10 @@ #include #include +#include #include #include -#include +#include namespace sprout { namespace tuples { @@ -48,10 +49,10 @@ namespace sprout { template struct get_impl<0, sscrisk::cel::pair > { public: - T1& operator()(sscrisk::cel::pair& t) const { + SPROUT_CONSTEXPR T1& operator()(sscrisk::cel::pair& t) const { return t.first; } - T1 const& operator()(sscrisk::cel::pair const& t) const { + SPROUT_CONSTEXPR T1 const& operator()(sscrisk::cel::pair const& t) const { return t.first; } }; @@ -59,36 +60,30 @@ namespace sprout { struct get_impl<1, sscrisk::cel::pair > { public: public: - T2& operator()(sscrisk::cel::pair& t) const { + SPROUT_CONSTEXPR T2& operator()(sscrisk::cel::pair& t) const { return t.second; } - T2 const& operator()(sscrisk::cel::pair const& t) const { + SPROUT_CONSTEXPR T2 const& operator()(sscrisk::cel::pair const& t) const { return t.second; } }; } // namespace detail template - typename sprout::tuples::tuple_element >::type& get( - sscrisk::cel::pair& t - ) SPROUT_NOEXCEPT - { + inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type& + get(sscrisk::cel::pair& t) SPROUT_NOEXCEPT { static_assert(I < 2, "get: index out of range"); return sprout::tuples::detail::get_impl >()(t); } template - SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type const& get( - sscrisk::cel::pair const& t - ) SPROUT_NOEXCEPT - { + inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type const& + get(sscrisk::cel::pair const& t) SPROUT_NOEXCEPT { static_assert(I < 2, "get: index out of range"); return sprout::tuples::detail::get_impl >()(t); } template - typename sprout::tuples::tuple_element >::type&& get( - sscrisk::cel::pair&& t - ) SPROUT_NOEXCEPT - { - return std::move(sprout::tuples::get(t)); + inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type&& + get(sscrisk::cel::pair&& t) SPROUT_NOEXCEPT { + return sprout::move(sprout::tuples::get(t)); } } // namespace tuples diff --git a/sprout/tuple/string.hpp b/sprout/tuple/string.hpp index a10ab9ee..f5af5891 100644 --- a/sprout/tuple/string.hpp +++ b/sprout/tuple/string.hpp @@ -2,10 +2,9 @@ #define SPROUT_TUPLE_STRING_HPP #include -#include #include #include -#include +#include #include namespace sprout { @@ -14,18 +13,21 @@ namespace sprout { // get // template - T& get(sprout::basic_string& t) SPROUT_NOEXCEPT { + inline SPROUT_CONSTEXPR T& + get(sprout::basic_string& t) SPROUT_NOEXCEPT { static_assert(I < N, "get: index out of range"); return t[I]; } template - SPROUT_CONSTEXPR T const& get(sprout::basic_string const& t) SPROUT_NOEXCEPT { + inline SPROUT_CONSTEXPR T const& + get(sprout::basic_string const& t) SPROUT_NOEXCEPT { static_assert(I < N, "get: index out of range"); return t[I]; } template - T&& get(sprout::basic_string&& t) SPROUT_NOEXCEPT { - return std::move(sprout::tuples::get(t)); + inline SPROUT_CONSTEXPR T&& + get(sprout::basic_string&& t) SPROUT_NOEXCEPT { + return sprout::move(sprout::tuples::get(t)); } } // namespace tuples diff --git a/sprout/tuple/sub_array.hpp b/sprout/tuple/sub_array.hpp index abd89496..e6ddf407 100644 --- a/sprout/tuple/sub_array.hpp +++ b/sprout/tuple/sub_array.hpp @@ -2,12 +2,11 @@ #define SPROUT_TUPLE_SUB_ARRAY_HPP #include -#include #include #include #include #include -#include +#include #include namespace sprout { @@ -16,27 +15,27 @@ namespace sprout { // get // template - typename sprout::container_traits >::value_type& get( - sprout::sub_array& t - ) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(*sprout::next(sprout::internal_begin(t), I))) + inline SPROUT_CONSTEXPR typename sprout::container_traits >::value_type& + get(sprout::sub_array& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(*sprout::next(sprout::internal_begin(t), I))) { static_assert(I < sprout::container_traits >::static_size, "get: index out of range"); return *sprout::next(sprout::internal_begin(t), I); } template - SPROUT_CONSTEXPR typename sprout::container_traits >::value_type const& get( - sprout::sub_array const& t - ) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(*sprout::next(sprout::internal_begin(t), I))) + inline SPROUT_CONSTEXPR typename sprout::container_traits >::value_type const& + get(sprout::sub_array const& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(*sprout::next(sprout::internal_begin(t), I))) { static_assert(I < sprout::container_traits >::static_size, "get: index out of range"); return *sprout::next(sprout::internal_begin(t), I); } template - typename sprout::container_traits >::value_type&& get( - sprout::sub_array&& t - ) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::move(sprout::tuples::get(t)))) + inline SPROUT_CONSTEXPR typename sprout::container_traits >::value_type&& + get(sprout::sub_array&& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::move(sprout::tuples::get(t)))) { - return std::move(sprout::tuples::get(t)); + return sprout::move(sprout::tuples::get(t)); } } // namespace tuples diff --git a/sprout/tuple/tuple.hpp b/sprout/tuple/tuple.hpp index 06a953b9..fbbd6200 100644 --- a/sprout/tuple/tuple.hpp +++ b/sprout/tuple/tuple.hpp @@ -501,9 +501,8 @@ namespace sprout { // get // template - SPROUT_CONSTEXPR auto get( - T&& t - ) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::get(sprout::forward(t)))) + SPROUT_CONSTEXPR auto + get(T&& t) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::get(sprout::forward(t)))) -> decltype(std::get(sprout::forward(t))) { return std::get(sprout::forward(t)); @@ -513,41 +512,31 @@ namespace sprout { // namespace detail { template - SPROUT_CONSTEXPR typename std::add_lvalue_reference::type get_helper( - sprout::tuples::detail::tuple_impl& t - ) SPROUT_NOEXCEPT - { + SPROUT_CONSTEXPR typename std::add_lvalue_reference::type + get_helper(sprout::tuples::detail::tuple_impl& t) SPROUT_NOEXCEPT { return sprout::tuples::detail::tuple_impl::head(t); } template - SPROUT_CONSTEXPR typename std::add_lvalue_reference::type>::type get_helper( - sprout::tuples::detail::tuple_impl const& t - ) SPROUT_NOEXCEPT - { + SPROUT_CONSTEXPR typename std::add_lvalue_reference::type>::type + get_helper(sprout::tuples::detail::tuple_impl const& t) SPROUT_NOEXCEPT { return sprout::tuples::detail::tuple_impl::head(t); } } // namespace detail template - SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type& get( - sprout::tuples::tuple& t - ) SPROUT_NOEXCEPT - { + SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type& + get(sprout::tuples::tuple& t) SPROUT_NOEXCEPT { return sprout::tuples::detail::get_helper(t); } template - SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type&& get( - sprout::tuples::tuple&& t - ) SPROUT_NOEXCEPT - { + SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type&& + get(sprout::tuples::tuple&& t) SPROUT_NOEXCEPT { return sprout::forward >::type&&>( sprout::tuples::get(t) ); } template - SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type const& get( - sprout::tuples::tuple const& t - ) SPROUT_NOEXCEPT - { + SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type const& + get(sprout::tuples::tuple const& t) SPROUT_NOEXCEPT { return sprout::tuples::detail::get_helper(t); } } // namespace tuples diff --git a/sprout/tuple/uuid.hpp b/sprout/tuple/uuid.hpp index 75c709cc..c12b59e5 100644 --- a/sprout/tuple/uuid.hpp +++ b/sprout/tuple/uuid.hpp @@ -2,10 +2,9 @@ #define SPROUT_TUPLE_UUID_HPP #include -#include #include #include -#include +#include #include namespace sprout { @@ -14,18 +13,21 @@ namespace sprout { // get // template - sprout::uuids::uuid::value_type& get(sprout::uuids::uuid& t) SPROUT_NOEXCEPT { + inline SPROUT_CONSTEXPR sprout::uuids::uuid::value_type& + get(sprout::uuids::uuid& t) SPROUT_NOEXCEPT { static_assert(I < 16, "get: index out of range"); return t[I]; } template - SPROUT_CONSTEXPR sprout::uuids::uuid::value_type const& get(sprout::uuids::uuid const& t) SPROUT_NOEXCEPT { + inline SPROUT_CONSTEXPR sprout::uuids::uuid::value_type const& + get(sprout::uuids::uuid const& t) SPROUT_NOEXCEPT { static_assert(I < 16, "get: index out of range"); return t[I]; } template - sprout::uuids::uuid::value_type&& get(sprout::uuids::uuid&& t) SPROUT_NOEXCEPT { - return std::move(sprout::tuples::get(t)); + inline SPROUT_CONSTEXPR sprout::uuids::uuid::value_type&& + get(sprout::uuids::uuid&& t) SPROUT_NOEXCEPT { + return sprout::move(sprout::tuples::get(t)); } } // namespace tuples diff --git a/sprout/type_traits/aliases.hpp b/sprout/type_traits/aliases.hpp index 8ec299a7..98b87769 100644 --- a/sprout/type_traits/aliases.hpp +++ b/sprout/type_traits/aliases.hpp @@ -2,7 +2,6 @@ #define SPROUT_TYPE_TRAITS_ALIASES_HPP #include - #if SPROUT_USE_TEMPLATE_ALIASES # include # include diff --git a/sprout/utility/pair.hpp b/sprout/utility/pair.hpp index 2e1ccbf4..6c0eb7d3 100644 --- a/sprout/utility/pair.hpp +++ b/sprout/utility/pair.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -233,27 +234,21 @@ namespace sprout { }; } // namespace detail template - typename sprout::tuples::tuple_element >::type& get( - sprout::pair& t - ) SPROUT_NOEXCEPT - { + inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type& + get(sprout::pair& t) SPROUT_NOEXCEPT { static_assert(I < 2, "get: index out of range"); return sprout::tuples::detail::get_impl >()(t); } template - SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type const& get( - sprout::pair const& t - ) SPROUT_NOEXCEPT - { + inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type const& + get(sprout::pair const& t) SPROUT_NOEXCEPT { static_assert(I < 2, "get: index out of range"); return sprout::tuples::detail::get_impl >()(t); } template - typename sprout::tuples::tuple_element >::type&& get( - sprout::pair&& t - ) SPROUT_NOEXCEPT - { - return std::move(sprout::tuples::get(t)); + inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type&& + get(sprout::pair&& t) SPROUT_NOEXCEPT { + return sprout::move(sprout::tuples::get(t)); } } // namespace tuples diff --git a/sprout/uuid/uuid.hpp b/sprout/uuid/uuid.hpp index ed1e7c28..781d420d 100644 --- a/sprout/uuid/uuid.hpp +++ b/sprout/uuid/uuid.hpp @@ -281,4 +281,6 @@ namespace std { }; } // namespace std +#include + #endif // #ifndef SPROUT_UUID_UUID_HPP diff --git a/sprout/weed/attr_cnv.hpp b/sprout/weed/attr_cnv.hpp index 9fd2222a..46bc316c 100644 --- a/sprout/weed/attr_cnv.hpp +++ b/sprout/weed/attr_cnv.hpp @@ -7,5 +7,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_WEED_ATTR_CNV_HPP diff --git a/sprout/weed/attr_cnv/bitwise_or.hpp b/sprout/weed/attr_cnv/bitwise_or.hpp index dc37286c..6959fb0c 100644 --- a/sprout/weed/attr_cnv/bitwise_or.hpp +++ b/sprout/weed/attr_cnv/bitwise_or.hpp @@ -135,7 +135,7 @@ namespace sprout { typedef typename sprout::weed::attr_cnv::result_of::bitwise_or::type type; return sprout::make(); } - // unused >> unused -> unused + // unused | unused -> unused template inline SPROUT_CONSTEXPR typename std::enable_if< sprout::weed::detail::is_both_unused::value, diff --git a/sprout/weed/attr_cnv/mem_ptr.hpp b/sprout/weed/attr_cnv/mem_ptr.hpp new file mode 100644 index 00000000..45caba2f --- /dev/null +++ b/sprout/weed/attr_cnv/mem_ptr.hpp @@ -0,0 +1,22 @@ +#ifndef SPROUT_WEED_ATTR_CNV_MEM_PTR_HPP +#define SPROUT_WEED_ATTR_CNV_MEM_PTR_HPP + +#include +#include + +namespace sprout { + namespace weed { + namespace attr_cnv { + // + // mem_ptr + // + template + inline SPROUT_CONSTEXPR typename sprout::weed::attr_cnv::result_of::mem_ptr::type + mem_ptr(T const& t, U const& u) { + return u(t); + } + } // namespace attr_cnv + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_ATTR_CNV_MEM_PTR_HPP diff --git a/sprout/weed/attr_cnv/result_of.hpp b/sprout/weed/attr_cnv/result_of.hpp index 953b3559..61eff56e 100644 --- a/sprout/weed/attr_cnv/result_of.hpp +++ b/sprout/weed/attr_cnv/result_of.hpp @@ -7,5 +7,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_WEED_ATTR_CNV_RESULT_OF_HPP diff --git a/sprout/weed/attr_cnv/result_of/mem_ptr.hpp b/sprout/weed/attr_cnv/result_of/mem_ptr.hpp new file mode 100644 index 00000000..8fb4049b --- /dev/null +++ b/sprout/weed/attr_cnv/result_of/mem_ptr.hpp @@ -0,0 +1,23 @@ +#ifndef SPROUT_WEED_ATTR_CNV_RESULT_OF_MEM_PTR_HPP +#define SPROUT_WEED_ATTR_CNV_RESULT_OF_MEM_PTR_HPP + +#include +#include + +namespace sprout { + namespace weed { + namespace attr_cnv { + namespace result_of { + // + // mem_ptr + // + template + struct mem_ptr + : public std::result_of + {}; + } // namespace result_of + } // namespace attr_cnv + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_ATTR_CNV_RESULT_OF_MEM_PTR_HPP diff --git a/sprout/weed/context/parse_context/operator.hpp b/sprout/weed/context/parse_context/operator.hpp index 97e53ae9..ffb92436 100644 --- a/sprout/weed/context/parse_context/operator.hpp +++ b/sprout/weed/context/parse_context/operator.hpp @@ -11,5 +11,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_OPERATOR_HPP diff --git a/sprout/weed/context/parse_context/operator/mem_ptr.hpp b/sprout/weed/context/parse_context/operator/mem_ptr.hpp new file mode 100644 index 00000000..40709241 --- /dev/null +++ b/sprout/weed/context/parse_context/operator/mem_ptr.hpp @@ -0,0 +1,81 @@ +#ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_OPERATOR_MEM_PTR_HPP +#define SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_OPERATOR_MEM_PTR_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + // + // parse_context::eval + // + template + template + struct parse_context::eval< + Expr, + typename std::enable_if< + std::is_same< + typename sprout::weed::traits::tag_of::type, + sprout::weed::tag::mem_ptr + >::value + >::type + > { + private: + typedef sprout::weed::parse_context context_type; + typedef typename sprout::tuples::tuple_element<0, typename Expr::args_type>::type expr1_type; + typedef typename sprout::tuples::tuple_element<1, typename Expr::args_type>::type expr2_type; + public: + typedef typename sprout::weed::attr_cnv::result_of::mem_ptr< + typename sprout::weed::traits::attribute_of::type, + typename sprout::tuples::tuple_element<0, typename expr2_type::args_type>::type + >::type attribute_type; + typedef sprout::weed::eval_result result_type; + private: + template + SPROUT_CONSTEXPR result_type call_1( + typename Expr::args_type const& args, + context_type const& ctx, + Result1 const& res + ) const + { + return res.success() + ? result_type( + true, + res.current(), + sprout::weed::attr_cnv::mem_ptr( + res.attr(), sprout::tuples::get<0>(sprout::tuples::get<1>(args).args()) + ), + context_type(ctx, res.current()) + ) + : result_type(false, ctx.begin(), attribute_type(), ctx) + ; + } + SPROUT_CONSTEXPR result_type call( + typename Expr::args_type const& args, + context_type const& ctx + ) const + { + return call_1(args, ctx, sprout::weed::eval(sprout::tuples::get<0>(args), ctx)); + } + public: + SPROUT_CONSTEXPR result_type operator()( + Expr const& expr, + context_type const& ctx + ) const + { + return call(expr.args(), ctx); + } + }; + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_OPERATOR_MEM_PTR_HPP diff --git a/sprout/weed/context/parse_context/terminal/parser.hpp b/sprout/weed/context/parse_context/terminal/parser.hpp index e1afc741..837756e3 100644 --- a/sprout/weed/context/parse_context/terminal/parser.hpp +++ b/sprout/weed/context/parse_context/terminal/parser.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -26,6 +27,9 @@ namespace sprout { typename sprout::weed::traits::tag_of::type, sprout::weed::tag::terminal >::value + && sprout::weed::traits::is_parser< + typename sprout::tuples::tuple_element<0, typename Expr::args_type>::type + >::value && !sprout::weed::traits::is_char_type< typename sprout::tuples::tuple_element<0, typename Expr::args_type>::type >::value diff --git a/sprout/weed/expr/expr.hpp b/sprout/weed/expr/expr.hpp index 2584038c..c0c4af0a 100644 --- a/sprout/weed/expr/expr.hpp +++ b/sprout/weed/expr/expr.hpp @@ -4,6 +4,9 @@ #include #include #include +#include +#include +#include namespace sprout { namespace weed { diff --git a/sprout/weed/expr/expr_fwd.hpp b/sprout/weed/expr/expr_fwd.hpp new file mode 100644 index 00000000..431a2247 --- /dev/null +++ b/sprout/weed/expr/expr_fwd.hpp @@ -0,0 +1,16 @@ +#ifndef SPROUT_WEED_EXPR_EXPR_FWD_HPP +#define SPROUT_WEED_EXPR_EXPR_FWD_HPP + +#include + +namespace sprout { + namespace weed { + // + // expr + // + template + class expr; + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_EXPR_EXPR_FWD_HPP diff --git a/sprout/weed/expr/tag.hpp b/sprout/weed/expr/tag.hpp index 384388c5..c0b8146a 100644 --- a/sprout/weed/expr/tag.hpp +++ b/sprout/weed/expr/tag.hpp @@ -16,6 +16,7 @@ namespace sprout { struct modulus {}; struct minus {}; struct bitwise_or {}; + struct mem_ptr {}; } // namespace tag } // namespace weed } // namespace sprout diff --git a/sprout/weed/operator.hpp b/sprout/weed/operator.hpp index ba4e1473..291411c7 100644 --- a/sprout/weed/operator.hpp +++ b/sprout/weed/operator.hpp @@ -11,5 +11,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_WEED_OPERATOR_HPP diff --git a/sprout/weed/operator/mem_ptr.hpp b/sprout/weed/operator/mem_ptr.hpp new file mode 100644 index 00000000..6849b9f5 --- /dev/null +++ b/sprout/weed/operator/mem_ptr.hpp @@ -0,0 +1,40 @@ +#ifndef SPROUT_WEED_OPERATOR_MEM_PTR_HPP +#define SPROUT_WEED_OPERATOR_MEM_PTR_HPP + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + // + // operator->* + // + template< + typename Arg1, + typename Arg2, + typename = typename std::enable_if< + sprout::weed::traits::is_parser< + typename sprout::weed::detail::uncvref::type + >::value + >::type + > + inline SPROUT_CONSTEXPR typename sprout::weed::traits::expr_of< + sprout::weed::tag::mem_ptr, + Arg1, + Arg2 + >::type operator->*(Arg1&& arg1, Arg2&& arg2) { + return sprout::weed::make_expr( + sprout::forward(arg1), + sprout::forward(arg2) + ); + } + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_OPERATOR_MEM_PTR_HPP diff --git a/sprout/weed/traits/expr/expr_of.hpp b/sprout/weed/traits/expr/expr_of.hpp index a35b05c5..1dca9e05 100644 --- a/sprout/weed/traits/expr/expr_of.hpp +++ b/sprout/weed/traits/expr/expr_of.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include diff --git a/sprout/weed/traits/expr/is_expr.hpp b/sprout/weed/traits/expr/is_expr.hpp index a1c92bfb..6d1dc55c 100644 --- a/sprout/weed/traits/expr/is_expr.hpp +++ b/sprout/weed/traits/expr/is_expr.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include namespace sprout { namespace weed { diff --git a/sprout/weed/traits/expr/terminal_of.hpp b/sprout/weed/traits/expr/terminal_of.hpp index 9682eeef..bd9584a2 100644 --- a/sprout/weed/traits/expr/terminal_of.hpp +++ b/sprout/weed/traits/expr/terminal_of.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include #include