Boost logo

Boost Users :

From: Pedro Lamarão (pedro.lamarao_at_[hidden])
Date: 2007-01-15 09:20:54


Mark Ruzon escreveu:
> I have a function that performs the same task on several data types and
> data combinations:
>
> template <typename T>
> int f(const type1<T>& x);
>
> template <typename T>
> int f(const type2<T>& x);
>
> template <typename T>
> int f(const type2<T>& x, const type2<T>& y);
>
> I want to create a function object out of the second function. However,
> bind(f, _1) is ambiguous. Is there a way to disambiguate this using a
> bind call, or do I have to create my own function object?

To take the address of an overloaded function you need to use
static_cast to select the correct overload.

The following program will compile.

template <typename T> struct type1 { };
template <typename T> struct type2 { };

template <typename T>
int f(const type1<T>& x) { return 0; }

template <typename T>
int f(const type2<T>& x) { return 0; }

template <typename T>
int f(const type2<T>& x, const type2<T>& y) { return 0; }

int
main (int argc, char* argv[]) {
     int (*ptr)(const type1<int>&) =
         static_cast<int (*)(const type1<int>&)>(&f);
     return ptr(type1<int>());
}

--
  Pedro Lamarão

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