Boost logo

Boost Users :

From: Sharon Galtzur (sharon.galtzur_at_[hidden])
Date: 2005-02-14 08:43:48


John Maddock wrote:
>> 1. How (or rather Why) does is_class works.
>
>
> There are two key concepts:
>
> 1) A class type is the only kind of type that can have a member function.
> 2) When the compiler performs template argument substition to a function
> signature, if the signature is an invalid type then the signature is
> ignored without a compiler error (sometimes called Substitution Failure
> Is Not An Error or SFINAE).
>
> So given the overloads:
>
> template <class T>
> void f(int (T::*)(int)); / #1
> template <class T>
> void f(...); // #2
>
> The expression:
>
> f<T>(0);
>
> Will call #1 if T is a class type, or #2 otherwise.
>
>> 2. Same for is_enum
>
>
> An enum type is the only type that has a built-in implicit conversion to
> int, but is not itself an integer type. Combine that with the fact that
> only one user-defined conversion may be performed per conversion
> sequence, and you have the implementation.
>
> John.

Thanks for the reply. The thing i dont understand is this :
template <class T> void f(int (T::*)(int)) will match any member
function with specific signature (receiving int and returning int). But
not all classes have such function. So in this case how will a class F {
} be matched ?

The only function that always exist for all classes with the same
signature is a destructor ( with void (void) signature ?) - is this the
function that is used ?

Thanks

Sharon


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net