|
Boost : |
From: Jaakko Jarvi (jajarvi_at_[hidden])
Date: 2002-04-05 16:53:06
Hi,
I've changed tuples a bit (not in CVS yet).
The elements used to be stored like this:
template <class HT, class TT>
struct cons {
typedef HT head_type;
head_type head;
tail etc.
With this scheme, tuples cannot have void element types, nor
nonreference function types. Obviously a tuple cannot hold a void
object or a nonreference function object, but it would be nice to
be able to manipulate the type of such object:
For example, it should be ok to write:
typedef tuple<void, int()()> t;
This can be done by changing the code to:
// a class that cannot have instances:
template <class T> class non_storeable_type {
non_storeable_type();
};
// if we have a plain function type or void, we use non_storeable_type
// otherwise this is an identity mapping
template <class T> struct wrap_non_storeable_type {
typedef typename IF<
boost::is_function<T>::value, non_storeable_type<T>, T
>::RET type;
};
template <> struct wrap_non_storeable_type<void> {
typedef non_storeable_type<void> type;
};
} // detail
template <class HT, class TT>
struct cons {
typedef HT head_type;
typedef typename
detail::wrap_non_storeable_type<head_type>::type stored_head_type;
stored_head_type head;
Now stored_head_type will be the same as head_type except for void and
plain function types. In those cases, no object of the tuple type can be
created anyway, so it does not make a difference.
Any objections?
In sum, there should be no effects on any existing code, only that the
tuple element types can now represent any valid C++ type.
Cheers, Jaakko
-- -- -- Jaakko Järvi email: jajarvi_at_[hidden] -- Post Doc Fellow phone: +1 (812) 855-3608 -- Pervasive Technology Labs fax: +1 (812) 855-4829 -- Indiana University, Bloomington
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk