News for hackers. Stuff that matters.
Re:Popular Myths about C++, Part 1 by StephanTLavavej on Wednesday December 10, 2014 @01:52AM (#8728003)
C++14's "meow"s is syntactic sugar for string("meow"), with identical efficiency.
Re:Popular Myths about C++, Part 1 by mike-cardwell on Wednesday December 10, 2014 @04:08AM (#8728346)
If that's the case, then when I do:

  auto str = "something";
Why is "str" a "const char " rather than a std::string? Tested using "-std=c++14" with both gcc version 4.9.1, clang 3.5.0 and with both libstdc++ and libc++ ?

[edit] If you're the guy who does the MSDN videos on C++, thank you*. They've been incredibly useful to me.

Re:Popular Myths about C++, Part 1 by StephanTLavavej on Sunday December 21, 2014 @04:03PM (#8780943)
Sorry, wasn't checking my HN comments frequently (unlike Reddit there's no little red icon).

"meow" is a traditional string literal, whose type is const char [5] (array of 5 const chars). When you say "auto", you get the same deduction as when you pass something to a template foo(T t) taking by value. This triggers "decay", where arrays decay to pointers. Hence auto (and T) is const char *.

"meow"s is a user-defined literal (the Standard Library is a user as far as the compiler is concerned), for which you must include <string> and say "using namespace std::string_literals;" or something equivalent. The specification for UDLs says that this calls operator""s() which returns a std::string by value.

Yep, I'm the video guy. Glad you like them!