473,322 Members | 1,526 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

initializer lists and user-defined containers

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

Jul 22 '05 #1
4 1248
jf******@gmail.com 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
Jul 22 '05 #2
jf******@gmail.com 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
Jul 22 '05 #3
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
Jul 22 '05 #4
<jf******@gmail.com> wrote in message
news:10**********************@z14g2000cwz.googlegr 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
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Alexander Stippler | last post by:
Hi, I wonder about the behaviour of como and icc on some very simple program. I thought initializing members of classes, which are of class type, would be 'direct initialized' (as the standard...
1
by: Chris K | last post by:
I am relatively new to C++ and hope that this question is relevant. I have spent some time at the local library and some time on dejanews, but have no decided to go ahead with my question, since...
2
by: ccs | last post by:
First, no compiling error for the following code... class CStudent { int id; public: CStudent(int i) : id(i); }; class CTeam
12
by: Serve Laurijssen | last post by:
Is code like the following allowed? I am talking about the comma after the last function in the initializer. void f(void) {puts("f");} void g(void) {puts("g");} struct Funcs { void...
3
by: Ham Pastrami | last post by:
class Point { public: const int x, y; Point(int x, int y); } Point::Point(int x, int y) : x(x), y(y) { }
0
by: =?Utf-8?B?YmlqYXk=?= | last post by:
The type initializer for 'Microsoft.ApplicationBlocks.Cache.CacheService' threw an exception. We migrated our windows application from 1.1 to 2.0. The debug and Release mode of the application...
4
by: =?Utf-8?B?YmlqYXk=?= | last post by:
We migrated our windows application from 1.1 to 2.0. The debug and Release mode of the application work fine with some tweaking. But when the setup project is migrated to 2.0 the installation gives...
6
by: Marvin Barley | last post by:
I have a class that throws exceptions in new initializer, and a static array of objects of this type. When something is wrong in initialization, CGI program crashes miserably. Debugging shows...
8
by: Richard | last post by:
If class C inherits from class B, which inherits from class A, is the order of the initializer list in the following constructor insignificant (C only inherits from A because it inherits from B)?:...
5
by: Pallav singh | last post by:
How can we justify that initializer list is better in performance than assignment list in constructor of C++ ??
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.