Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: Please cons...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 4 Topic 9507 of 10104
Post > Topic >>

Re: Please consider this addition for tuples in c++0x

by Brendan <catphive@[EMAIL PROTECTED] > Apr 17, 2008 at 03:51 AM

On Apr 16, 10:37 am, german diago <germandi...@[EMAIL PROTECTED]
> wrote:
> Hello. I would like to propose a small addition to the tuple class
> template in c++0x. I'm surprised I didn't
> see this in any proposal, since it's gonna give us more than a
> headache (I think) if it's not included.
> Since the tuple class template is a container, it would be very useful
> to be able to loop over
> each element in the tuple. This is not easy, since that requires
> metaprogramming.
>
> A good small addition would be to do something like this:
>
> struct do_something
> {
>        template <class T>
>        void operator()(const T & elem)
>        {
>           //...
>        }
>
> };

I think in most cases it would be impractical to fill that method in.

> int main()
> {
>      tuple<int, float, std::string> t(3, 2.38f, "hello");
>
>     tuple_elem_each(t, do_something());
>
> }

Technically there is nothing wrong with this, and I think that it
would actually be pretty easy to write this function. It would just
take the type of t as a template argument, and then pass it to a
simple template metaprogram.

However, tuples aren't really meant to hold arbitrarily sized
collections that need to be iterated over. They are only collections
in the sense that a struct is a collection of it's elements. They are
meant to be a convenient way to pack and unpack a small number of
variables of possibly different types. You should think of them as a
kind of anonymous struct for packing parameters.

Also, since there's a limit to the level of template recursion in a
given compiler, large enough tuples aren't ****table.

-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 4 Posts in Topic:
Please consider this addition for tuples in c++0x
german diago <germandi  2008-04-16 11:37:05 
Re: Please consider this addition for tuples in c++0x
Mathias Gaunard <loufo  2008-04-17 03:55:06 
Re: Please consider this addition for tuples in c++0x
Brendan <catphive@[EMA  2008-04-17 03:51:10 
Re: Please consider this addition for tuples in c++0x
german diago <germandi  2008-04-17 11:43:14 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Oct 15 22:37:55 CDT 2008.