[Boost.Functional.OverloadedFunction][C++03] Number of overloads in boost::overload_function<...>

Hello, Is there a way to know how many overloads are there in a overloaded_function without resorting to preprocessor metaprogramming in C++03? It doesn't seem to be a MPL sequence, for example. Regards, -- Felipe Magno de Almeida

On Tue, Oct 16, 2012 at 5:40 PM, Felipe Magno de Almeida
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

On Wed, Oct 17, 2012 at 2:49 AM, Lorenzo Caminiti
On Tue, Oct 16, 2012 at 5:40 PM, Felipe Magno de Almeida
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
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.
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.
--Lorenzo
Regards, -- Felipe Magno de Almeida

On Wed, Oct 17, 2012 at 4:24 AM, Felipe Magno de Almeida
On Wed, Oct 17, 2012 at 2:49 AM, Lorenzo Caminiti
wrote: On Tue, Oct 16, 2012 at 5:40 PM, Felipe Magno de Almeida
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
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

AMDG On 10/17/2012 07:50 AM, Lorenzo Caminiti wrote:
On Wed, Oct 17, 2012 at 4:24 AM, Felipe Magno de Almeida
wrote: 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?
This would happen if the overloads are computed by metaprogramming instead of being hard-coded into the source.
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).
I would argue that overloaded_function should be a fusion sequence even without knowing any specific use cases. If something looks like a container, I can pretty much guarantee that sooner or later, someone will want use algorithms on it. In Christ, Steven Watanabe

Hello,
Sorry, I didn't have much time to write this email sooner.
On Fri, Oct 19, 2012 at 12:42 AM, Steven Watanabe
AMDG
On 10/17/2012 07:50 AM, Lorenzo Caminiti wrote:
On Wed, Oct 17, 2012 at 4:24 AM, Felipe Magno de Almeida
wrote: 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?
This would happen if the overloads are computed by metaprogramming instead of being hard-coded into the source.
Yes. That's exactly the case. I'm writing a Java Binding library, and all I need to pass at runtime is three variables to create an overload set that is mapped to functions in Java. And at compile time I need to specify all the function overloads. Since it is not necessary, I don't want the user to create all function objects seperately, since their constructions are all the same. I need to pass just a sequence of function prototypes and the three variables I mentioned and I can just return a boost.overloadedfunction constructed by metaprogramming. [snip]
In Christ, Steven Watanabe
Regards, -- Felipe Magno de Almeida

On Thu, Oct 18, 2012 at 8:54 PM, Felipe Magno de Almeida
Hello,
Sorry, I didn't have much time to write this email sooner.
On Fri, Oct 19, 2012 at 12:42 AM, Steven Watanabe
wrote: AMDG
On 10/17/2012 07:50 AM, Lorenzo Caminiti wrote:
On Wed, Oct 17, 2012 at 4:24 AM, Felipe Magno de Almeida
wrote: 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?
This would happen if the overloads are computed by metaprogramming instead of being hard-coded into the source.
Yes. That's exactly the case. I'm writing a Java Binding library, and all I need to pass at runtime is three variables to create an overload set that is mapped to functions in Java. And at compile time I need to specify all the function overloads. Since it is not necessary, I don't want the user to create all function objects seperately, since their constructions are all the same. I need to pass just a sequence of function prototypes and the three variables I mentioned and I can just return a boost.overloadedfunction constructed by metaprogramming.
This is fine. Also as Steven mentioned using Fusion sequences might provide an API to support generic algorithms on the overloaded_function type which is useful on itself. I'm willing to add either the MPL or Fusion sequence to the API (it should be backward compatible). However, I'd like to see some example code as a use case against which I can implement such a functionality. Can you please post, in a form or another, the code that you are trying to program? Thanks, --Lorenzo
participants (3)
-
Felipe Magno de Almeida
-
Lorenzo Caminiti
-
Steven Watanabe