-1

Well this is a silly question but I have this error :

#include <unordered_set> 
std::unordered_set<std::string> ValidValues **{**"one", "two", "three"};

Error : expected a ";" appears at the first bracket. Exacty the same with a "set".

Restarted Visual Studio 2010 and the computer.

Mr. Starck
  • 232
  • 6
  • 16

1 Answers1

3

This works:

#include <string>
#include <unordered_set> 
std::unordered_set<std::string> ValidValues {"one", "two", "three"};

with GCC 4.4+, Clang 3.1+, and MSVS2013+.

MSVS2010/2012 does not support the language feature called list initialization, wich is what you are doing.

rubenvb
  • 74,642
  • 33
  • 187
  • 332
  • Doens't compile with VS 2012 – Mr. Starck Jan 28 '14 at 10:56
  • @Mr.Starck You're right, the 2012 November CTP added language support for them, but didn't modify the library to add the `std::initializer_list` constructors, and so 2013 it is. – rubenvb Jan 28 '14 at 11:00