Live data from Hacker News

Popular Myths about C++, Part 1

isocpp.org

141–144 of 144 posts

Re: Popular Myths about C++, Part 1

#141
post #124
post #40

A major problem with C++ is a lack of consistency, which you run into if you start trying to generalize the ideas presented in this article. The article demonstrates string concatenation using +. That is great! Except it's inconsistent. The article's example works fine, of course: return name+'@'+domain; I'll skip over the weird use of '' instead of "". Now let's say I want to prepend mailto: as well: return "mailto:…

Not that this is necessarily any cleaner, but in C++14 one would write: return "mailto"s + ":"s + name + "@"s + domain; and it would compile fine. (s being a literal for std::string)

It's sad that it can't become the default for "" literals without breaking a ton of code, but I'm glad to see this change.

Re: Popular Myths about C++, Part 1

#142
post #133

Earlier quoted context omitted.

> return "mailto" + ":" + name+'@'+domain; Apparently, the first `+` is a problem, so just take it away: return "mailto" ":" + name+'@'+domain; // there, problem solved.

Of course. Now, do you want to sit down and explain why that's necessary to somebody who's still grappling with the concept of for loops?

That was supposed to be a sarcastic joke about yet another obscure C++ perk. I guess it wasn't very funny.

Re: Popular Myths about C++, Part 1

#143

Good luck trying to understand C++ without C. The numerous C++ traps and pitfalls will just look mad to you. BTW, 'multi-paradigm' is an oxymoron. Not even Scala uses that concept any more.

Scott Meyers says in Effective C++, view C++ as a confederation of languages: C, C++, the preprocessor and templates. When some people say that when you are learning C++ you should not be exposed to C, I really have to disagree.

I think he says "OO C++" and "STL", not "C++" and "preprocessor".

Re: Popular Myths about C++, Part 1

#144

Earlier quoted context omitted.

C++14's "meow"s is syntactic sugar for string("meow"), with identical efficiency.

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.

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 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!

Post reply on HN