initializer_list in the new standard

S

Sarath

In the new standard of C++ (C++ 0x), it has a new template class which
can contain a sequence of data.
there are many other templates like vector,dequeue and list are there.
How this one differs. can't we existing containers than this one?
 
P

Pete Becker

Sarath said:
In the new standard of C++ (C++ 0x), it has a new template class which
can contain a sequence of data.
there are many other templates like vector,dequeue and list are there.
How this one differs. can't we existing containers than this one?

Are you referring to std::array? The difference is that array is an
aggregate type, so all of its members are held directly in the object,
just as with a C-style array. This means, for example, that when you
create an array object on the stack, all of its members are also on the
stack.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
 
S

Sarath

Are you referring to std::array? The difference is that array is an
aggregate type, so all of its members are held directly in the object,
just as with a C-style array. This means, for example, that when you
create an array object on the stack, all of its members are also on the
stack.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)

no I was talking about the intrinsic type arrays
 
P

Pete Becker

Sarath said:
no I was talking about the intrinsic type arrays

Sorry, I don't know what you're referring to. The current C++ draft
doesn't use the word "intrinsic" anywhere, and I'm not going to look at
every use of the word "array" to see if it might fit this. <g>

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
 
D

David Harmon

On 1 Mar 2007 04:36:10 -0800 in comp.lang.c++, "Sarath"
no I was talking about the intrinsic type arrays

What section number in the draft are you referring to?
 
?

=?iso-8859-1?q?Erik_Wikstr=F6m?=


The goal of this class is not to act as a container such as vector or
dequeue, instead it is meant to be used when initializing, for
example, such a container. The idea is that you should be able to
write code such as:

std::vector<int> a = {1, 2, 3, 4};

Instead of

std::vector<int> a;
a.push_back(1);
a.push_back(2);
// and so on
 
P

Pete Becker

Sarath said:

You have to be a little careful with that article. As it says at the
top, it's not up to date.

For the latest status of language additions, see
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2122.htm. In
particular, search for "Initializer Lists", where you'll find a list of
the current papers on this subject.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
 
D

David Harmon

On Fri, 02 Mar 2007 11:51:52 -0500 in comp.lang.c++, Pete Becker
For the latest status of language additions, see
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2122.htm. In
particular, search for "Initializer Lists", where you'll find a list of
the current papers on this subject.

That "initializer list" proposal looked to me as if std::array in the
current draft might serve the same purpose. Is that true, or are the
distinct things?
 
P

Pete Becker

David said:
On Fri, 02 Mar 2007 11:51:52 -0500 in comp.lang.c++, Pete Becker


That "initializer list" proposal looked to me as if std::array in the
current draft might serve the same purpose. Is that true, or are the
distinct things?

In n2100, an initializer_list<T> object holds either a pair of pointers
or a pointer and a count. So, unlike std::array<T>, it provides indirect
access to a range. The name is also a magic cookie to the compiler,
which generates different code than it would for an ordinary argument.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top