Boost logo

Boost :

From: Jesse Jones (jejones_at_[hidden])
Date: 2000-11-17 18:04:50


>On Fri, 17 Nov 2000 20:54:33 -0000
>"William Kempf" <sirwillard_at_[hidden]> wrote:
>
>> --- In boost_at_[hidden], Douglas Gregor <gregod_at_r...> wrote:
>> > On Fri, 17 Nov 2000 19:40:05 -0000
>> > 1) I use one "Callback" class that takes any number of parameters
>> > instead of having many Callback0, Callback1, ..., CallbackN
>> > classes.
>>
>> In theory I really like this. Unfortunately, it requires partial
>> template specialization and so may hinder or prevent implementation
>> on VC++, which I think is a major problem. It's definately an idea
>> worth looking into, however.
>
>I believe that we need partial specialization in any case. Even if we use
>Callback0, Callback1, etc. classes, we still (might) need a void (partial)
>specialization. e.g.,
>
>template<typename Arg1, typename Arg2>
>struct Callback2<void, Arg1, Arg2> { ... };

I tried to use something like the following:

// force a compile error if the function returns an incompatible type
template <typename RETURN_TYPE>
struct ReturnValue {
   template <typename T>
   RETURN_TYPE Cast(T value) {return value;}
};

// for void callbacks we'll eat the return value
template <>
struct ReturnValue<void> {
   template <typename T>
   void Cast(T) {}
};

virtual R Call() const {return ReturnValue<R>().Cast(mFunctor());}

but I couldn't get it to work with CW 5.3. Perhaps it will work with MSVC...

  -- Jesse


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