Skip to main content
GameDev.net gamedev.net
🔒 Locked

Variable template argument lists

Started by CommanderXXL Jul 10, 2008 at 1:23 PM 6 replies 1.5k views
Original Post
CommanderXXL
CommanderXXL
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
---------------------------- By CommanderXXLCommander@bloomm.de----------------------------
Antheus
Antheus
Coming in next C++ standard.

It's supported by some experimental compilers, but isn't considered as available for production use yet.
dmail
dmail
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.
Zahlman
Zahlman
Quote:
Original post by CommanderXXL
template < typename RetVal, ... Args > class CBaseFunctorBase
{


This sounds like you might be trying to reinvent boost::function.
MaulingMonkey
MaulingMonkey
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.
dmail
dmail
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.