Boost logo

Boost Users :

Subject: [Boost-users] Problem using enable_if with gcc 3.4.4
From: gao_bolin_at_[hidden]
Date: 2009-12-03 15:47:51


Hi,

I am having some trouble using enable_if with gcc 3.4.4 (code below). Basically it is working as expected with functions ("bar"), but using it on member functions of a class ("Foo"), I am getting the error that this member function cannot be overloaded.

Visual 2008 and gcc4 seem to be ok with it though.

Any explanation and work around appreciated.

B.

--
#include <iostream>
#include <boost/type_traits.hpp>
#include <boost/utility/enable_if.hpp>
// This won't compile with gcc 3.4.4
class Foo
{
public:
  template < typename T >
  typename boost::enable_if<boost::is_same<T, int>, T>::type
  bar(int x)
  {
    std::cout << "A" << std::endl;
    return x;
  }
  template < typename T >
  typename boost::disable_if<boost::is_same<T, int>, T>::type
  bar(int x)
  {
    std::cout << "B" << std::endl;
    return x;
  }
};
// this would.
template < typename T >
typename boost::enable_if<boost::is_same<T, int>, T>::type
bar(int x)
{
  std::cout << "A" << std::endl;
  return x;
}
template < typename T >
typename boost::disable_if<boost::is_same<T, int>, T>::type
bar(int x)
{
  std::cout << "B" << std::endl;
  return x;
}
int main()
{
  bar<int>(1);
  bar<double>(1);
  Foo f;
  f.bar<int>(1);
  f.bar<double>(1);
  return 0;
}
____________________________________________________
Michael Jackson, Susan Boyle, Black Eyed Peas ... Retrouvez leurs derniers titres sur http://musiline.voila.fr

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