CppCon 2018: Vincent Reverdy “Custom Overload Sets and Inline SFINAE for Truly Generic Interfaces”

Опубликовано: 27 Декабрь 2024
на канале: CppCon
2,273
24

http://CppCon.org
Vincent Reverdy “From Metaprogramming Tricks to Elegance: Custom Overload Sets and Inline SFINAE for Truly Generic Interfaces”

Presentation Slides, PDFs, Source Code and other presenter materials are available at: https://github.com/CppCon/CppCon2018

Wouldn't it be nice to be able to tell the compiler "pick the first piece of code in this list which compiles", "pick the first type which has these properties" or simply be able to ask "does this code compile?". In this talk we will build a set of tools to make this happen using some of the new C++17 features.

SFINAE (Substitution Failure Is Not An Error) has been used for years to do this and to help the writing of generic code. It often required to play with a lot of templates to force the compiler to choose the right overload or specialization, often leading to a lot of boilerplate code. The upcoming concepts, already usable in some compilers as an experimental feature, will simplify a lot of these use cases. However, sometimes, it would be very nice to be able to write "inline" SFINAE directly in application code without having to worry too much with templates. This talk is intended to both metaprogrammers (to write these tools) and developers who want to write very generic code (to use these tools) using C++17.

In this talk, we will build these tools step by step, layer by layer. This will allow to see how some C++17 features like void_t, template deduction guides, invoke and constexpr if can be used. First we will design some additional type traits to play with qualifiers and to retrieve information about callable types. Second, we will design classes to be able to create custom overload sets or overload sequences from functions with different names. Then on the top of it, we will use metaprogramming techniques to design tools to let the user ask questions to the compiler or to pick the first code that compiles from a list. Finally, we will explore some of the very nice applications of these tools, allowing to make interfaces even more generic than before with an elegant and simple syntax.

Vincent Reverdy, University of Illinois at Urbana-Champaign
Astrophysicist

Vincent has been working as a post-doctoral researcher at the University of Illinois at Urbana-Champaign (USA) since he obtained his PhD at the Paris observatory (France) in november 2014. His main scientific interests are related to cosmology and general relativity. He his particularly interested in the study of relativistic effects at cosmological scales using high performance simulations run on supercomputers. Because these simulations rely on tree data structures, he started investigating ways to optimize them. He now leads a research team working on tree data structures with main applications in simulations, machine learning, and data science. He also participates into the C++ standardization process and regularly submits proposals to improve the C++ language.

Videos Filmed & Edited by Bash Films: http://www.BashFilms.com

*-----*
*--*
*-----*