Boost logo

Boost :

Subject: Re: [boost] tuple<T,T,...> generator meta-function
From: mbiddeg_at_[hidden]
Date: 2009-10-23 10:13:55


Both will work, if you want different types generated.

I think Emre wants the same type generated for T, not T0, T1, T2..... as the preprocessor & variadics would do.

Pass make_tuple<int, 8>, & it generates a tuple of 8 ints.

However, if otherwise, & no access to C++ 0x:

#include <boost/preprocessor/repetition/enum_params.hpp>

template<size_t VAL, size_t LIMIT>

 struct limit_repeat {

    enum { value = LIMIT < VAL ? LIMIT : VAL };

};

template <typename T, size_t N, size_t M>

struct make_tuple { };

 template <typename T>

 struct make_tuple<T, N = 1, M = limit_repeat<N, BOOST_PP_LIMIT_REPEAT>::value >

 {

      typedef boost::tuple<BOOST_PP_ENUM_PARAMS(M, T)> type;

  };

______________________________________________________________________

Kizza George Mbidde

Interconnect Billing Systems Analyst

IT

cell: +256 77 212 0982

email: mbiddeg_at_[hidden]

-----Original Message-----
From: boost-bounces_at_[hidden] [mailto:boost-bounces_at_[hidden]] On Behalf Of Frank Mori Hess
Sent: October 23, 2009 16:16
To: boost_at_[hidden]
Subject: Re: [boost] tuple<T,T,...> generator meta-function

-----BEGIN PGP SIGNED MESSAGE-----

Hash: SHA1

On Friday 23 October 2009, Emre Turkay wrote:

> Hi folks,

>

> How can I do this in a better way?

>

> template <typename T, size_t N>

> struct make_tuple { };

>

> template <typename T>

> struct make_tuple<T, 1>

> {

> typedef boost::tuple<T> type;

> };

>

> template <typename T>

> struct make_tuple<T, 2>

> {

> typedef boost::tuple<T, T> type;

> };

>

If you have a c++0x compiler, you could define it recursively using variadic

templates. Otherwise, you could use Boost.Preprocessor.

-----BEGIN PGP SIGNATURE-----

Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkrhrJkACgkQ5vihyNWuA4WOIQCeLggKvmAlYFzRsYWXSwiqd5tx

JJkAnikG50kPcfpo86Whp8UVZoGWZ9yF

=BXDu

-----END PGP SIGNATURE-----

_______________________________________________

Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

No virus found in this incoming message.

Checked by AVG - www.avg.com

Version: 8.5.423 / Virus Database: 270.14.27/2452 - Release Date: 10/22/09 18:44:00


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