Boost logo

Boost :

From: Vesa Karvonen (vesa_karvonen_at_[hidden])
Date: 2002-03-19 06:09:47


>I'm trying to use the BPL for the following and I'm kind of stuck.
[...]

I have trouble understanding the intention. If you just want a new syntax
for specifying function types, then I would recommend to not do it. If you
want a macro for specifying functions types that take N arguments of a
single type, then there might be some sense. What is it that you are trying
to macroize?

Are you positive about the syntax of function typedefs that you seem to be
trying to achieve? The following is a representative of a function
declaration (of 1 parameter):

  ret_type fun_name(param);

To get a typedef from any declaration, you just put `typedef´ in front of
the declaration:

  typedef ret_type fun_type(param);

Anyway, you obviously need to pass the param to the macro. Try the
following:

  #include <boost/preprocessor.hpp>

  #define MAKE_FUNCTION_TYPE_NAME(f_name)\
    BOOST_PP_CAT(f_name,_type)

  #define MAKE_TYPEDEF_N(ret_type,f_name,n_params,param)\
    typedef ret_type f_name(MAKE_FUNCTION_TYPE_NAME(f_name))\
      (BOOST_PP_ENUM_PARAMS(n_params,param))

  #define TYPEDEF_0(ret_type,f_name)\
    MAKE_TYPEDEF_N(ret_type,f_name,0,_)
  #define TYPEDEF_1(ret_type,f_name,param0)\
    MAKE_TYPEDEF_N(ret_type,f_name,1,param0)

The above (probably) isn't what you were after, however. You probably want
to be able to pass an arbitrary number of parameters:

  TYPEDEF_3(void,bar,foo_type,int,long)

And get:

  typedef void bar(bar_type)(foo_type,int,long)

The above can be done, but I do not understand the motivation. You might
want to consider using lists.

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk