|
Boost : |
From: Yitzhak Sapir (yitzhaks_at_[hidden])
Date: 2002-10-09 06:43:31
On Tue, 8 Oct 2002, Aleksey Gurtovoy wrote:
> > Also why does list_c allow specifying a type but defaults all
> > parameters to long?
> > Couldn't list_c<class T, T c1, T c2, etc.> have been used? (Like in
> > integral_c?)
>
> Nope, because due to its variadic interface 'list_c<T,...>' needs to reserve
> some single value for denoting unused arguments, and taking that value out
> of range of possible values of type 'T' is not really a feasible option
> (consider, for instance, T == bool).
This seems to work on VC:
template <class T> struct LargerThan
{
typedef long type;
enum { illegal_value = 0xBADBAD };
};
template <> struct LargerThan<bool>
{
typedef char type;
enum { illegal_value = -1 };
};
// For pointers, illegal value is 0 (or perhaps, 1)
template <class T, LargerThan<T>::type c1 = LargerThan<T>::illegal_value>
struct list_c
{
...
};
> > And for the pair optimization, I need a "is_pair". That
> > would have been nice to have in type traits.
> >
>
> template< typename T >
> struct is_pair
> : mpl::logical_and<
> has_first<T>
> , has_second<T>
> >
> {
> };
>
> ;)
What do I include for has_first/has_second? I couldn't find anything like
it in the type_traits documentation. Also, if we have an has_first and
has_second, wouldn't it be more complete to have is_pair?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk