Boost logo

Boost Users :

From: Bryan Silverthorn (yg-boost-users_at_[hidden])
Date: 2003-03-20 13:50:07


Hi,

I haven't found any discussion of this issue; it's possible I've just
missed it. Anyway, the short form is that I'm trying to partially
specialize a class for tuple types. I specialize for cons<H, T>, but
specialization requires an exact type match, so tuple<...> will fail to
match cons<...> and instead fall to the base template<class T>
case--which has the wrong behavior.
If I assume that the passed type is a tuple, I can use inheritance
trickery and inherit from the tuple<...>::inherited case to match the
correct case. Of course, this assumes that the template type is a tuple,
when I can't make that assumption--I'm using specialization precisely
because the type isn't known.
I could specialize on tuple<T0...T9>, but that sets another arbitrary
max tuple size; it would be nice to be able to match all tuples allowed
by the boost::tuple implementation.
So: I need a way to determine if a particular type is a tuple type,
which would allow me to do the following:

template<bool B, class T>
class FooIf {};
template<class T>
class Foo : public FooIf<is_tuple_type<T>, T> {};
template<class T>
class FooIf<true, T> { /* tuple implementation */ };
template<class T>
class FooIf<false, T> { /* non-tuple implementation */ };

AFAICT, there's no way to do so at present. I'd like to suggest a way to
  add this functionality: have cons<> (or tuple<>) inherit from a blank
"tuple_base" class. This would let us use boost::is_base_and_derived to
provide the is_tuple_type functionality for the code block above.

Of course, it's possible I'm just missing a simple way to partially
specialize for tuple types, or that such functionality is bad and
unecessary. Thoughts?

  ----
Bryan Silverthorn :: bcs26_at_[hidden]


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