Substitution failure is not an error: Difference between revisions

Content deleted Content added
Alendit (talk | contribs)
Example: Changed call argument from 0 to nullptr as it is a pointer.
Tags: Mobile edit Mobile web edit
Erdavila (talk | contribs)
Example: Fixing consitency
Line 45:
static no& test(...);
 
// If the "sizeof" of the result of calling test<T>(0nullptr) would be equal to sizeof(yes),
// the first overload worked and T has a nested type named foobar.
static const bool value = sizeof(test<T>(nullptr)) == sizeof(yes);
Line 61:
</source>
 
When <code>T</code> has the nested type <code>foobar</code> defined, the instantiation of the first <code>test</code> works and 0 is successfully passed as the null pointer constant is successfully passed. (And the resulting type of the expression is <code>yes</code>.) If it does not work, the only available function is the second <code>test</code>, and the resulting type of the expression is <code>no</code>. (An ellipsis is used not only because it will accept any argument, but also because its conversion rank is lowest, so a call to the first function will be preferred if it is possible; this removes ambiguity.)
 
The developers of [[Boost C++ Libraries|Boost]] used SFINAE in boost::enable_if<ref name="enable_if">[http://www.boost.org/doc/libs/release/libs/utility/enable_if.html Boost Enable If]</ref> and in other ways.