Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: The members of ::std::initializer_list

45 views
Skip to first unread message
Message has been deleted

Victor Bazarov

unread,
May 5, 2015, 11:30:53 AM5/5/15
to
On 5/5/2015 11:05 AM, Stefan Ram wrote:
> Can someone explain why the type ::std::initializer_list
> does not have some convenience members that some programmers
> might expect? IIRC, it's members can be stored in ROM, but
> why does an ::std::initializer_list l has
>
> l.begin()
> ::std::begin( l )
>
> but no
>
> l.cbegin()
> ::std::cbegin( l )
>
> , and why is there no
>
> l[ size_t ]
> l.at( size_t )
>
> ?

Most likely *because* those were deemed unnecessary or unnecessarily
difficult to implement. An initializer list is not a container. Its
purpose is to assist initialization, that's all.

I hope you're not going to ask next why pointers and arrays don't have
members like 'cbegin' or 'rend'...

Besides, the rationales behind language design decisions are discussed
in comp.std.c++. Consider posting there, if you are really interested
and not just venting some kind of frustration, OK?

V
--
I do not respond to top-posted replies, please don't ask
Message has been deleted

Victor Bazarov

unread,
May 5, 2015, 12:36:11 PM5/5/15
to
On 5/5/2015 12:07 PM, Stefan Ram wrote:
> Victor Bazarov <v.ba...@comcast.invalid> writes:
>> I hope you're not going to ask next why pointers and arrays don't have
>> members like 'cbegin' or 'rend'...
>
> Well, for arrays ...
>
> #include <iostream>
> #include <ostream>
> #include <memory>
> #include <vector>
>
> int main()
> { ::std::cout << __cplusplus << '\n';
> ::std::vector< int >a{ 1, 2, 3 };
> for( auto p = ::std::cbegin( a ); p != ::std::cend( a ); ++p )

Yes, but those are not *members*.

> ::std::cout << *p << '\n'; }
>
> 201402
> 1
> 2
> 3
>
> And all of a sudden, it also works with initializer lists!
>
> My problem was actually that I did not manage before to force
> my compiler into C++14 mode before!
>
> #include <iostream>
> #include <ostream>
> #include <memory>
> #include <initializer_list>
>
> int main()
> { ::std::cout << __cplusplus << '\n';
> ::std::initializer_list< int >a{ 1, 2, 3 };
> for( auto p = ::std::cbegin( a ); p != ::std::cend( a ); ++p )
> ::std::cout << *p << '\n'; }
>
> 201402
> 1
> 2
> 3
Message has been deleted

Bo Persson

unread,
May 5, 2015, 1:43:25 PM5/5/15
to
On 2015-05-05 17:05, Stefan Ram wrote:
> Can someone explain why the type ::std::initializer_list
> does not have some convenience members that some programmers
> might expect? IIRC, it's members can be stored in ROM, but
> why does an ::std::initializer_list l has
>
> l.begin()
> ::std::begin( l )
>
> but no
>
> l.cbegin()
> ::std::cbegin( l )
>
> , and why is there no
>

Part of this is likely just an historical accident. In C++98 none of the
containers had cbegin or cend. When they were added by one C++11
proposal, std::initializer_list was in another proposal, and apparently
nobody thought about cross checking that.

The free functions, added even later, should work in all cases.


Bo Persson


Juha Nieminen

unread,
May 6, 2015, 4:42:10 AM5/6/15
to
Victor Bazarov <v.ba...@comcast.invalid> wrote:
> Besides, the rationales behind language design decisions are discussed
> in comp.std.c++. Consider posting there, if you are really interested
> and not just venting some kind of frustration, OK?

Dispersing conversation about the same topic (ie. C++) into several
groups doesn't help anybody. It's not like this group gets thousands
of posts every day and there's need to alleviate the flooding.

--- news://freenews.netfront.net/ - complaints: ne...@netfront.net ---

Victor Bazarov

unread,
May 6, 2015, 9:06:03 AM5/6/15
to
On 5/6/2015 4:41 AM, Juha Nieminen wrote:
> Victor Bazarov <v.ba...@comcast.invalid> wrote:
>> Besides, the rationales behind language design decisions are discussed
>> in comp.std.c++. Consider posting there, if you are really interested
>> and not just venting some kind of frustration, OK?
>
> Dispersing conversation about the same topic (ie. C++) into several
> groups doesn't help anybody. It's not like this group gets thousands
> of posts every day and there's need to alleviate the flooding.

Welcome back! I've missed you. It's not the same newsgroup without you.
Message has been deleted
0 new messages