initializer_list in the new standard

Discussion in 'C++' started by Sarath, Mar 1, 2007.

  1. Sarath

    Sarath Guest

    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?
     
    Sarath, Mar 1, 2007
    #1
    1. Advertising

  2. Sarath

    Pete Becker Guest

    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)
     
    Pete Becker, Mar 1, 2007
    #2
    1. Advertising

  3. Sarath

    Sarath Guest

    On Mar 1, 9:32 pm, Pete Becker <> 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
     
    Sarath, Mar 1, 2007
    #3
  4. Sarath

    Pete Becker Guest

    Sarath wrote:
    > On Mar 1, 9:32 pm, Pete Becker <> 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)
     
    Pete Becker, Mar 1, 2007
    #4
  5. Sarath

    David Harmon Guest

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


    What section number in the draft are you referring to?
     
    David Harmon, Mar 1, 2007
    #5
  6. Sarath

    Sarath Guest

    On Mar 2, 2:17 am, David Harmon <> wrote:
    > On 1 Mar 2007 04:36:10 -0800 in comp.lang.c++, "Sarath"
    > <> 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++0x#Sequence_constructors
     
    Sarath, Mar 2, 2007
    #6
  7. On Mar 2, 6:35 am, "Sarath" <> wrote:
    > On Mar 2, 2:17 am, David Harmon <> wrote:
    >
    > > On 1 Mar 2007 04:36:10 -0800 in comp.lang.c++, "Sarath"
    > > <> 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++0x#Sequence_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
     
    =?iso-8859-1?q?Erik_Wikstr=F6m?=, Mar 2, 2007
    #7
  8. Sarath

    Pete Becker Guest

    Sarath wrote:
    > On Mar 2, 2:17 am, David Harmon <> wrote:
    >> On 1 Mar 2007 04:36:10 -0800 in comp.lang.c++, "Sarath"
    >> <> 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++0x#Sequence_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/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)
     
    Pete Becker, Mar 2, 2007
    #8
  9. Sarath

    David Harmon Guest

    On Fri, 02 Mar 2007 11:51:52 -0500 in comp.lang.c++, Pete Becker
    <> wrote,
    >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?
     
    David Harmon, Mar 3, 2007
    #9
  10. Sarath

    Pete Becker Guest

    David Harmon wrote:
    > On Fri, 02 Mar 2007 11:51:52 -0500 in comp.lang.c++, Pete Becker
    > <> wrote,
    >> 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?
    >


    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)
     
    Pete Becker, Mar 3, 2007
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. steve.leach

    How standard is the standard library?

    steve.leach, Apr 18, 2005, in forum: Python
    Replies:
    1
    Views:
    411
    Christos TZOTZIOY Georgiou
    Apr 18, 2005
  2. Rodolfo Lima
    Replies:
    0
    Views:
    315
    Rodolfo Lima
    Jun 28, 2010
  3. SG
    Replies:
    4
    Views:
    1,814
    Dilip
    Jul 23, 2010
  4. Elias Salomão Helou Neto
    Replies:
    6
    Views:
    466
    Vladimir Jovic
    Jul 28, 2010
  5. Replies:
    2
    Views:
    499
    Thomas 'PointedEars' Lahn
    Mar 11, 2008
Loading...

Share This Page