Skip to content

Commit

Permalink
use inheriting constructors, since clang's support is pretty good now
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Niebler committed Apr 17, 2013
1 parent 5169d2d commit 62b9ade
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 135 deletions.
100 changes: 5 additions & 95 deletions boost/proto/v5/expr.hpp
Expand Up @@ -177,95 +177,6 @@ namespace boost
};
}

////////////////////////////////////////////////////////////////////////////////////////
// constructors
// This will no longer be needed once clang implements inheriting constructors
#define BOOST_PROTO_INHERIT_EXPR_CTORS(EXPR, BASE) \
using typename BASE::proto_tag_type; \
using typename BASE::proto_children_type; \
\
constexpr EXPR(proto_tag_type tag, proto_children_type args) \
noexcept(noexcept( \
BASE(static_cast<proto_tag_type &&>(tag), static_cast<proto_children_type &&>(args)) \
)) \
: BASE(static_cast<proto_tag_type &&>(tag), static_cast<proto_children_type &&>(args))\
{} \
\
constexpr explicit EXPR(proto_children_type args) \
noexcept(noexcept( \
EXPR(proto_tag_type(), static_cast<proto_children_type &&>(args)) \
)) \
: EXPR(proto_tag_type(), static_cast<proto_children_type &&>(args)) \
{} \
\
template<typename proto_A_ \
, BOOST_PROTO_ENABLE_IF( \
proto_children_type::proto_size::value == 1 && \
!(boost::proto::v5::utility::is_base_of<EXPR, proto_A_>::value) \
) \
> \
constexpr EXPR(proto_tag_type tag, proto_A_ &&a) \
noexcept(noexcept( \
BASE(static_cast<proto_tag_type &&>(tag), static_cast<proto_A_ &&>(a)) \
)) \
: BASE(static_cast<proto_tag_type &&>(tag), static_cast<proto_A_ &&>(a)) \
{} \
\
template<typename proto_A_ \
, BOOST_PROTO_ENABLE_IF( \
proto_children_type::proto_size::value == 1 && \
!(boost::proto::v5::utility::is_base_of<EXPR, proto_A_>::value) \
) \
> \
explicit constexpr EXPR(proto_A_ &&a) \
noexcept(noexcept( \
EXPR(proto_tag_type(), static_cast<proto_A_ &&>(a)) \
)) \
: EXPR(proto_tag_type(), static_cast<proto_A_ &&>(a)) \
{} \
\
template<typename proto_A_, typename proto_B_, typename ...proto_C_ \
, BOOST_PROTO_ENABLE_IF(proto_children_type::proto_size::value == sizeof...(proto_C_) + 2) \
> \
constexpr EXPR(proto_tag_type tag, proto_A_ &&a, proto_B_ &&b, proto_C_ &&... c) \
noexcept(noexcept( \
BASE( \
static_cast<proto_tag_type &&>(tag) \
, static_cast<proto_A_ &&>(a) \
, static_cast<proto_B_ &&>(b) \
, static_cast<proto_C_ &&>(c)... \
) \
)) \
: BASE( \
static_cast<proto_tag_type &&>(tag) \
, static_cast<proto_A_ &&>(a) \
, static_cast<proto_B_ &&>(b) \
, static_cast<proto_C_ &&>(c)... \
) \
{} \
\
template<typename proto_A_, typename proto_B_, typename ...proto_C_ \
, BOOST_PROTO_ENABLE_IF(proto_children_type::proto_size::value == sizeof...(proto_C_) + 2)> \
constexpr EXPR(proto_A_ &&a, proto_B_ &&b, proto_C_ &&... c) \
noexcept(noexcept( \
EXPR( \
proto_tag_type() \
, static_cast<proto_A_ &&>(a) \
, static_cast<proto_B_ &&>(b) \
, static_cast<proto_C_ &&>(c)... \
) \
)) \
: EXPR( \
proto_tag_type() \
, static_cast<proto_A_ &&>(a) \
, static_cast<proto_B_ &&>(b) \
, static_cast<proto_C_ &&>(c)... \
) \
{} \
\
using boost_proto_inherited_ctors ## __LINE__ = int \
/**/

namespace exprs
{
////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -497,9 +408,10 @@ namespace boost
)
>
explicit constexpr basic_expr(A &&a)
noexcept(noexcept(
basic_expr(Tag(), static_cast<A &&>(a))
))
// http://llvm.org/bugs/show_bug.cgi?id=15757
// noexcept(noexcept(
// basic_expr(Tag(), static_cast<A &&>(a))
// ))
: basic_expr(Tag(), static_cast<A &&>(a))
{}

Expand Down Expand Up @@ -594,9 +506,7 @@ namespace boost

////////////////////////////////////////////////////////////////////////////////
// constructors
//using basic_expr<ExprDesc, Domain>::basic_expr;
using proto_base_expr_type = basic_expr<ExprDesc, Domain>;
BOOST_PROTO_INHERIT_EXPR_CTORS(expr, proto_base_expr_type);
using basic_expr<ExprDesc, Domain>::basic_expr;

////////////////////////////////////////////////////////////////////////////////
// operator=
Expand Down
5 changes: 1 addition & 4 deletions libs/proto/v5/example/lambda.cpp
Expand Up @@ -72,11 +72,8 @@ struct lambda_expr
, proto::expr_subscript<lambda_expr<ExprDesc>>
{
BOOST_PROTO_REGULAR_TRIVIAL_CLASS(lambda_expr);

using proto::expr_assign<lambda_expr>::operator=;
//using proto::basic_expr<ExprDesc, lambda_domain>::basic_expr;
using proto_basic_expr_type = proto::basic_expr<ExprDesc, lambda_domain>;
BOOST_PROTO_INHERIT_EXPR_CTORS(lambda_expr, proto_basic_expr_type);
using proto::basic_expr<ExprDesc, lambda_domain>::basic_expr;

template<typename ...T>
auto operator()(T &&... t) const
Expand Down
4 changes: 1 addition & 3 deletions libs/proto/v5/example/virtual_member.cpp
Expand Up @@ -162,10 +162,8 @@ namespace mini_lambda
)

public:
using proto_basic_expr_type = proto::basic_expr<ExprDesc, domain>;
BOOST_PROTO_REGULAR_TRIVIAL_CLASS(expression);
//using proto::basic_expr<ExprDesc, domain>::basic_expr;
BOOST_PROTO_INHERIT_EXPR_CTORS(expression, proto_basic_expr_type);
using proto::basic_expr<ExprDesc, domain>::basic_expr;
using proto::expr_assign<expression>::operator=;

// Use BOOST_PROTO_EXTENDS_MEMBERS() to define "virtual"
Expand Down
8 changes: 2 additions & 6 deletions libs/proto/v5/scratch/main.cpp
Expand Up @@ -78,13 +78,9 @@ struct lambda_expr
, proto::expr_subscript<lambda_expr<ExprDesc>>
{
BOOST_PROTO_REGULAR_TRIVIAL_CLASS(lambda_expr);

using proto::basic_expr<ExprDesc, lambda_domain>::basic_expr;
using proto::expr_assign<lambda_expr>::operator=;

using proto_basic_expr_type = proto::basic_expr<ExprDesc, lambda_domain>;
BOOST_PROTO_INHERIT_EXPR_CTORS(lambda_expr, proto_basic_expr_type);
//using proto::basic_expr<ExprDesc, lambda_domain>::basic_expr;

template<typename ...T>
auto operator()(T &&... t) const
BOOST_PROTO_AUTO_RETURN(
Expand Down Expand Up @@ -130,7 +126,7 @@ int main()
std::cout << "expr:\n"
<< proto::pretty_expr(_1 + 42 * _2, 4)
<< std::endl;

// Create a lambda
auto fun = proto::deep_copy(_1 + 42 * _2);

Expand Down
5 changes: 2 additions & 3 deletions libs/proto/v5/test/bug2407.cpp
Expand Up @@ -34,11 +34,10 @@ template<class E>
struct e
: proto::basic_expr<E, d>
{
using proto_basic_expr_type = proto::basic_expr<E, d>;
static_assert(proto::matches<proto_basic_expr_type, g>::value, "");
static_assert(proto::matches<proto::basic_expr<E, d>, g>::value, "");

BOOST_PROTO_REGULAR_TRIVIAL_CLASS(e);
BOOST_PROTO_INHERIT_EXPR_CTORS(e, proto_basic_expr_type);
using proto::basic_expr<E, d>::basic_expr;
};

e<proto::terminal(int)> i;
Expand Down
9 changes: 3 additions & 6 deletions libs/proto/v5/test/constrained_ops.cpp
Expand Up @@ -76,8 +76,7 @@ struct extension
: proto::basic_expr<ExprDesc, my_domain>
{
BOOST_PROTO_REGULAR_TRIVIAL_CLASS(extension);
using proto_basic_expr_type = proto::basic_expr<ExprDesc, my_domain>;
BOOST_PROTO_INHERIT_EXPR_CTORS(extension, proto_basic_expr_type);
using proto::basic_expr<ExprDesc, my_domain>::basic_expr;

void test() const
{}
Expand All @@ -88,17 +87,15 @@ struct lhs_extension
: proto::basic_expr<ExprDesc, my_lhs_domain>
{
BOOST_PROTO_REGULAR_TRIVIAL_CLASS(lhs_extension);
using proto_basic_expr_type = proto::basic_expr<ExprDesc, my_lhs_domain>;
BOOST_PROTO_INHERIT_EXPR_CTORS(lhs_extension, proto_basic_expr_type);
using proto::basic_expr<ExprDesc, my_lhs_domain>::basic_expr;
};

template<class ExprDesc>
struct rhs_extension
: proto::basic_expr<ExprDesc, my_rhs_domain>
{
BOOST_PROTO_REGULAR_TRIVIAL_CLASS(rhs_extension);
using proto_basic_expr_type = proto::basic_expr<ExprDesc, my_rhs_domain>;
BOOST_PROTO_INHERIT_EXPR_CTORS(rhs_extension, proto_basic_expr_type);
using proto::basic_expr<ExprDesc, my_rhs_domain>::basic_expr;
};

void test_constrained_ops()
Expand Down
3 changes: 1 addition & 2 deletions libs/proto/v5/test/deep_copy.cpp
Expand Up @@ -86,9 +86,8 @@ template<typename ExprDesc>
struct Expr
: proto::basic_expr<ExprDesc, Domain>
{
using proto_basic_expr_type = proto::basic_expr<ExprDesc, Domain>;
BOOST_PROTO_REGULAR_TRIVIAL_CLASS(Expr);
BOOST_PROTO_INHERIT_EXPR_CTORS(Expr, proto_basic_expr_type);
using proto::basic_expr<ExprDesc, Domain>::basic_expr;
};

void test_custom_expr()
Expand Down
6 changes: 1 addition & 5 deletions libs/proto/v5/test/expr.cpp
Expand Up @@ -39,11 +39,7 @@ struct MyExpr
, proto::expr_function<MyExpr<ExprDesc>>
{
BOOST_PROTO_REGULAR_TRIVIAL_CLASS(MyExpr);

//using proto::basic_expr<ExprDesc, MyDomain>::basic_expr;
using proto_basic_expr_type = proto::basic_expr<ExprDesc, MyDomain>;
BOOST_PROTO_INHERIT_EXPR_CTORS(MyExpr, proto_basic_expr_type);

using proto::basic_expr<ExprDesc, MyDomain>::basic_expr;
using proto::expr_assign<MyExpr>::operator=;
};

Expand Down
3 changes: 1 addition & 2 deletions libs/proto/v5/test/flatten.cpp
Expand Up @@ -132,9 +132,8 @@ struct My
: proto::basic_expr<ExprDesc, MyDomain>
, proto::expr_function<My<ExprDesc>>
{
using proto_basic_expr_type = proto::basic_expr<ExprDesc, MyDomain>;
BOOST_PROTO_INHERIT_EXPR_CTORS(My, proto_basic_expr_type);
BOOST_PROTO_REGULAR_TRIVIAL_CLASS(My);
using proto::basic_expr<ExprDesc, MyDomain>::basic_expr;
};

using my = proto::custom<My>;
Expand Down
6 changes: 2 additions & 4 deletions libs/proto/v5/test/make_expr.cpp
Expand Up @@ -29,8 +29,7 @@ struct ewrap
: proto::expr<E, mydomain>
{
BOOST_PROTO_REGULAR_TRIVIAL_CLASS(ewrap);
using proto_basic_expr_type = proto::expr<E, mydomain>;
BOOST_PROTO_INHERIT_EXPR_CTORS(ewrap, proto_basic_expr_type);
using proto::expr<E, mydomain>::expr;
};

void test_make_expr()
Expand Down Expand Up @@ -313,8 +312,7 @@ struct by_ref_expr
, proto::expr_function<by_ref_expr<ExprDesc>>
{
BOOST_PROTO_REGULAR_TRIVIAL_CLASS(by_ref_expr);
using proto_basic_expr_type = proto::basic_expr<ExprDesc, by_ref_domain>;
BOOST_PROTO_INHERIT_EXPR_CTORS(by_ref_expr, proto_basic_expr_type);
using proto::basic_expr<ExprDesc, by_ref_domain>::basic_expr;
};

struct length_impl {};
Expand Down
3 changes: 1 addition & 2 deletions libs/proto/v5/test/mpl.cpp
Expand Up @@ -30,9 +30,8 @@ struct my_expr
: proto::expr<E, my_domain>
{
using tag = fusion::fusion_sequence_tag;
using proto_basic_expr_type = proto::expr<E, my_domain>;
BOOST_PROTO_REGULAR_TRIVIAL_CLASS(my_expr);
BOOST_PROTO_INHERIT_EXPR_CTORS(my_expr, proto_basic_expr_type);
using proto::expr<E, my_domain>::expr;
};

// Test that we can call mpl algorithms on proto expression types, and get proto expression types back
Expand Down
4 changes: 1 addition & 3 deletions libs/proto/v5/test/virtual_member.cpp
Expand Up @@ -31,9 +31,7 @@ struct MyExpr
: proto::basic_expr<ExprDesc, MyDomain>
{
BOOST_PROTO_REGULAR_TRIVIAL_CLASS(MyExpr);

using proto_basic_expr_type = proto::basic_expr<ExprDesc, MyDomain>;
BOOST_PROTO_INHERIT_EXPR_CTORS(MyExpr, proto_basic_expr_type);
using proto::basic_expr<ExprDesc, MyDomain>::basic_expr;

BOOST_PROTO_EXTENDS_MEMBERS(
MyExpr, MyDomain,
Expand Down

0 comments on commit 62b9ade

Please sign in to comment.