|
Boost : |
From: John Maddock (John_Maddock_at_[hidden])
Date: 2000-01-29 07:05:53
OK,
I think that maybe finally type_traits is about ready to go: I've uploaded
type_traits.zip to the document vault as
http://www.egroups.com/docvault/boost/TypeTraits/type_traits.zip, there are
docs for the type-traits classes, call traits and compressed pair, and I've
modified utilities index.htm to include the additional docs.
Howard - I've made some changes to the compressed_pair implementation:
1) I removed the default template arguments to compressed_pair_imp in order
to get C++ Builder to compile this (in other words a work around).
2) I couldn't get either gcc or C++ Builder to instantiate your swap code,
I ended up trampling all over it (sorry), but it does now seem to be
reasonably portable, I'm not sure if this was a real problem or whether
this is another work around.
3) gcc complained about ODR violations when both template arguments are the
same (I think it was right in this case) - so I added a couple of extra
partial specialisations to deal with this case.
4) Currently if one template argument to compressed_pair is a reference
then the swap member function *will* instantiate for that template even
though it should not do so IMO, I guess maybe we need a compile time assert
here?
I've also added a bunch of test code (mostly test instantiations) to
type_traits_test.cpp to stress call_traits and compressed_pair a little.
Finally - I've added guarantees to the call_traits docs based on those
Steve suggested a while ago - they're a little less strict than those Steve
suggested though:
<snip>
For all types the following conditions hold:
call_traits<T>::value_type is copy-constructable from types: T,
call_traits<T>::value_type, call_traits<T>::reference, and
call_traits<T>::param_type.
call_traits<T>::reference is copy-constructable from types: T,
call_traits<T>::value_type, and call_traits<T>::reference.
call_traits<T>::const_reference is copy constructable from types: T,
call_traits<T>::value_type, call_traits<T>::reference,
call_traits<T>::const_reference, and call_traits<T>::param_type.
call_traits<T>::param_type is copy-constructable from types: T,
call_traits<T>::value_type, call_traits<T>::reference, and
call_traits<T>::const_reference.
If T is an assignable type then the following conditions also hold:
call_traits<T>::value_type is assignable from types: T,
call_traits<T>::value_type, call_traits<T>::reference,
call_traits<T>::const_reference, and call_traits<T>::param_type.
</snip>
However these conditions as they stand don't hold for array types, there
are four options as I see it:
Option 1: change the call_traits array specialisation to:
template <typename T, std::size_t N>
struct call_traits<T [N]>
{
typedef T* const value_type;
typedef T* const reference;
typedef const T* const const_reference;
typedef value_type param_type;
};
Option 2: change the call_traits array specialisation to:
template <typename T, std::size_t N>
struct call_traits<T [N]>
{
private:
typedef T array_type[N];
public:
typedef array_type& value_type;
typedef array_type& reference;
typedef const array_type& const_reference;
typedef value_type param_type;
};
Option 3: weaken the guarantees further:
Option 4: do nothing for now, accept that we need more example of usage
conventions of this template before going any further.
I think that either option 1 or 2 would be compatible with your make_pair
code (?) - however both unmasked compiler problems when I tried them out in
type_traits_test.cpp, so I would appreciate some feedback.
Anyway, hopefully this is close now,
- John.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk