Boost logo

Boost Users :

From: Howard Hinnant (yg-boost-users_at_[hidden])
Date: 2003-06-21 09:08:37


In article <3fc901c337d4$5821a420$8d6c6f50_at_pc>, Terje Slettebř
<tslettebo_at_[hidden]> wrote:

| Granted, this doesn't appear use SFINAE, though, so maybe leave it out.

Your conversion operator example worked fine for me. test<int>
converted to double, but not to std::string.

| On
| the other hand, does constructors? I get the same kind of error message for
| both constructors and conversion operators, on both Intel C++ and g++:
|
| template<class T>
| class test
| {
| public:
| test(const T &,
| typename enable_if<
| is_arithmetic<T>::value,
| T
| >::type * = 0) {}
| };
|
| test a(1); // Ok
|
| test b(0 (int *) 0); // error: class "enable_if<false, int *>" has no member
| "type"

Maybe you meant:

class test
{
public:
   template<class T>
   test(const T &,
      typename enable_if<is_arithmetic<T>::value>::type* = 0) {}
};

int main ()
{
   test a(1);
   test b((int*)0);
}

And yes, test b is an error. If you want to make test b not an error,
then you must add a ctor to accept it:

   test(int*) {}

-- 
Howard Hinnant
Metrowerks

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