Boost logo

Boost :

From: Giovanni Bajo (giovannibajo_at_[hidden])
Date: 2002-05-11 05:34:45


----- Original Message -----
From: "Dirk Gerrits" <dirkg_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Saturday, May 11, 2002 12:08 PM
Subject: [boost] Overloading a function taking a boost::function

> So I was wondering if Boost contains a function like this? Or if you know
> of different methods to accomplish this task. (I haven't been able to come
> up with any so far. :(

There are methods that work for normal functions but will fail on any other
type of "functors". For example, you can use partial template specializion:

template <typename FUNC>
struct ArietyTrait;

template <typename R>
struct ArietyTrait<R (*)(void)>
{
  // ....
};

template <typename R, typename P1>
struct ArietyTrait<R (*)(P1)>
{
  // ....
};

template <typename R, typename P1, typename P2>
struct ArietyTrait<R (*)(P1, P2)>
{
  // ....
};

With this trait, you can match functions with 0, 1, 2, etc parameters.

Giovanni Bajo


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk