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 10:50:01


On Wed, Oct 17, 2012 at 4:24 AM, Felipe Magno de Almeida
<felipe.m.almeida_at_[hidden]> wrote:
> On Wed, Oct 17, 2012 at 2:49 AM, Lorenzo Caminiti <lorcaminiti_at_[hidden]> wrote:
>> 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
>
> I want to query boost::overloaded_function<x, y, z> to get 3 at compile-time.

overloaded_function could expose this as a constant but...

>> 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?
>
> I don't know because I get the type as template parameter and I must
> create an instance of that type with that many functors and return it.

... can you post some example code to illustrate what you are trying to do?

>>> 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.
>
> Yeah, I would have to resort on knowing that the default template
> parameter is void, or maybe
> check if the type boost::is_function.
>
>>> 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.
>
> That's a bit restricting. I could really use a overloaded_function
> that received a MPL or Fusion
> sequence as well.

Why do you need to use MPL and Fusion sequences? What's the use case?
You should be able to do the same with the current interface (a part
from the other question of if the current interface should expose the
number of overloads as constant).

--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