Substitution failure is not an error: Difference between revisions

Content deleted Content added
Example: ed: reworded "if...sizeof...calling...is equal" -> "if...sizeof...calling...would be equal" for clarity
mNo edit summary
Line 12:
 
template <typename T>
void f(typename T::type) {} // definitionDefinition #1
 
template <typename T>
void f(T) {} // definitionDefinition #2
 
int main() {
f<Test>(10); // callCall #1 .
f<int>(10); // callCall #2. withoutWithout error thanks to SFINAE.
}
</source>
Line 34:
template <typename T>
struct has_typedef_type {
// Variables "yes" and "no" are guaranteed to have different sizes,
// specifically sizeof(yes) == 1 and sizeof(no) == 2.
typedef char yes[1];
typedef char no[2];
Line 45:
static no& test(...);
 
// ifIf the "sizeof" the result of calling test<T>(0) would be equal to the sizeof(yes),
// the first overload worked and T has a nested type named type.
static const bool value = sizeof(test<T>(0)) == sizeof(yes);