Boost logo

Boost Users :

Subject: Re: [Boost-users] [Boost.Functional.OverloadedFunction][C++03] Number of overloads in boost::overload_function<...>
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2012-10-17 01:49:41


On Tue, Oct 16, 2012 at 5:40 PM, Felipe Magno de Almeida
<felipe.m.almeida_at_[hidden]> wrote:
> Is there a way to know how many overloads are there in a
> overloaded_function

I'm not sure I understand your question... for example, in the code below:

boost::overloaded_function<
      const std::string& (const std::string&)
    , int (int)
    , double (double)
> identity(identity_s, identity_i, identity_d);

You want a way to query the type of identity at compile-time to get 3
and/or the identity object at run-time to get 3? If so, why? Don't you
know already know that such a number is 3 given that you are
constructing the overloaded_function type passing 3 function
signatures and/or constructing the identity object passing 3
functors... what's your actual use case for this feature?

> without resorting to preprocessor metaprogramming

The pp will only tell you the max number of possible overloads
BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX but not the
actual number of overloads that an overloaded_function type/object has
at compile/run time. For example, in the code above
BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX is always 5
(unless you #define it differently) even if the number of identity
overloads is 3.

> in C++03? It doesn't seem to be a MPL sequence, for example.

No, it's not. The overloaded_function accepts a number of type
template parameters from a min of 1 to a max of
BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.

--Lorenzo


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net