Рет қаралды 3,672
In this video we get comfortable with an advanced C++ topic: SFINAE
SFINAE stands for Substitution Failure Is Not An Error. It is a C++ template metaprogramming technique that allows us to choose between implementations depending on the "characteristics" of a type.
In other words it's not about what a type is, but what it can do.
It's a very powerful technique that allows us to write generic code that can be used with different types, and it's used extensively in the standard library.
I am planning to write a blog post about it so that you can have the code in a more usable format.
I will do this once I reach 1000 subscribers, so if you liked the video and would like to get hold of the code, please subscribe and share the video with your friends. 🎉
2024 Update: 1000 Subscribers reached!
Here's the tutorial in a written form: platis.solutions/blog/2024/01...
00:00 Introduction, disclaimers and prerequisites
02:31 SFINAE: What and why?
05:54 SFINAE alternatives
09:43 Basic SFINAE without std::enable_if
16:26 std::enable_if
19:31 SFINAE with std::enable_if
23:09 Creating traits
26:30 std::void_t
28:55 Introspection with declval
30:36 SFINAE on class member functions
32:15 Disabling or enabling functions with SFINAE
34:06 SFINAE and fold expressions
34:42 Conclusion and takeaways