The ultimate SFINAE

Our goal now is to make a reusable framework that we could use to test any expression for validity, without creating a syntax error if our expression is not valid. Just as in the previous section, we don't want to actually specify how the expression is evaluated, whether by a specific function, or using conversions, or in some other way. We just want to precompile the expression we are about to use in the body of the function, to make sure that the real compilation will not fail, or to instantiate some other template function if it does fail. We need a general is_valid feature that we can apply to any expression.

To accomplish this goal, we need to use all the template programming tricks we have studied so far, including ...

Get Hands-On Design Patterns with C++ now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.