fenbf / cppstories-discussions

4 stars 1 forks source link

2016/02/notes-on-c-sfinae/ #114

Open utterances-bot opened 1 year ago

utterances-bot commented 1 year ago

Notes on C++ SFINAE, Modern C++ and C++20 Concepts - C++ Stories

What is SFINAE? Where can you use this metaprogramming technique? Are there any better alternatives in Modern C++? And how about Concepts from C++20? Read on to find out! Note: I’d like to thank KJ for reviewing this article and providing me with valuable feedback from the early stage of the writing process.

https://www.cppstories.com/2016/02/notes-on-c-sfinae/

thewhoo commented 1 year ago

I think there's a slight error in the Expression SFINAE section in the sentence after the code snippet:

template <class T> auto f(T t1, T t2) -> decltype(t1 + t2);

In the above case, the expression of t1+t2 needs to be checked. It will work for two int’s (the return type of the + operator is still int), but not for int and std::vector.

But the compiler would never attempt to instantiate this template for an int and a std::vector, as the arguments are of different type, right? So maybe change it to t1, t2 of type std::string?