Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > initializer_list in the new standard

Reply
Thread Tools

initializer_list in the new standard

 
 
Sarath
Guest
Posts: n/a
 
      03-01-2007
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?

 
Reply With Quote
 
 
 
 
Pete Becker
Guest
Posts: n/a
 
      03-01-2007
Sarath wrote:
> 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)
 
Reply With Quote
 
 
 
 
Sarath
Guest
Posts: n/a
 
      03-01-2007
On Mar 1, 9:32 pm, Pete Becker <(E-Mail Removed)> wrote:
> Sarath wrote:
> > 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)


no I was talking about the intrinsic type arrays

 
Reply With Quote
 
Pete Becker
Guest
Posts: n/a
 
      03-01-2007
Sarath wrote:
> On Mar 1, 9:32 pm, Pete Becker <(E-Mail Removed)> wrote:
>> Sarath wrote:
>>> 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.
>>

>
> 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)
 
Reply With Quote
 
David Harmon
Guest
Posts: n/a
 
      03-01-2007
On 1 Mar 2007 04:36:10 -0800 in comp.lang.c++, "Sarath"
<(E-Mail Removed)> wrote,
>no I was talking about the intrinsic type arrays


What section number in the draft are you referring to?

 
Reply With Quote
 
Sarath
Guest
Posts: n/a
 
      03-02-2007
On Mar 2, 2:17 am, David Harmon <(E-Mail Removed)> wrote:
> On 1 Mar 2007 04:36:10 -0800 in comp.lang.c++, "Sarath"
> <(E-Mail Removed)> wrote,
>
> >no I was talking about the intrinsic type arrays

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


Could you please refer to this link?

http://en.wikipedia.org/wiki/C%2B%2B...e_constructors

 
Reply With Quote
 
=?iso-8859-1?q?Erik_Wikstr=F6m?=
Guest
Posts: n/a
 
      03-02-2007
On Mar 2, 6:35 am, "Sarath" <(E-Mail Removed)> wrote:
> On Mar 2, 2:17 am, David Harmon <(E-Mail Removed)> wrote:
>
> > On 1 Mar 2007 04:36:10 -0800 in comp.lang.c++, "Sarath"
> > <(E-Mail Removed)> wrote,

>
> > >no I was talking about the intrinsic type arrays

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

>
> Could you please refer to this link?
>
> http://en.wikipedia.org/wiki/C%2B%2B...e_constructors


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

--
Erik Wikström

 
Reply With Quote
 
Pete Becker
Guest
Posts: n/a
 
      03-02-2007
Sarath wrote:
> On Mar 2, 2:17 am, David Harmon <(E-Mail Removed)> wrote:
>> On 1 Mar 2007 04:36:10 -0800 in comp.lang.c++, "Sarath"
>> <(E-Mail Removed)> wrote,
>>
>>> no I was talking about the intrinsic type arrays

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

>
> Could you please refer to this link?
>
> http://en.wikipedia.org/wiki/C%2B%2B...e_constructors
>


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/wg...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)
 
Reply With Quote
 
David Harmon
Guest
Posts: n/a
 
      03-03-2007
On Fri, 02 Mar 2007 11:51:52 -0500 in comp.lang.c++, Pete Becker
<(E-Mail Removed)> wrote,
>For the latest status of language additions, see
>http://www.open-std.org/jtc1/sc22/wg...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?

 
Reply With Quote
 
Pete Becker
Guest
Posts: n/a
 
      03-03-2007
David Harmon wrote:
> On Fri, 02 Mar 2007 11:51:52 -0500 in comp.lang.c++, Pete Becker
> <(E-Mail Removed)> wrote,
>> For the latest status of language additions, see
>> http://www.open-std.org/jtc1/sc22/wg...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?
>


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)
 
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
A better technique than initializer_list. Worth a defect report? Elias Salomão Helou Neto C++ 6 07-28-2010 07:44 AM
C++0x, exact semantics of initializer_list<E> SG C++ 4 07-23-2010 01:06 AM
initializer_list members not being constexpr anymore Rodolfo Lima C++ 0 06-28-2010 12:37 AM
add pexpect to the standard library, standard "install" mechanism. funkyj Python 5 01-20-2006 08:35 PM
How standard is the standard library? steve.leach Python 1 04-18-2005 04:07 PM



Advertisments