Boost logo

Boost :

From: William Kempf (sirwillard_at_[hidden])
Date: 2000-11-17 18:07:52


--- In boost_at_[hidden], Jesse Jones <jejones_at_a...> wrote:
> >On Fri, 17 Nov 2000 20:54:33 -0000
> >"William Kempf" <sirwillard_at_m...> 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...

Check out the threads on simulating partial specialization. This
particular issue was even coded for using VC++ for a bind() function
by Dave Abrahams, I believe. The general idea is to use full
specialization instead of partial specialization and to just
eliminate the return all together for void return types (as opposed
to trying to cast them). After all, VC++ won't work with this code:

void func()
{
}

template <typename T>
void bar(T* p)
{
   return func();
}

Bill Kempf


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