C++Now 2017: Ben Deane & Jason Turner "constexpr ALL the things!"
Why Stack Overflow recommends it
Stack Overflow users link it when answering questions about constexpr techniques, compile-time parsing, and building constexpr data structures in C++14 and C++17.
Recommended by 3 people across 4 different months, 2017 to 2018.
What it is
A C++Now 2017 conference talk by Ben Deane and Jason Turner on what can be done at compile time with constexpr in C++17. It covers constexpr data structures and algorithms, mixing compile-time and runtime computation, and user-defined literals, with a compile-time JSON parser as a running example.
What people said
Strong rec Julius · 2018-08 · Stack Overflow · on “C++17 constexpr string parsing”
You may be interested in the experimental **`constexpr` JSON parser** by Ben Deane and Jason Turner. Their experiments are titled *constexpr all the things*. There have been talks at C++Now 2017 [LINK] ( [this video] ) and CppCon 2017 [LINK] ( [LINK] ). The source code is on GitHub [LINK] , but I recommend watching the talk.
Recommends johannes · 2017-08 · Stack Overflow · on “How to parse text for a DSL at compile time?”
Related: [this video] an 90 minute talk on parsing JSON at compile time using constexpr functions and matching data structures. Requires some C++17 I think (at least C++14) and some will to do. Parsing simple expressions should be simpler, but video might be worthwhile nonetheless.
Recommends Julius · 2017-10 · Stack Overflow · on “How to create a constexpr list?”
Or have a look at this constexpr JSON parser [LINK] . Recorded presentations are available on Youtube from C++Now 2017 [this video] and (more recently) CppCon 2017 [LINK] .
Recommends wimalopaan · 2017-11 · Stack Overflow · on “Transform constexpr expressions into template non-type parameter”
Just found it: it is in the [this video] Version of the talk at the very end at time 1:34:45. That is awesome ....
Cites Vorac · 2017-06 · Stack Overflow · on “How to prevent accidental emission of constexpr functions”
Ben Deane mentions the throw trick [this video] , which ensures a link error when a constexpr function is used in a non-constexpr context. Here is my take: #include <iostream> struct Exc; constexpr int foo( int a ) { if( a == 42 ) { throw Exc{}; } return 666; } int main() { constexpr auto ret = foo(43); std::cout << ret << "\n"; return ret; } But I couldn't make it work (clang++ 3.8.1-23 and g++ 6.3.0): $ clang++ -std=c++14 main.cpp main.cpp:9:15: error: invalid use of incomplete type 'ExcBase' throw ExcBase{}; ^~~~~~~~~ main.cpp:3:8: note: forward declaration of 'ExcBase' struct ExcBase; ^ 1 error generated. A comment in this thread [LINK] suggests another trick: #include <iostream> constexpr in
Cites Julius · 2017-11 · Stack Overflow · on “Transform constexpr expressions into template non-type parameter”
In C++17 you can pass a constexpr lambda returning your argument: constexpr auto t2 = transform([&] { return t1; }); Inside the function you can "call" the lambda and assign to a constexpr : template<class Tuple_> constexpr auto transform(Tuple_ tuple_) { constexpr auto tuple = tuple_(); // ... Some research (thanks @wimalopaan) shows that this idiom has been described in an audience comment to a talk at C++Now 2017 [this video] by an anonymous commenter (referring to "some discussion on slack") in a blog post [LINK] by Michael Park [LINK] #include <cstdint> #include <iostream> #include <tuple> // not sure how robust this macro is... #define CONSTEXPR_ARG(arg) [&] { return arg; } template<auto N>