| Home | Libraries | People | FAQ | More

## Struct template extends

boost::proto::extends — For adding behaviors to a Proto expression template.

## Synopsis

    // In header: <boost/proto/extends.hpp>

    template<typename Expr, typename Derived,
             typename Domain = proto::default_domain>
    struct extends {
      // types
      typedef typename Expr::proto_base_expr          proto_base_expr;
      typedef Domain                                  proto_domain;
      typedef Derived                                 proto_derived_expr;
      typedef typename proto_base_expr::proto_tag     proto_tag;
      typedef typename proto_base_expr::proto_args    proto_args;
      typedef typename proto_base_expr::proto_arity   proto_arity;
      typedef typename proto_base_expr::proto_grammar proto_grammar;
      typedef typename proto_base_expr::proto_childN  proto_childN;        // For each N in [0,max(1,proto_arity_c))

      // member classes/structs/unions
      template<typename Signature>
      struct result {
        // types
        typedef unspecified type;
      };

      // construct/copy/destruct
      extends();
      extends(extends const &);
      extends(Expr const &);

      // public static functions
      static Derived const make(Expr const &);

      // public member functions
      proto_base_expr & proto_base();
      proto_base_expr const & proto_base() const;
      template<typename A> unspecified operator=(A &);
      template<typename A> unspecified operator=(A const &);
      template<typename A> unspecified operator=(A &) const;
      template<typename A> unspecified operator=(A const &) const;
      template<typename A> unspecified operator[](A &);
      template<typename A> unspecified operator[](A const &);
      template<typename A> unspecified operator[](A &) const;
      template<typename A> unspecified operator[](A const &) const;
      template<typename... A> unspecified operator()(A const &...);
      template<typename... A> unspecified operator()(A const &...) const;

      // public data members
      Expr proto_expr_;  // For exposition only.
      static const long proto_arity_c;  // = proto_base_expr::proto_arity_c;
    };

## Description

Use `proto::extends<>` to give expressions in your domain custom data members and member functions.

Conceptually, using `proto::extends<>` is akin to inheriting from `proto::expr<>` and adding your own members. Using `proto::extends<>` is generally preferrable to straight inheritance because the members that would be inherited from `proto::expr<>` would be wrong; they would incorrectly slice off your additional members when building larger expressions from smaller ones. `proto::extends<>` automatically gives your expression types the appropriate operator overloads that preserve your domain-specific members when composing expression trees.

Expression extensions are typically defined as follows:

    template< typename Expr >
    struct my_expr
      : proto::extends<
            Expr            // The expression type we're extending
          , my_expr< Expr > // The type we're defining
          , my_domain       // The domain associated with this expression extension
        >
    {
        typedef proto::extends< Expr, my_expr< Expr >, my_domain > base_type;

        // An expression extension is constructed from the expression
        // it is extending.
        my_expr( Expr const & e = Expr() )
          : base_type( e )
        {}

        // Unhide proto::extends::operator=
        // (This is only necessary if a lazy assignment operator
        // makes sense for your domain-specific language.)
        BOOST_PROTO_EXTENDS_USING_ASSIGN(my_expr)

        /*
        ... domain-specific members go here ...
        */
    };

See also:

- `BOOST_PROTO_EXTENDS()`
- `BOOST_PROTO_EXTENDS_USING_ASSIGN()`
- `BOOST_PROTO_EXTENDS_USING_ASSIGN_NON_DEPENDENT()`

### `extends` public construct/copy/destruct

1.     extends();

2.     extends(extends const & that);

3.     extends(Expr const & expr_);

### `extends` public static functions

1.     static Derived const make(Expr const & expr);

   Construct an expression extension from the base expression.

### `extends` public member functions

1.     proto_base_expr & proto_base();

   Returns: | `proto_expr_.proto_base()`
   Throws: | Will not throw.

2.     proto_base_expr const & proto_base() const;

   Returns: | `proto_expr_.proto_base()`
   Throws: | Will not throw.

3.     template<typename A> unspecified operator=(A & a);

   Lazy assignment expression

   Returns: | A new expression node representing the assignment operation.

4.     template<typename A> unspecified operator=(A const & a);

   This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

5.     template<typename A> unspecified operator=(A & a) const;

   This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

6.     template<typename A> unspecified operator=(A const & a) const;

   This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

7.     template<typename A> unspecified operator[](A & a);

   Lazy subscript expression

   Returns: | A new expression node representing the subscript operation.

8.     template<typename A> unspecified operator[](A const & a);

   This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

9.     template<typename A> unspecified operator[](A & a) const;

   This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

10.     template<typename A> unspecified operator[](A const & a) const;

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

11.     template<typename... A> unspecified operator()(A const &... a);

    Lazy function call

    Returns: | A new expression node representing the function call operation.

12.     template<typename... A> unspecified operator()(A const &... a) const;

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.