Live data from Hacker News

C++20 Concepts: The Definitive Guide

thecodepad.com

1–10 of 102 posts

Re: C++20 Concepts: The Definitive Guide

#2
Is it just me, or have C++ errors gotten a lot better? Below example from guide seems a lot more ergonomic than in years past.

  test.cpp: In instantiation of ‘T add(T, T) [with T = std::basic_string]’:
  test.cpp:17:21:   required from here
  test.cpp:11:22: error: static assertion failed
   11 |   static_assert(std::is_integral_v);
      |                 ~~~~~^~~~~~~~~~~~~~~~
  test.cpp:11:22: note: ‘std::is_integral_v >’ evaluates to false
Build finished with error(s).

Re: C++20 Concepts: The Definitive Guide

#3
post #2

Is it just me, or have C++ errors gotten a lot better? Below example from guide seems a lot more ergonomic than in years past. test.cpp: In instantiation of ‘T add(T, T) [with T = std::basic_string ]’: test.cpp:17:21: required from here test.cpp:11:22: error: static assertion failed 11 | static_assert(std::is_integral_v ); | ~~~~~^~~~~~~~~~~~~~~~ test.cpp:11:22: note: ‘std::is_integral_v >’ evaluates to false Build f…

It's not just you, dinostics continuously and noticably improve. A lot of effort is spent on this.

Re: C++20 Concepts: The Definitive Guide

#4
post #2

Is it just me, or have C++ errors gotten a lot better? Below example from guide seems a lot more ergonomic than in years past. test.cpp: In instantiation of ‘T add(T, T) [with T = std::basic_string ]’: test.cpp:17:21: required from here test.cpp:11:22: error: static assertion failed 11 | static_assert(std::is_integral_v ); | ~~~~~^~~~~~~~~~~~~~~~ test.cpp:11:22: note: ‘std::is_integral_v >’ evaluates to false Build f…

There has been more interest from modern programming languages and modern compiler developers in good diagnostics in two ways: 1. The earlier you report the problem, the cheaper the fix and 2. The better the diagnostic the more likely the programmer's fix is appropriate to the actual problem they had.

I agree this is great news. I actually had to write MS SQL for the first time last week and it was disappointing but sadly expected to have it respond to a common but not technically-standard SQL syntax I'm used to with "Syntax error" as though somehow that's helpful. Such poor errors meant I spent more time reading the documentation than writing queries even though I've years of experience across several other SQL dialects.

Re: C++20 Concepts: The Definitive Guide

#5
post #2

Is it just me, or have C++ errors gotten a lot better? Below example from guide seems a lot more ergonomic than in years past. test.cpp: In instantiation of ‘T add(T, T) [with T = std::basic_string ]’: test.cpp:17:21: required from here test.cpp:11:22: error: static assertion failed 11 | static_assert(std::is_integral_v ); | ~~~~~^~~~~~~~~~~~~~~~ test.cpp:11:22: note: ‘std::is_integral_v >’ evaluates to false Build f…

One of the major motivations for concepts is to allow better error messages.

Re: C++20 Concepts: The Definitive Guide

#6
post #2

Is it just me, or have C++ errors gotten a lot better? Below example from guide seems a lot more ergonomic than in years past. test.cpp: In instantiation of ‘T add(T, T) [with T = std::basic_string ]’: test.cpp:17:21: required from here test.cpp:11:22: error: static assertion failed 11 | static_assert(std::is_integral_v ); | ~~~~~^~~~~~~~~~~~~~~~ test.cpp:11:22: note: ‘std::is_integral_v >’ evaluates to false Build f…

Yeah, and besides the focus on error messages in past years, concepts will naturally allow template errors to be a _lot_ clearer, since they can serve as the specification of templated type requirements.

Re: C++20 Concepts: The Definitive Guide

#7
I guess this is somewhat besides the point but checking if something can be multiplied by -1 is not great as a definition of subtraction. You'll typically want to use the additive inverse directly.

I mean sure you can extend any commutative group into a module over the integers but you probably don't want to make this a hard requirement just to have subtraction.

Re: C++20 Concepts: The Definitive Guide

#9
post #2

Is it just me, or have C++ errors gotten a lot better? Below example from guide seems a lot more ergonomic than in years past. test.cpp: In instantiation of ‘T add(T, T) [with T = std::basic_string ]’: test.cpp:17:21: required from here test.cpp:11:22: error: static assertion failed 11 | static_assert(std::is_integral_v ); | ~~~~~^~~~~~~~~~~~~~~~ test.cpp:11:22: note: ‘std::is_integral_v >’ evaluates to false Build f…

One of the major motivations for concepts is to allow better error messages.

And ironically it’s questionable if it helps. Worse error messages were one of the main reasons it got blocked from 17.

Re: C++20 Concepts: The Definitive Guide

#10
post #2

Is it just me, or have C++ errors gotten a lot better? Below example from guide seems a lot more ergonomic than in years past. test.cpp: In instantiation of ‘T add(T, T) [with T = std::basic_string ]’: test.cpp:17:21: required from here test.cpp:11:22: error: static assertion failed 11 | static_assert(std::is_integral_v ); | ~~~~~^~~~~~~~~~~~~~~~ test.cpp:11:22: note: ‘std::is_integral_v >’ evaluates to false Build f…

One of clang’s stated goals is “expressive diagnostics”

See https://clang.llvm.org/diagnostics.html ; that page is not dated, but compares to gcc 4.9, which is from April 22, 2014.

gcc also has worked on improving its error messages (most likely because of competition with clang), so that comparison probably isn’t accurate anymore.

Post reply on HN