Which is the better way to initialize a type in c++14:
#include <iostream> #include <vector> using namespace std; int main() { // your code goes here int i = 0; int _initializer_list_i {0}; std::cout << "Initialize with = " << std::to_string(i); std::cout << "Initialize with std::initializer_list " << std::to_string(_initializer_list_i); std::cout << "\nNormal intialize: \n"; std::vector<int> v(10, 22); for(auto it = v.begin(); it != v.end(); it++) std::cout << *it << "\n"; std::cout << "\n\nUsing intializer_list: \n"; std::vector<int> v2{10, 22}; for(auto it = v2.begin(); it != v2.end(); it++) std::cout << *it << "\n"; return 0; } When I use {}, it calls the constructor for std::initializer_list, but the result is the same as with =. Have some performance case here?
int i = 0; int _initializer_list_i {0}; And here's another case using std::vector<T>:
std::vector<int> v(10, 22);//allocate 10 with value 22 std::vector<int> v2{10, 22}; //Call std::initializer_list with 2 positions{10, 20} Which is the better way to initialize? Some performance case?
the result is the same that {operator=}?The code you show never once usesoperator=operator=use in the above code.int x = 3;does not involveoperator=. Please be more specific in what you mean by "better".