Jump to content
  • Advertisement
Sign in to follow this  
CommanderXXL

Variable template argument lists

This topic is 3629 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to write a template functor which uses a variable argument list. I tried it with the following code:
template < typename RetVal, ... Args > class CBaseFunctorBase
{
public:
	virtual RetVal Run(Args _Params) const = 0;
};

this is (according to the few sources i found) the way to do it. But my visual studio 2008 does not compile it. I get "C2059: syntax error: '...'" Is it possible that microsoft does not support this c++ conform template ellipsis parameters? If anyone knows another solution to my problem please post it. Thanks

Share this post


Link to post
Share on other sites
Advertisement
Coming in next C++ standard.

It's supported by some experimental compilers, but isn't considered as available for production use yet.

Share this post


Link to post
Share on other sites
As Antheus said this is the next standard, to do something like what you want in the current standard you could always go the same way as Loki and use typelists and function overloading, see his functor template class on sourceforge.

Share this post


Link to post
Share on other sites
Until compiler support comes along (it's in GCC 4.3 if you want to play with it now), you might be able to create a workaround using Boost's preprocessor library and/or the MPL (mentioned in a previous post) to generate numerous overloads.

Share this post


Link to post
Share on other sites
Quote:
Original post by CommanderXXL
template < typename RetVal, ... Args > class CBaseFunctorBase
{


This sounds like you might be trying to reinvent boost::function.

Share this post


Link to post
Share on other sites
In the meantime:

#ifndef IG_THIS
#define IG_THIS

#include <boost/preprocessor.hpp>

template < typename R, BOOST_PP_ENUM_BINARY_PARAMS( 10, typename A, = void BOOST_PP_INTERCEPT ) > class CBaseFunctorBase;

#define BOOST_PP_FILENAME_1 "this.hpp"
#define BOOST_PP_ITERATION_LIMITS (0, 10)
#include BOOST_PP_ITERATE()


#elif defined( BOOST_PP_IS_ITERATING )

template < typename R BOOST_PP_ENUM_TRAILING_PARAMS( BOOST_PP_ITERATION(), typename A ) > class CBaseFunctorBase {
public:
virtual R Run( BOOST_PP_ENUM_BINARY_PARAMS( BOOST_PP_ITERATION(), A, a ) ) const = 0;
};

#endif




Fixing the bugs is left as an exercise to the reader.

Share this post


Link to post
Share on other sites
Hmm MaulingMonkey pimping Boost PP again:) I just can not get my head around how it is doing what it does. I have read the Boost docs, looked at the source and it might as well be written in brainfuck! Maybe Zahlman or SiCrane could give a little run down of how it actually works and really twists the language.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!