Monday, April 21, 2014

Three Worthwhile std::enable_if Blog Posts

As I continue my work on Effective Modern C++, I'm pleased to see that the pile of stuff I need to read or reread (or reread again), because it might be useful in the book, is getting smaller. Today I finished my second full draft of my chapter on rvalue references, move semantics, and perfect forwarding, and part of that process was reviewing some interesting blog posts that appeared at Flaming Dangerzone. All address std::enable_if, in one way or another. My first draft of the chapter discussed std::enable_if, but for the second draft, I was pleased to get rid of the material, because (1) it's hard to explain, (2) I think it's too advanced and specialized for the kind of book I want to produce, and (3) I think I found a better way to solve the problem I'd been using std::enable_if for. (To be more precise, I believe that a better way was suggested by one of the technical reviewers of the initial draft of that chapter.)

Book or no book, the blog posts were interesting in a "template metaprogramming makes my head hurt" kind of way, so if you like that kind of headache, would like to better understand std::enable_if and its applications, and have not seen these articles, I recommend them:

Remastered enable_if
To SFINAE or not to SFINAE
Beating overload resolution into submission

Scott

4 comments:

Unknown said...

Hello! Can you help me with one simple question? I've read clause 3 of N3797 working draft but I can't find definition of definition. Only some examples of definitions and definition of declaration.

Scott Meyers said...

@Dmitry Fucintv: "Definition" is defined in 3.1/2. All declarations are definitions, except for the exceptions noted.

Markus Werle said...

I volunteer for proof-reading!

Scott Meyers said...

@Markus: Thanks for the offer, but I already have my technical reviewers lined up.