|
Boost-Commit : |
From: eric_at_[hidden]
Date: 2008-04-27 20:54:24
Author: eric_niebler
Date: 2008-04-27 20:54:23 EDT (Sun, 27 Apr 2008)
New Revision: 44830
URL: http://svn.boost.org/trac/boost/changeset/44830
Log:
add back a new and improved implicit_expr()
Text files modified:
branches/proto/v4/boost/proto/extends.hpp | 11 +++-
branches/proto/v4/boost/proto/generate.hpp | 6 ++
branches/proto/v4/boost/proto/make_expr.hpp | 87 +++++++++++++++++++++++++++++++++++++++
branches/proto/v4/boost/proto/proto_fwd.hpp | 3
branches/proto/v4/boost/proto/traits.hpp | 20 +++-----
5 files changed, 108 insertions(+), 19 deletions(-)
Modified: branches/proto/v4/boost/proto/extends.hpp
==============================================================================
--- branches/proto/v4/boost/proto/extends.hpp (original)
+++ branches/proto/v4/boost/proto/extends.hpp 2008-04-27 20:54:23 EDT (Sun, 27 Apr 2008)
@@ -104,7 +104,7 @@
BOOST_PP_CAT(proto_child_ref, N); \
/**/
- #define BOOST_PROTO_BASIC_EXTENDS(Expr, Derived, Domain) \
+ #define BOOST_PROTO_BASIC_EXTENDS_(Expr, Derived, Domain) \
Expr proto_expr_; \
\
typedef typename Expr::proto_base_expr proto_base_expr; \
@@ -134,6 +134,11 @@
} \
/**/
+ #define BOOST_PROTO_BASIC_EXTENDS(Expr, Derived, Domain) \
+ BOOST_PROTO_BASIC_EXTENDS_(Expr, Derived, Domain) \
+ typedef void proto_is_aggregate_; \
+ /**/
+
/// INTERNAL ONLY
///
#define BOOST_PROTO_EXTENDS_ASSIGN_IMPL_(Const) \
@@ -385,7 +390,7 @@
: proto_expr_(expr_)
{}
- BOOST_PROTO_BASIC_EXTENDS(Expr, Derived, Domain)
+ BOOST_PROTO_BASIC_EXTENDS_(Expr, Derived, Domain)
BOOST_PROTO_EXTENDS_ASSIGN_CONST()
BOOST_PROTO_EXTENDS_SUBSCRIPT_CONST()
@@ -423,7 +428,7 @@
: proto_expr_(expr_)
{}
- BOOST_PROTO_BASIC_EXTENDS(Expr, Derived, Domain)
+ BOOST_PROTO_BASIC_EXTENDS_(Expr, Derived, Domain)
BOOST_PROTO_EXTENDS_ASSIGN()
BOOST_PROTO_EXTENDS_SUBSCRIPT()
Modified: branches/proto/v4/boost/proto/generate.hpp
==============================================================================
--- branches/proto/v4/boost/proto/generate.hpp (original)
+++ branches/proto/v4/boost/proto/generate.hpp 2008-04-27 20:54:23 EDT (Sun, 27 Apr 2008)
@@ -55,7 +55,11 @@
struct by_value_generator_;
#define BOOST_PROTO_DEFINE_BY_VALUE_TYPE(Z, N, Expr) \
- typename expr_traits<Expr>::args::BOOST_PP_CAT(child_ref, N)::proto_derived_expr \
+ typename remove_const< \
+ typename remove_reference< \
+ typename expr_traits<Expr>::args::BOOST_PP_CAT(child, N) \
+ >::type \
+ >::type \
/**/
#define BOOST_PROTO_DEFINE_BY_VALUE(Z, N, expr) \
Modified: branches/proto/v4/boost/proto/make_expr.hpp
==============================================================================
--- branches/proto/v4/boost/proto/make_expr.hpp (original)
+++ branches/proto/v4/boost/proto/make_expr.hpp 2008-04-27 20:54:23 EDT (Sun, 27 Apr 2008)
@@ -496,6 +496,24 @@
: make_expr_<tag::terminal, default_domain, A>
{};
+ template<typename A0>
+ struct implicit_expr_1;
+
+ template<typename T>
+ typename disable_if_c<is_expr<T>::value, implicit_expr_1<T> >::type
+ implicit_arg_1(T &t)
+ {
+ implicit_expr_1<T> that = {t};
+ return that;
+ }
+
+ template<typename T>
+ typename disable_if_c<!is_expr<T>::value, T &>::type
+ implicit_arg_1(T &t)
+ {
+ return t;
+ }
+
#define BOOST_PP_ITERATION_PARAMS_1 \
(4, (1, BOOST_PROTO_MAX_ARITY, <boost/proto/make_expr.hpp>, 1)) \
/**/
@@ -944,6 +962,24 @@
>::call(sequence2);
}
+ /// \brief Return a proxy object that holds its arguments by reference
+ /// and is implicitly convertible to an expression.
+ template<typename A0>
+ detail::implicit_expr_1<A0> const
+ implicit_expr(A0 &a0)
+ {
+ detail::implicit_expr_1<A0> that = {a0};
+ return that;
+ }
+
+ // Additional overloads generated by the preprocessor...
+
+ #define BOOST_PP_ITERATION_PARAMS_1 \
+ (4, (2, BOOST_PROTO_MAX_ARITY, <boost/proto/make_expr.hpp>, 4)) \
+ /**/
+
+ #include BOOST_PP_ITERATE()
+
/// INTERNAL ONLY
///
template<typename Tag, typename Domain>
@@ -997,11 +1033,41 @@
BOOST_PP_REPEAT(N, M0, ~)
#undef M0
+ template<typename Args>
+ operator proto::expr<tag::terminal, Args, 0>() const
+ {
+ proto::expr<tag::terminal, Args, 0> that = {a0};
+ return that;
+ };
+
+ template<typename Tag, typename Args, long Arity>
+ operator proto::expr<Tag, Args, Arity>() const
+ {
+ #define M0(Z, N, DATA) detail::implicit_arg_1(this->BOOST_PP_CAT(a, N))
+ proto::expr<Tag, Args, Arity> that = {BOOST_PP_ENUM(N, M0, ~)};
+ #undef M0
+ return that;
+ };
+
template<typename Expr>
operator Expr() const
{
- typename Expr::proto_base_expr that = {BOOST_PP_ENUM_PARAMS(N, a)};
- return typename Expr::proto_domain()(that);
+ typename Expr::proto_base_expr that = *this;
+ return this->wrap(that, is_aggregate<Expr>(), static_cast<Expr *>(0));
+ }
+
+ private:
+ template<typename Base, typename Expr>
+ static Expr wrap(Base const &expr, mpl::false_, Expr *)
+ {
+ return Expr(expr);
+ }
+
+ template<typename Base, typename Expr>
+ static Expr wrap(Base const &expr, mpl::true_, Expr *)
+ {
+ Expr that = {expr};
+ return that;
}
};
@@ -1202,4 +1268,21 @@
#undef N
+#elif BOOST_PP_ITERATION_FLAGS() == 4
+
+ #define N BOOST_PP_ITERATION()
+
+ /// \overload
+ ///
+ template<BOOST_PP_ENUM_PARAMS(N, typename A)>
+ detail::BOOST_PP_CAT(implicit_expr_, N)<BOOST_PP_ENUM_PARAMS(N, A)> const
+ implicit_expr(BOOST_PP_ENUM_BINARY_PARAMS(N, A, &a))
+ {
+ detail::BOOST_PP_CAT(implicit_expr_, N)<BOOST_PP_ENUM_PARAMS(N, A)> that
+ = {BOOST_PP_ENUM_PARAMS(N, a)};
+ return that;
+ }
+
+ #undef N
+
#endif // BOOST_PP_IS_ITERATING
Modified: branches/proto/v4/boost/proto/proto_fwd.hpp
==============================================================================
--- branches/proto/v4/boost/proto/proto_fwd.hpp (original)
+++ branches/proto/v4/boost/proto/proto_fwd.hpp 2008-04-27 20:54:23 EDT (Sun, 27 Apr 2008)
@@ -689,7 +689,7 @@
template<typename T>
struct is_callable;
- template<typename T>
+ template<typename T, typename Void = void>
struct is_aggregate;
template<typename T, typename Void = void>
@@ -698,6 +698,7 @@
#define BOOST_PROTO_UNEXPR() typedef int proto_is_expr_;
#define BOOST_PROTO_CALLABLE() typedef void proto_is_callable_;
#define BOOST_PROTO_TRANSFORM() typedef void proto_is_transform_;
+ #define BOOST_PROTO_AGGREGATE() typedef void proto_is_aggregate_;
struct callable
{
Modified: branches/proto/v4/boost/proto/traits.hpp
==============================================================================
--- branches/proto/v4/boost/proto/traits.hpp (original)
+++ branches/proto/v4/boost/proto/traits.hpp 2008-04-27 20:54:23 EDT (Sun, 27 Apr 2008)
@@ -136,7 +136,7 @@
/// If <tt>is_aggregate\<T\>::::value</tt> is \c true, then an object of
/// type T will be initialized as <tt>T t = {a0,a1,...aN};</tt>. Otherwise,
/// it will be initialized as <tt>T t(a0,a1,...aN)</tt>.
- template<typename T>
+ template<typename T, typename Void>
struct is_aggregate
: is_pod<T>
{};
@@ -144,7 +144,13 @@
/// \brief Specialization of <tt>is_aggregate\<\></tt> that indicates
/// that objects of <tt>expr\<\></tt> type require aggregate initialization.
template<typename Tag, typename Args, long N>
- struct is_aggregate<proto::expr<Tag, Args, N> >
+ struct is_aggregate<proto::expr<Tag, Args, N>, void>
+ : mpl::true_
+ {};
+
+ /// INTERNAL ONLY
+ template<typename T>
+ struct is_aggregate<T, typename T::proto_is_aggregate_>
: mpl::true_
{};
@@ -2246,16 +2252,6 @@
{};
}
- ///// INTERNAL ONLY
- //template<BOOST_PP_ENUM_PARAMS(N, typename A)>
- //detail::BOOST_PP_CAT(implicit_expr_, N)<BOOST_PP_ENUM_PARAMS(N, A)>
- //implicit_expr(BOOST_PP_ENUM_BINARY_PARAMS(N, A, &a))
- //{
- // detail::BOOST_PP_CAT(implicit_expr_, N)<BOOST_PP_ENUM_PARAMS(N, A)> that
- // = {BOOST_PP_ENUM_PARAMS(N, a)};
- // return that;
- //}
-
#endif
namespace result_of
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk