Boost logo

Boost Users :

Subject: [Boost-users] [proto] non-proto objects as terminals
From: Igor R (boost.lists_at_[hidden])
Date: 2016-05-30 15:00:47

I would like to use instances of a non-proto class as proto terminals
for all purposes. To enable this functionality, I use is_terminal
metafunction that I pass to BOOST_PROTO_DEFINE_OPERATORS().
This actually defines the operators, so the following expression makes
an expression tree, as expected:
non_proto_obj * proto_obj;

However, I cannot do this:
non_proto_obj = proto_obj;
Or this:

While the opposite does compile:
proto_obj = non_proto_obj;

How to solve this issue?


P.S.: here is an sscce:


#include <iostream>
#include <boost/proto/proto.hpp>
#include <boost/mpl/int.hpp>

namespace mpl = boost::mpl;
namespace proto = boost::proto;
using proto::_;

template<typename Expr>
struct my_expression;

struct my_domain : proto::domain<proto::generator<my_expression> >

template<int I> struct placeholder {};

template<typename Expr>
struct my_expression : proto::extends<Expr, my_expression<Expr>, my_domain>
    explicit my_expression(Expr const &expr = Expr()) :


const my_expression<proto::terminal<placeholder<1>>::type> _1;

namespace app
  struct non_proto_type

  template <typename T>
  struct is_terminal : mpl::false_
  struct is_terminal<non_proto_type> : mpl::true_
  BOOST_PROTO_DEFINE_OPERATORS(is_terminal, my_domain)

  non_proto_type non_proto;

int main()
    _1 = app::non_proto; // ok, builds temporary proto expression
    //app::non_proto = _1; // does not compile! no operator=
    _1[app::non_proto]; // ok
    //app::non_proto[_1]; // does not compile! no operator[]
    (+app::non_proto)[_1]; // ok! applying unary + to make a proto
expression first, then operator[] is available

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at