C++ Truths
cpptruths.blogspot.com · Personal blog · on HN since 2012
Technical blog on C++ covering lambdas, templates, metaprogramming, constexpr, and type system features like variant and variance.
What HN saysHN commenters praise its C++14 lambda series and cite it for constexpr and the Turing-completeness of templates.
17HN people shared it
9linked it in comments
11stories submitted
54story points
8 years agolast shared
2012people per year2026
Most-shared posts
- 1Inheritance vs. std::variant in C++2 people · 2 points · first shared 2018 · discussion on HN
- 2Covariance and Contravariance in C++ Standard Library1 people · 36 points · first shared 2015 · 4 comments on HN
- 3Fun with Lambdas: C++14 Style1 people · 4 points · first shared 2016 · 1 comments on HN
- 4Fun with Lambdas: C++14 Style (part 2)1 people · 3 points · first shared 2014 · discussion on HN
- 5Using The Pigeonhole Principle in C++ Metaprogramming1 people · 2 points · first shared 2014 · discussion on HN
- 6Dependently-typed Curried printf1 people · 2 points · first shared 2016 · discussion on HN
- 7Fun with Lambdas: C++14 Style (Part 4)1 people · 2 points · first shared 2015 · discussion on HN
- 8Functional programming first principles in C++141 people · 1 points · first shared 2014 · discussion on HN
- 9Unit Testing C++ Templates and Mock Injection Using Traits1 people · 1 points · first shared 2019 · discussion on HN
- 10C++ Truths: Fun with Lambdas: C++14 Style (part 3)1 people · 1 points · first shared 2014 · discussion on HN
- 11Rvalue references in constructor when1 people · first shared 2012
- 12Creating recursive lambdas and1 people · first shared 2014
- 13C templates are turing complete1 people · first shared 2012
- 14Want speed use constexpr meta1 people · first shared 2013
- 15Why we need compile time reflection in1 people · first shared 2014
What HN people wrote when they linked it
hellofunk · 2016-03-30
Part 2 is also great:
http://cpptruths.blogspot.nl/2014/05/fun-with-lambdas-c14-style-part-2…
kruhft · 2013-05-17
This is my first exposure to constexpr and it looks very interesting. According to this article it's a second C++ metaprogramming language: http://cpptruths.blogspot.ca/2011/07/want-speed-use-constexpr-meta.htm…
The more I learn about C++11 the more I like it. There's some really amazing new features that I've only seen in Lisps, plus there's full static typing, which is the one thing I miss from Lisps.
pyrois · 2014-10-02
It's very heartening to see Microsoft and Intel actually adopting the new C++ standards given the fiasco that compiler support for C and C++ standards has been in the past.
That said, I sort of worry about the new approach to C++ standards. It was nearly a decade between C++03 and C++11 (duh) and C++03 was a very minor set of changes compared to C++98. Now we are planning to have major changes every six years, with a minor release in between? That's a new standard every three years. It seems hard to imagine how the compiler developers are going to keep up with that, much less our libraries.
Considering the C++ world is already very fragmented in terms of style and features used (C with Classes, Modern C++, horrible in-between?), I don't know if C++17 is going to be good for the ecosystem. I mean, people are talking about adding everything from monads[0] to compile-time reflection[1].
If the designers were willing or able to remove features (do we really need two different initialization syntaxes?) then I would be less concerned, but intentionally breaking every existing C++ library would probably do more harm than good.
Overall, I'm just not sure that this aggressive schedule of adding new features to a large language is a great idea.
[0] http://bartoszmilewski.com/2014/02/26/c17-i-see-a-monad-in-your-future…
[1] http://cpptruths.blogspot.com/2014/03/why-we-need-compile-time-reflect…
pjc50 · 2016-05-17
C++ templates are also turing complete, executed at compile time, and can result in extremely high compile times: http://cpptruths.blogspot.co.uk/2005/11/c-templates-are-turing-complet…
I don't think that failure to terminate compiles is too big a problem in practice; treat it as just another form of compile-time error and fix your program.
amelius · 2014-11-14
Here is a personal anecdote.
I recently tried to make a lambda function in C++ call itself.
My first approach didn't work, because the variables were captured by reference, causing my program to crash (the enclosing scope had disappeared when my recursive lambda function was called). I easily tracked down that problem. But this generated a second problem: without using "capturing by reference", I couldn't make the lambda function refer to itself!
Of course, I looked around on the internet, and I found [1], which actually shows the insane amount of hacking required to make a lambda function call itself. And in the end, this solution didn't even work for me.
So, concluding, I think we're a long way from "functional programming in C++".
[1] http://cpptruths.blogspot.nl/2013/10/creating-recursive-lambdas-and.ht…
octo_t · 2014-06-24
This exist: -Weffc++
http://cpptruths.blogspot.co.uk/2006/08/g-compiler-option-weffc.html
zem · 2012-11-28
wow, did not know about -Weffc++. quite impressive that they added that flag. here's a blog post if anyone else wants to read about it:
http://cpptruths.blogspot.com/2006/08/g-compiler-option-weffc.html
vinayan3 · 2012-05-08
I agree. It depends on what subset of C and C++ is used. If macros are used the only way to actually verify the code will be to pre-process it. Worse is if templates are used. Some templates don't even finish compiling.
http://cpptruths.blogspot.com/2005/11/c-templates-are-turing-complete.…
Most likely no one will write such a template in a mission critical system. However, from a formal verification standpoint the only way to verify the code is to check the binaries.
Tatyanazaxarova · 2012-03-14