Iterate over template arguments
Hi,
I have a set of old classes which I use for inter process communication:
Example:
template
On 11/23/2011 03:34 PM, Allan Nielsen wrote:
What I would like is an interface where the following would be valid (much like boost function):
Interface< int (int, std::string )> if1(...) ;
I known this might not be easy or the intension of c++99, but I would like to give it a try anyway...
There is no particular problem doing that in C++98/03. You may want to take a look at http://www.boost.org/doc/libs/release/libs/function_types/doc/html/index.htm... It can extract the return type and convert the arguments to an MPL sequence.
On Wed, Nov 23, 2011 at 8:45 AM, Mathias Gaunard
On 11/23/2011 03:34 PM, Allan Nielsen wrote:
What I would like is an interface where the following would be valid (much like boost function):
Interface< int (int, std::string )> if1(...) ;
You may want to take a look at http://www.boost.org/doc/libs/release/libs/function_types/doc/html/index.htm...
It can extract the return type and convert the arguments to an MPL sequence.
I'm in the process of trying to wrap my head around MPL and am reading the metaprogramming book. It has a good description of MPL sequences and iterating over arguments in either ch 3 or 4 (that's from memory...too lazy to pull up the book). -- Chris Cleeland
On Wed, Nov 23, 2011 at 3:45 PM, Mathias Gaunard
On 11/23/2011 03:34 PM, Allan Nielsen wrote:
What I would like is an interface where the following would be valid (much like boost function):
Interface< int (int, std::string )> if1(...) ;
I known this might not be easy or the intension of c++99, but I would like to give it a try anyway...
There is no particular problem doing that in C++98/03.
You may want to take a look at http://www.boost.org/doc/libs/release/libs/function_types/doc/html/index.htm...
It can extract the return type and convert the arguments to an MPL sequence.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Hi It might be me which does not understand it, but as I read the documentation funciton_types is for manipulating functions pointers, not to manage template arguments... Please correct me if I'm wrong -- Allan
It might be me which does not understand it, but as I read the documentation funciton_types is for manipulating functions pointers, not to manage template arguments...
Please correct me if I'm wrong Okay, I got it...
is one template argument... : typename boost::function_types::result_type<T0>::type is the return type, and I can use parameter_types and MPL to iterate over the parameters. Clever..
But how do I implement the call interface: template<typename T > struct IfCall { typedef typename boost::function_types::result_type<T0>::type R; R call( /* T0, T1, T2...*/ ) { // can I get the MPL sequence into the method signature?? } }; -- Allan
On Wed, Nov 23, 2011 at 7:33 AM, Allan Nielsen wrote:
It might be me which does not understand it, but as I read the documentation funciton_types is for manipulating functions pointers, not to manage template arguments...
Please correct me if I'm wrong Okay, I got it...
is one template argument... : typename boost::function_types::result_type<T0>::type is the return type, and I can use parameter_types and MPL to iterate over the parameters. Clever.. But how do I implement the call interface:
template<typename T > struct IfCall { typedef typename boost::function_types::result_type<T0>::type R;
R call( /* T0, T1, T2...*/ ) { // can I get the MPL sequence into the method signature?? } };
Ugh. Well, what I can think of at the moment: - Use the Boost.Preprocessor library to specialize each arity of lfCall, e.g., generate template< class R, class T0 > struct lfCall< R ( T0 ) > { /*...*/ R call(T0) { /*...*/ } }; and similarly for all other supported arities with the preprocessor; or - If you're flexible in the call interface, you might be able to utilize Boost.Fusion's fuse/unfuse adaptors [1]. - Jeff http://www.boost.org/doc/libs/1_48_0/libs/fusion/doc/html/fusion/functional/...
On 11/23/2011 04:33 PM, Allan Nielsen wrote:
It might be me which does not understand it, but as I read the documentation funciton_types is for manipulating functions pointers, not to manage template arguments...
Please correct me if I'm wrong Okay, I got it...
is one template argument... : typename boost::function_types::result_type<T0>::type is the return type, and I can use parameter_types and MPL to iterate over the parameters. Clever.. But how do I implement the call interface:
template<typename T> struct IfCall { typedef typename boost::function_types::result_type<T0>::type R;
R call( /* T0, T1, T2...*/ ) { // can I get the MPL sequence into the method signature?? } };
You need to use the preprocessor for this; in that case, you can also
get rid of Boost.FunctionTypes.
#include
participants (4)
-
Allan Nielsen
-
Chris Cleeland
-
Jeffrey Lee Hellrung, Jr.
-
Mathias Gaunard