Boost logo

Boost :

From: Brock Peabody (brock.peabody_at_[hidden])
Date: 2003-08-05 10:24:46


That's a cool idea. It's a lot prettier than using the preprocessor.

Does anyone know whether or not a language solution is being considered
for this or variable class template arguments?

> -----Original Message-----
> From: boost-bounces_at_[hidden]
[mailto:boost-bounces_at_[hidden]]
> On Behalf Of Philippe A. Bouchard
> Sent: Monday, August 04, 2003 9:39 PM
> To: boost_at_[hidden]
> Subject: [boost] Infinite number of parameters?
>
> Hello,
>
> Often some function and functors requires to be overloaded N times
to
> handle undefinite number of arguments, depending on some default
setting.
> Maybe the following could be used; it overloads operator , () and
> gradually
> creates a typelist. This typelist is used to replace the undefinite
> number
> of arguments:
>
> #include <iostream>
>
>
> using namespace std;
>
>
> namespace infinite
> {
>
>
> template <typename T = void, typename U = void>
> struct typelist : U
> {
> typedef T type;
>
> T value;
>
> typelist(T const & a, U const & b) : value(a), U(b) {}
> };
>
> template <>
> struct typelist<void, void>
> {
> typedef void type;
> };
>
> template <typename T>
> struct typelist<T, void>
> {
> typedef T type;
>
> T value;
>
> typelist(T const & a) : value(a) {}
> };
>
>
> typelist<> const begin = typelist<>();
>
>
> }
>
>
> template <typename V>
> infinite::typelist<V, void> operator , (infinite::typelist<> const &,
V
> const & v)
> {
> return infinite::typelist<V, void>(v);
> }
>
> template <typename T, typename U, typename V>
> infinite::typelist< V, infinite::typelist<T, U> > operator ,
> (infinite::typelist<T, U> const & t, V const & v)
> {
> return infinite::typelist< V, infinite::typelist<T, U> >(v,
> infinite::typelist<T, U>(t));
> }
>
>
> // Usage example:
>
> template <typename T, typename U>
> void foo(infinite::typelist<T, U> const & i)
> {
> cout << __PRETTY_FUNCTION__ << endl;
> }
>
> int main()
> {
> foo((infinite::begin, true, (char *) "adasd", 12367, 127.2));
> }
>
>
>
> My 0,02$
>
> Philippe
>
>
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost


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