Loading…
CppCon 2018 has ended
View analytic
Thursday, September 27 • 14:00 - 15:00
From Metaprogramming Tricks to Elegance: Custom Overload Sets and Inline SFINAE for Truly Generic Interfaces

Sign up or log in to save this to your schedule and see who's attending!

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.

Speakers
avatar for Vincent Reverdy

Vincent Reverdy

Astrophysicist, University of Illinois at Urbana-Champaign
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... Read More →


Thursday September 27, 2018 14:00 - 15:00
Copper Mountain Theater (2nd Floor)

Attendees (177)