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 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 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
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
<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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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
|
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...
|
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)
{
}
|
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...
|
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...
|
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...
|
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)?:...
|
by: Pallav singh |
last post by:
How can we justify that initializer list is better in performance
than assignment list in constructor of C++ ??
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
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...
|
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)...
|
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....
|
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
|
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...
| |