Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > initializer lists and user-defined containers

Reply
Thread Tools

initializer lists and user-defined containers

 
 
jfindlay@gmail.com
Guest
Posts: n/a
 
      10-14-2004
Is it possible to populate a container with an initializer list? I am
not too particular about how hackish or ugly any suggestions might be,
I'm simply interested in investigating possible elegancies (or
perversities) for an initializer list.

const container<double> array = mitigating_struct<double>() = {pi, e,
phi, gamma, 0.0042};
// container is magically filled with initalizer list members

Of course, something without an explicit temporary would be more ideal,
but perhaps beyond the realm of C++.


Justin

 
Reply With Quote
 
 
 
 
Gianni Mariani
Guest
Posts: n/a
 
      10-14-2004
wrote:
> Is it possible to populate a container with an initializer list? I am
> not too particular about how hackish or ugly any suggestions might be,
> I'm simply interested in investigating possible elegancies (or
> perversities) for an initializer list.
>
> const container<double> array = mitigating_struct<double>() = {pi, e,
> phi, gamma, 0.0042};
> // container is magically filled with initalizer list members
>
> Of course, something without an explicit temporary would be more ideal,
> but perhaps beyond the realm of C++.


It sounds like this is probably not what you want but it should be
interesting anyway.

http://bdsoft.com/tools/initutil.html
 
Reply With Quote
 
 
 
 
Ioannis Vranos
Guest
Posts: n/a
 
      10-14-2004
wrote:
> Is it possible to populate a container with an initializer list? I am
> not too particular about how hackish or ugly any suggestions might be,
> I'm simply interested in investigating possible elegancies (or
> perversities) for an initializer list.
>
> const container<double> array = mitigating_struct<double>() = {pi, e,
> phi, gamma, 0.0042};
> // container is magically filled with initalizer list members
>
> Of course, something without an explicit temporary would be more ideal,
> but perhaps beyond the realm of C++.



You may use a built in array:


int array[]={1,2,3,4,5,6,7};

vector<int> v(array, array+7);



or using a temp:


vector<int> v;

{
int temp[]={1,2,3,4,5,6,7};

v.assign(temp, temp+7);
}



--
Ioannis Vranos

http://www23.brinkster.com/noicys
 
Reply With Quote
 
Ioannis Vranos
Guest
Posts: n/a
 
      10-14-2004
Ioannis Vranos wrote:

> You may use a built in array:
>
>
> int array[]={1,2,3,4,5,6,7};
>
> vector<int> v(array, array+7);
>
>
>
> or using a temp:
>
>
> vector<int> v;
>
> {
> int temp[]={1,2,3,4,5,6,7};
>
> v.assign(temp, temp+7);
> }



Also check this:

http://groups.google.com/groups?hl=e....ntua.gr#link2



--
Ioannis Vranos

http://www23.brinkster.com/noicys
 
Reply With Quote
 
Thorsten Ottosen
Guest
Posts: n/a
 
      10-14-2004
<> wrote in message
news: oups.com...
| Is it possible to populate a container with an initializer list? I am
| not too particular about how hackish or ugly any suggestions might be,
| I'm simply interested in investigating possible elegancies (or
| perversities) for an initializer list.
|
| const container<double> array = mitigating_struct<double>() = {pi, e,
| phi, gamma, 0.0042};
| // container is magically filled with initalizer list members
|
| Of course, something without an explicit temporary would be more ideal,
| but perhaps beyond the realm of C++.

maybe boost.assign will be just what you want (see www.boost.org) It will be
in the next boost release, but you can
already get it from the main cvs if you want.

Shortly put (and among other ways), it allows you to say

const container<double> array = list_of<double>( pi )( e )( phi )( gamma )(
0.00042 );

br

Thorsten


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Are sequence containers not a subset of general containers? Sebastian Mach C++ 5 10-06-2012 07:54 PM
Containers of iterators vs. containers of references clark.coleman@att.net C++ 7 01-25-2008 01:37 PM
Initializer lists and multiple constructors Richard C++ 8 03-02-2007 12:46 AM
List of lists of lists of lists... =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==?= Python 5 05-15-2006 11:47 AM
Initializer and comma seperated lists Pmb C++ 2 05-26-2004 11:49 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57