Boost logo

Boost :

From: James Harris (james.harris_at_[hidden])
Date: 2004-10-30 02:55:22


Hello Boost Members,

I have written a small library of meta-functions that allow rebinding of
template arguments
and function pointer return/argument types. I am posting in an attempt to
guage interest and
hopefully receive pointers on the library proposal process.

The library provides the following meta-functions:

rebind<int index, class rebind_type, class source_type> -- rebind
template arguments
rebind_func_arg<int index, class rebind_type, class func_type> -- rebind
argument type of func/method ptr
rebind_func_return<class rebind_type, class func_type> -- rebind
return type of func/method ptr
rebind_method_class<class rebind_type, class func_type> -- rebind
class portion of method ptr

// --- rebind<> example ------------------------------------------------

template <class A, class B, class C>
class foo { };

typedef foo<int, int, int> source_type;
typedef rebind<1, char, source_type>::type rebound_type; // rebound_type
equates to foo<int, char, int>

// --- rebind_func_arg<> example ---------------------------------------

typedef int (*func_ptr)(int);
typedef rebind_func_arg<0, char, func_ptr>::type rebound_type //
rebound_type equates to int (*)(char)
// rebind_func_args also works with pointer-to-method types

// --- rebind_func_return<> example ------------------------------------

typedef int (*func_ptr)(int);
typedef rebind_func_return<char, func_ptr>::type rebound_type //
rebound_type equates to char (*)(int)
// rebind_func_return also works with pointer-to-method types

// --- rebind_method_class<class rebind_type, class func_type> ---------

typedef int (foo::*method_ptr)(int);
typedef rebind_method_class<bar, method_ptr>::type rebound_type; //
rebound_type equates to int (bar::*)(int);

-- end examples --

I have tested the code using MSVC 7.1 and GCC 3.3.2-1.

Please let me know if this library would be useful to any of you, or
otherwise any reason why it is not required or, of course any
tips/suggestions/questions that you might have.

Kind Regards,
James Harris.


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