Top "Initializer-list" questions

std::initializer_list is a special type in C++11 which is used to construct containers and other types from a list of values of the same type.

When to use the brace-enclosed initializer?

In C++11, we have that new syntax for initializing classes which gives us a big number of possibilities how to …

c++ c++11 initializer-list
How to construct std::array object with initializer list?

Possible Duplicate: How do I initialize a member array with an initializer_list? You can construct an std::array just …

c++ arrays initializer-list c++11
std::initializer_list as function argument

For some reason I thought C++0x allowed std::initializer_list as function argument for functions that expect types that …

c++ c++11 initializer-list
C++: Should I initialize pointer members that are assigned to in the constructor body to NULL?

Suppose I have: // MyClass.h class MyClass { public: MyClass(); private: Something *something_; } // MyClass.cpp MyClass::MyClass() { something_ = new Something(); } Should …

c++ pointers constructor initializer-list ctor-initializer
std::shared_ptr and initializer lists

The std::shared_ptr constructor isn't behaving as I expected: #include <iostream> #include <vector> void func(…

c++ c++11 clang shared-ptr initializer-list
initializer_list and move semantics

Am I allowed to move elements out of a std::initializer_list<T>? #include <initializer_list> #…

c++ templates c++11 move-semantics initializer-list
Should constructor initialize all the data members of the class?

I have a situation like this: class A { public: A() : n(0) {} private: int n; int m; } There is simply no …

c++ eclipse initialization language-lawyer initializer-list
Initializer list in a range for loop

I have objects of different types derived from a single super-type. I wonder if there are any disadvantages in using …

c++ c++11 for-loop range initializer-list
Can I list-initialize a vector of move-only type?

If I pass the following code through my GCC 4.7 snapshot, it tries to copy the unique_ptrs into the vector. #…

c++ c++11 initializer-list move-semantics
C++ vector of arrays

Why does this work: std::pair<int, int> p = {1,2}; std::vector<std::pair<int, int>&…

c++ arrays c++11 initializer-list