Hi,

I have been trying to extend a domain by "subdomaining" it. The sole purpose 
of this subdomain was to allow another type of terminal expression.
Please see the attached code, which is a very simplified version of what I 
was trying to do.

Ok, so let me try to explain what happens with a small table showing what 
works, and what not (fixed size font helps here).

   expression | compiles? | matches grammar1? | matches grammar2?|
 -------------+-----------+-------------------+------------------+
1. t1         | yes       | yes               | no               |
2. t1 + t1    | yes       | yes               | no               |
3. t2         | yes       | no                | yes              |
4. t2 + t2    | no        | no                | no               |
5. t1 + t2    | no        | no                | no               |

So, 1.-3. are working as expected. 4. and 5. obviously doesn't work 
(operator+ gets SFINAE'd out because of these rules: 
https://svn.boost.org/trac/boost/ticket/4668

So far so good ... Or not.

Let me remind you that I want to get 4. and 5. compiled, matching grammar2, 
but not grammar1.

One attempt would be to change grammar1 to:
struct grammar1
    : proto::or_<
        proto::plus<proto::_, proto::_>
      , int_terminal
    >
{};

Which enables the operator+ for 4. however, the expressio 4. starts to match 
both grammars. Not really what I.
Expression 5. still fails, and i could not get it to work.

So, How to handle that correctly?
Let me remind you, that adding double_terminal to grammar1 not an option.

Regards,

Thomas
#include <boost/proto/proto.hpp>

namespace proto = boost::proto;

typedef proto::terminal<int> int_terminal;
typedef proto::terminal<double> double_terminal;

template <typename Expr>
struct actor1;

struct grammar1;

struct domain1
    : proto::domain<
        proto::pod_generator<actor1>
      , grammar1
      , proto::default_domain
    >
{};

struct grammar1
    : proto::or_<
        proto::plus<grammar1, grammar1>
      , int_terminal
    >
{};

template <typename Expr>
struct actor1
{
    BOOST_PROTO_BASIC_EXTENDS(Expr, actor1<Expr>, domain1)
};

template <typename Expr>
struct actor2;

struct grammar2;

struct domain2
    : proto::domain<
        proto::pod_generator<actor2>
      , grammar2
      , domain1
    >
{};

struct grammar2
    : proto::or_<
        grammar1
      , double_terminal
    >
{};

template <typename Expr>
struct actor2
{
    BOOST_PROTO_BASIC_EXTENDS(Expr, actor2<Expr>, domain2)
};

actor1<int_terminal::type> t1 = {{0}};
actor2<double_terminal::type> t2 = {{0}};
_______________________________________________
proto mailing list
proto@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/proto

Reply via email to