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

std::initializer_list assignment operator

28 views
Skip to first unread message

hbdev...@gmail.com

unread,
Apr 4, 2016, 1:13:14 AM4/4/16
to
Hi all,

In the code below, an assignment operator is used on the second line in main function.
I am curious to see how the initializer_list assignment operator looks like but I can't find its code in the STL library.
The class definition in /usr/include/c++/5/initializer_list does not provide any assignment operator.

Could anyone please tell me in which file it is defined ?


Thank you in advance


// initializer_list example
#include <iostream> // std::cout
#include <initializer_list> // std::initializer_list

int main ()
{
std::initializer_list<int> mylist;
mylist = { 10, 20, 30 }; ///<---------- ???????
std::cout << "mylist contains:";
for (int x: mylist) std::cout << ' ' << x;
std::cout << '\n';
return 0;
}

Öö Tiib

unread,
Apr 4, 2016, 2:23:47 AM4/4/16
to
On Monday, 4 April 2016 08:13:14 UTC+3, hbdev...@gmail.com wrote:
> Hi all,
>
> In the code below, an assignment operator is used on the second line in main function.
> I am curious to see how the initializer_list assignment operator looks like but I can't find its code in the STL library.
> The class definition in /usr/include/c++/5/initializer_list does not provide any assignment operator.
>
> Could anyone please tell me in which file it is defined ?

As legacy from C the C++ compiler makes assignment operators implicitly
for structs/classes when it is not explicitly done by user.

Besides that 'std::initializer_list' is a "magical" class and so not all
of its behavior is possible to implement as library code.
0 new messages