0

I am trying to run the count occurrences of elements in a vector code listed in the answer here.

But I'm running into compile errors in this function:

auto h = [](const std::string* s) {
     return std::hash<std::string>()(*s);
};

stating Expected expression around the [ ]. I know this has to do with the compiler. I'm using Xcode 5.0.2, so I have the option to change the compiler (I think).

Then I'm getting another compile error on the line:

std::unordered_map<const std::string*, size_t, decltype(h), decltype(eq)> m(v.size(), h, eq);

stating C++ requires a specifier for all declarations around the m(v.size(), h, eq) portion.

What compiler should I make sure Xcode is compiling with in order to get this code to work?

Update:

Is there a particular name for this auto = [ ](...) notation that I could google?

Community
  • 1
  • 1
Brett
  • 11,637
  • 34
  • 127
  • 213
  • Not sure, but doesn't [tag:xcode] imply [tag:clang]? – πάντα ῥεῖ Feb 03 '14 at 21:30
  • 1
    clang 3.1 or later; gcc 4.5 or later; see http://gcc.gnu.org/projects/cxx0x.html and http://clang.llvm.org/cxx_status.html – Brian Bi Feb 03 '14 at 21:30
  • @πάνταῥεῖ, It used to use GCC by default. – chris Feb 03 '14 at 21:41
  • @chris Thanks for clarifying. I'm not really familiar with Xcode, must be a misleaded personal association of mine ... – πάντα ῥεῖ Feb 03 '14 at 21:43
  • @πάνταῥεῖ, Funnily enough, I've never used it myself (probably because I've been secluded to Windows). I just remember seeing that as a point in a recent-ish release. – chris Feb 03 '14 at 21:44
  • Do you know what standard is taking into account? Try to force to C++11, to cover these `lambda` structures and `unordered_map`. – wesley.mesquita Feb 03 '14 at 21:51
  • 1
    @wesley.mesquita That did it. Interestingly, the option for `GNU11++` did not work. Only `C++11` Would have thought they would be the same. Put this in an answer, and I'll accept. Thanks! – Brett Feb 03 '14 at 21:55

1 Answers1

1

Do you know what standard is taking into account?

Try to force to C++11, to cover these lambda structures and unordered_map.

wesley.mesquita
  • 795
  • 5
  • 12