pstade

PrevUpHomeNext

Forwarding Strategies

by_perfect
by_ref
by_cref
by_value
Deducing nullary return types

A Forwarding Strategy is a type which has two associated imaginary operators _arg_list and _meta_arg_list which takes a token sequence and a strategy. If the first argument of arg_list or _meta_arg_list is not a sequence, assume it is "one element" sequence. Egg components use by_perfect when you omit or specify _default for strategy parameter.

This section uses the following notation.

Valid expression

Semantics

_arg(a)

_typeof(a) const if a is a rvalue; boost::remove_reference<_decltype(a)>::type otherwise.

_ref(a)

static_cast<_arg(a) &>(a)

_cref(a)

static_cast<_arg(a) const &>(a)

_val(a)

const_cast<V &>(static_cast<V const &>(boost::implicit_cast<V>(a)))

, where V is boost::remove_cv<boost::decay<_typeof(a)>::type>::type.

[Note] Note

_val(a) copies a and turns it into mutable lvalue in order to work around The Forwarding Problem. You shouldn't take reference in Little Function call with by_value strategy, unless writing generic one.

Description

Egg performs the "perfect forwarding" by default.

Header
  • <pstade/egg/by_perfect.hpp>
Valid expressions

Valid expression

Semantics

_arg_list(a, by_perfect)

_arg(a1),...,_arg(aK)

_meta_arg_list(a, by_perfect)

_ref(a1),...,_ref(aK)

function<B, by_perfect>

See function.

Preconditions
  • 0 <= K && K <= PSTADE_EGG_MAX_ARITY.
  • aI is not a function reference.
Example
  • _meta_arg_list(a, by_perfect) is int,const int,int const if a is i,3,ci, where i is non-const lvalue and ci is a const lvalue.
See also
Description

by_ref offers a large arity, but can't take a non-const rvalue.

Header
  • <pstade/egg/by_ref.hpp>
Valid expressions

Valid expression

Semantics

_arg_list(a, by_ref)

_arg(a1),...,_arg(aK)

_meta_arg_list(a, by_ref)

_ref(a1),...,_ref(aK)

function<B, by_ref>

See function.

Preconditions
  • 0 <= K && K <= PSTADE_EGG_MAX_LINEAR_ARITY.
  • aI is not a rvalue.
Example
  • _meta_arg_list(a, by_ref) is int,const int,int const if a is i,ci,ci, where i is non-const lvalue and ci is a const lvalue.
See also
Description

by_cref takes the arguments by const reference.

Header
  • <pstade/egg/by_cref.hpp>
Valid expressions

Valid expression

Semantics

_arg_list(a, by_cref)

_cref(a1),...,_cref(aK)

_meta_arg_list(a, by_cref)

_typeof(a1) const,...,_typeof(aK) const

function<B, by_cref>

See function.

Preconditions
  • 0 <= K && K <= PSTADE_EGG_MAX_LINEAR_ARITY.
Example
  • _meta_arg_list(a, by_cref) is int const,const int,int const if a is i,ci,ci, where i is non-const lvalue and ci is a const lvalue.
See also
Description

by_value takes the arguments by value, which means that it can take a temporary "movable type" like std::auto_ptr<>.

Header
  • <pstade/egg/by_value.hpp>
Valid expressions

Valid expression

Semantics

_arg_list(a, by_value)

_val(a1),...,_val(aK)

_meta_arg_list(a, by_value)

_typeof(a1),...,_typeof(aK)

function<B, by_value>

See function.

Preconditions
  • 0 <= K && K <= PSTADE_EGG_MAX_LINEAR_ARITY.
Example
  • _meta_arg_list(a, by_value) is int,int,int if a is i,3,ci, where i is non-const lvalue and ci is a const lvalue.
See also
Description

C++ instantiates the declarations of non-dependent member function templates, so that some Function Builders and Function Adaptors require a special workaround. Here an imaginary operator is defined for the documentation.

Valid expressions and semantics
  • _deduce_r0(R0, expr) is defined by the following:
    • If R0 is _default, it is a valid expression and returns an unspecified type .
    • If R0 is use_nullary_result,
      • If _decltype(_epxr) is a valid expression, it is a valid expression and returns _decltype(expr).
      • Otherwise, it is not a valid expression.
    • Otherwise, R0.
See also
Copyright 2007 Shunsuke Sogame

PrevUpHomeNext