| Home | Libraries | People | FAQ | More

## Class template overloaded_function

boost::overloaded_function — Function object to overload functions with distinct signatures.

## Synopsis

    // In header: <boost/functional/overloaded_function.hpp>

    template<typename F1, typename F2, ...>
    class overloaded_function {
    public:

      // public member functions
      overloaded_function(const boost::function< F1 > &,
                          const boost::function< F2 > &, ...);
      boost::function_traits< F1 >::result_type
      operator()(typename boost::function_traits< F1 >::arg1_type,
                 typename boost::function_traits< F1 >::arg2_type, ...) const;
      boost::function_traits< F2 >::result_type
      operator()(typename boost::function_traits< F2 >::arg1_type,
                 typename boost::function_traits< F2 >::arg2_type, ...) const;
    };

## Description

This function object aggregates together calls to functions of all the specified function types `F1`, `F2`, etc which must have distinct function signatures from one another.

Parameters:

`Fi` | Each function type must be specified using the following syntax (which is Boost.Function's preferred syntax):
    result_type (argument1_type, argumgnet2_type, ...)

In some cases, the `make_overloaded_function` function template can be useful to construct an overloaded function object without explicitly specifying the function types.

At least two distinct function types must be specified (because there is nothing to overload between one or zero functions). The maximum number of functions to overload is given by the `BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX` configuration macro. The maximum number of function parameters for each of the specified function types is given by the `BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX` configuration macro.

See: Tutorial section, `make_overloaded_function`, `BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX`, `BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX`, Boost.Function.

### `overloaded_function` public member functions

1.     overloaded_function(const boost::function< F1 > &,
                           const boost::function< F2 > &, ...);

   Construct the overloaded function object.

   Any function pointer, function reference, and monomorphic function object that can be converted to a `boost::function` function object can be specified as parameter.

   Note: Unfortunately, it is not possible to support polymorphic function objects (as explained here).

2.     boost::function_traits< F1 >::result_type
       operator()(typename boost::function_traits< F1 >::arg1_type,
                  typename boost::function_traits< F1 >::arg2_type, ...) const;

   Call operator matching the signature of the function type specified as 1st template parameter.

   This will in turn invoke the call operator of the 1st function passed to the constructor.

3.     boost::function_traits< F2 >::result_type
       operator()(typename boost::function_traits< F2 >::arg1_type,
                  typename boost::function_traits< F2 >::arg2_type, ...) const;

   Call operator matching the signature of the function type specified as 2nd template parameter.

   This will in turn invoke the call operator of the 2nd function passed to the constructor.

   Note: Similar call operators are present for all specified function types `F1`, `F2`, etc (even if not exhaustively listed by this documentation).