0

introduced Uniform Initialization Syntax as an explicit way to work around the Most Vexing Parse.

I believe http://en.cppreference.com refers to it as Direct List Initialization.

Anyway whatever you call it it doesn't seem to work in . Given this example:

istringstream foo("192 168 1 1");
const vector<int> bar{ istream_iterator<int>(foo), istream_iterator<int>() };

cout << bar.front() << endl;

I get the error:

error C2601: bar : local function definitions are illegal

If I instead do: const vector<int> bar(istream_iterator<int>(foo), istream_iterator<int>()); I get the error:

error C2228: left of .front must have class/struct/union

I can work around this with the pre- workaround: const vector<int> bar((istream_iterator<int>(foo)), istream_iterator<int>()); But I find it frustrating. Is Uniform Initialization Syntax not implemented for ?

Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
  • @FrançoisAndrieux Yeah... that's an `initialization_list` question. This isn't. – Jonathan Mee Jan 11 '18 at 14:03
  • The syntax is not applied consistently anyway: iterators can use `{}` too, or even better, `istream_iterator{foo}, {}`, the latter will be inferred. – Incomputable Jan 11 '18 at 14:03
  • @Incomputable I actually tried that and still get the exact same errors, through that doesn't seem necessary elsewhere. – Jonathan Mee Jan 11 '18 at 14:04
  • My first comment was wrong, VS2013 was the one that rolled back support for default member initializers in an [update](https://blogs.msdn.microsoft.com/vcblog/2014/08/19/the-future-of-non-static-data-member-initialization/). VS2012 just [doesn't support](https://msdn.microsoft.com/en-us/library/hh567368(v=vs.110).aspx) list initialization. – Praetorian Jan 11 '18 at 14:10
  • @Praetorian So I see "Initializer Lists" in the unsupported features. I understood "Uniform Initialization Syntax" to be separate from that. – Jonathan Mee Jan 11 '18 at 14:18

0 Answers0