Skip to content
0:00 / 0:00

#constexpr#metaprogramming#templates

CppCon 2019: David Stone - Removing Metaprogramming From C++, Part 1 of N: constexpr Function Params

CppCon

189K subscribers • 103 videos on Hallway • Conference channel

YouTube

Advanced. Deep dive for people who know the field.

15K views7 years ago2 recommendations

Programming languagesC++Language design and type systems

David Stone proposes adding constexpr function parameters to C++ to merge compile-time and run-time programming and simplify code.

CppCon.org — Discussion & Comments: reddit.com/r/cpp/ — Presentation Slides, PDFs, Source Code and other presenter materials are available at: github.com/CppCon/CppCon2019 — C++ has, buried within it, no less than four "general-purpose" programming languages. We have regular run-time C++, constexpr, templates, and macros. This presentation will cover a new proposal for C++: constexpr Function Parameters. It aims to make C++ a much more powerful language by helping to merge constexpr programming into regular C++. This will allow writing code that is faster, is easier and more natural to use, is terser, and catches errors at compile time. This new language feature would provide a way to annotate a function parameter as constexpr, letting you do things like overload on whether something is a compile-time constant, or pass constants to things that cannot have template parameters (like constructors and operators). This presentation will focus on the principles used in the design of C++ and in this feature. From those principles, we will go into the details of the proposal. This presentation will briefly cover what constexpr is used for as of C++20 (the version of C++ that is being finalized now and will be officially 'released' in 2020). The proposal for constexpr function parameters is targeted at C++23 ('released' in 2023). The presentation will briefly cover the standardization process and timeline. Recommended background (none of these are necessary, but they are helpful): * No Shadow Worlds: probablydance.com/2015/02/16/ideas-for-a-programming-languag… * Inventing on Principle: vimeo.com/36579366 * constexpr: Introduction (as of C++11 and C++14) youtube.com/watch?v=fZjYCQ8dzTc The proposal paper can be found at github.com/davidstone/isocpp/blob/master/constexpr-parameter… — David Stone Uber Software Engineer Boulder, CO David Stone works on autonomous vehicles at Uber in Louisville, Colorado. He is a member of the C++ standardization committee, where he chairs the Modules Study Group (SG2) and is the vice chair of the Evolution Working Group. He has written an algorithm that solved the traveling salesman problem in constant time. He can square the circle and divide by zero. He can move his king into check. He once wrote an optimizing compiler that solved the halting problem, but doesn't need to use it because his code is already optimized.) — Videos Filmed & Edited by Bash Films: BashFilms.com Work at Hudson River Trading (HRT): tinyurl.com/safxfctf

Why it's here

2 people recommend this

What people say. Recommended by Zig developers as an interesting parallel to Zig's comptime parameters, showing how C++ is trying to solve similar metaprogramming problems.

u/marler8997in r/Zig • Recommends

Someone is trying to add Zig generics to C++ David Stone gave a talk where he discusses his proposal to add constexpr function parameters to C++, which is basically Zig comptime parameters: [video Coming from a D/C++ background, I was skeptical about Zig compile-time generics and if they could be as powerful as D/C++ templates. However, after writing a good amount of code with Zig I've found that Zig's approach makes the language simpler, more consistent and is just as powerful as templates. David's talk is a good summary of alot of the thoughts I had on the subject.

u/stuffsnoutin r/Zig • Recommends

Saw parallels in c++ talk on how comptime can replicate much of the metaprogramming found in c++

u/marler8997in r/Zig • Mentions

On “hey how different is Zig comptime from C++ constexpr/consteval?”

This is a cppcon talk that discusses a proposal to add constexpr function parameters to C++...which are pretty close/equivalent to Zig comp time parameters. It does a great job at explaining the difference between the two. link to this video

u/marler8997in r/Zig • Mentions

On “Zig-style generics are not well-suited for most languages”

I didn't have time to grok the whole article yet but I wanted to ask a question. A few years ago I saw a CppCon talk about an idea to add constexpr function parameters, which In believe is this video: link to this video When I watched it back then, it looked to me like these new constexpr function parameters behaved very similar to Zig generics, though, I can't remember all the details at the moment. Assuming you know of this talk or are willing to watch it, what's your take on that? In other words, would it be reasonable to say that this talk is about adding Zig-like generics to C++?