CppCon 2018: Louis Dionne “Compile-time programming and reflection in C++20 and beyond”

preview_player
Показать описание


Compile-time programming and reflection have been getting a lot of attention recently. Indeed, from Herb Sutter's well-known Metaclasses proposal to the newly created Reflection TS, a lot of effort is being put into solving the general problem of programmatic code generation and program introspection. More recently, the C++ Standards Committee has also been evaluating and adopting proposals that vastly expand the realm of constructs available at compile-time, in constexpr functions: new-expressions, try-catch blocks, virtual functions, some standard containers, and more.

For most people, it is unclear how all these features, whether exploratory or voted into the Draft International Standard, relate together. Without being active in the Committee, it can be difficult to see the big picture, the unifying vision driving all these changes. Fortunately, there is one, and this is what this talk is about.

We will go over these features and explain how they might interact with each other by boiling them down to their essential parts. We will present how different use cases for compile-time programming will be solved in C++20, and how even more use cases can be unlocked in the future. Attendees will leave this talk with an understanding of the improvements to constexpr planned for C++20, of what's needed to unlock more advanced use cases and an unifying vision for how to get there.

Louis Dionne, Apple, C++ Standard Library Engineer
Louis is a math and computer science enthusiast who got swallowed by the C++ monster when he was a naive, unsuspecting student. He now works for Apple, where he is responsible for libc++, the Standard Library shipped with LLVM/Clang. He is a member of the C++ Standards Committee and of the Boost community, where he authored the Boost.Hana metaprogramming library.


*-----*
*-----*
Рекомендации по теме
Комментарии
Автор

He makes this seem soo understandable and easy that its surprising it wasnt in the language already. !

mrlithium
Автор

incredible talk. i love how things are lining up over the years. especially "for..." is news to me, but looks very powerful to get rid of tons of repetition in the code.

hansiraber
Автор

You're making an amazing talk here Louis, as always.

Scorbutics
Автор

Awesome presentation. The future looks promising! @Louis Dionne, it really like you love your job :)

robinmoussu
Автор

Incredibly exciting to see C++ start catching up with modern languages on compile time evaluation, reflection and hygienic macros. One day I'll have nothing to complain about any more! xD

oscarcampbell
Автор

I have full confidence Louis will get it right, I've been using hana and it's an absolute pleasure compared to type based TMP.

DreyriRS
Автор

"Please reserve questions to the end." Audience: "question question question question" chrissakes people learn to listen

ninepoints
Автор

Great question at 1:04:00. "Are constexpr expressions evaluated when a module is compiled or when the interface is imported by another module?" I was thinking this myself. My assumption is that it would be compiled into the module so it's included only once by that translation unit. However, expressions can be templatized and exposed to other modules. In those cases I would expect the expression to be evaluated at the point of use by that external module. Can anyone offer a concrete answer?

PROMuffy
Автор

hell yea, finally slowing down template hell, and staying with the core language. please continue with minimizing having to use template hellish language to achieve compilation time functionality. loved the constexpr!.

TaiDesHen
Автор

Thanks for the great talk. Not in the committee, not really optimistic... but guess will use it in C++27 somehow.

TheLavaBlock
Автор

Regarding your very last statement in the video, that standardizing something to emit warnings (call it logging) during compile time isn't something that the committee would be interested in, I think it should be. We already have static_assert which breaks compilation with a message in case a predicate is not true. Why not have something that is always output. I think we'll need it. Call it static_log or something. A constexpr iostream "static_cout" is probably too much, but a static_log which takes a level and a constexpr string as a parameter - why not?

mfkman
Автор

I worked alot with constexpr in the recent months and I can tell you we are far away from a perfect implementation. I can count atleast 4 breaking compiler bugs I encountered in msvc, the most recent one was that he believed that I left a for loop which I didnt. Clang was better but the error messages were horrific if there were any at all.
Well it is fun because it is new but actually implementing whole containers seems such a monumental task at the moment, that I'm not too optimistic about the near future.

tilmanrotationalinvariant
Автор

39:20, that's exactly what I've been waiting for.

nites
Автор

So basically, the standards committee saw the compile-time execution available in D and Jai, and thought, "hey! We can make a worse version of that!"

notnullnotvoid
Автор

A constexpr unordered_set or unordered_map could actually use a perfect hash function. :-)

Omnifarious
Автор

As already mentioned by Louis Dionne, I see a lot of potential in serialization and pre-compiling data. When starting with game programming it was a chore to implement all the binary serialization for transmitting objects over the network. I know there are things like protobuff, but just letting your data class inherit from a "BinarySerializable" interface with meta-class code behind it, that generates the functions for you, would be REALLY nice. And we could get rid of the Macro hacking in engines like Unreal (which was actually the point that drove me away from it).

Another question: Could we constexpr std::fstream? :-p
Then I could read files at compile-time and generate new code from it. In a way utilizing the compile-time abilities of C++ to make a compiler itself. E.g. Reading a JSON file and generating classes from it.

OperationDarkside
Автор

I hear a bunch of talk about constexpr, but I don't hear that much about why this is a good thing. A couple of real life use cases might be a good idea if you want to sell this.

origamibulldoser
Автор

Considering compiler and the code it generates may be running in different environment, if we are calling `new int[N]`, how does compiler know the target machine has enough memory to allocate the storage for it?

echosystemd
Автор

1:02:20 is a good question, would be more work for library implementers but a valid and more minimal implementation

porkybrain
Автор

why was `constexpr` ever defined to mean "maybe constexpr"?

gideonmuller