Hi,
I am trying to create a DSEL with Boost.Proto, which (among other
things) should allow expressions like
i == j + 3 && t != "foo"
and want to prevent disallowed operators to be generated by Proto.
Please consider the code below.
// -----------------------------------------------------------------------
#include
using namespace boost;
typedef proto::terminal<int>::type terminal;
struct addition:
proto::or_
<
terminal,
proto::plus
>
{};
struct equation:
proto::equal_to
{};
struct condition:
proto::or_
<
equation,
proto::logical_and
>
{};
template<class Expr>
struct extension;
struct my_domain:
proto::domain
<
proto::pod_generator< extension>,
condition
>
{};
template<class Expr>
struct extension
{
BOOST_PROTO_EXTENDS(
Expr
, extension<Expr>
, my_domain
)
};
int main()
{
terminal c;
BOOST_PROTO_ASSERT_MATCHES(c + c, addition); // OK
BOOST_PROTO_ASSERT_MATCHES(c == c, equation); // OK
BOOST_PROTO_ASSERT_MATCHES(c == c, condition); // OK
BOOST_PROTO_ASSERT_MATCHES(c == c&& c == c, condition); // OK
extension<terminal> i;
// I was hoping for the following to be legal
i + i; // ERROR: operator+ not found
i == i; // ERROR: operator== not found
i == i&& i == i; // ERROR: operator== not found
}
// -----------------------------------------------------------------------
In my_domain, I can replace condition by addition, which allows i + i,
but then the == operator is still missing (and the &&, too, probably).
How can I solve this?
Thanks and regards,
Roland