Namespaces
Variants
Views
Actions

Talk:cpp/utility/initializer list

From cppreference.com
   std::pair<const int*, size_t> c_arr() const {
       return {&v[0], v.size()};  // list-initialization in return statement
   }

Doesn't this example just call pair<const int*, size_t> constructor, without creating any initializer_list? What type would value_type be?

True, this is an example of list-initialization. The author of the example just used that helper function to get some values, not to demonstrate initializer_list. I added a comment to the example, to hopefully make that clearer. --Cubbi 14:45, 5 December 2012 (PST)
Shouldn't the first template parameter to std:pair be const T*? 92.22.189.245 01:57, 1 May 2013 (PDT)
Yes, that makes more sense. Changed. --Cubbi 03:22, 1 May 2013 (PDT)
Should &v[0] be v.data()? 67.200.126.4 07:58, 16 September 2014 (PDT)
data() would make sense if v could be empty.. I don't think it matters in this case. &v[0] is more common since it predates c++11. --Cubbi (talk) 10:28, 16 September 2014 (PDT)