#include #include #include #if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) # include #endif #if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) # include #endif #include #include #include #include #if defined (STLPORT) # include # include #endif #if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) # include # include #endif #include #include #include "mvctor_test.h" #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) using namespace std; # if defined (STLPORT) using namespace std::tr1; # endif #endif #if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) # if defined (__GNUC__) && defined (_STLP_USE_NAMESPACES) // libstdc++ sometimes exposed its own __true_type in // global namespace resulting in an ambiguity. # define __true_type std::__true_type # define __false_type std::__false_type # endif static bool type_to_bool(__true_type) { return true; } static bool type_to_bool(__false_type) { return false; } template static bool is_movable(const _Tp&) { typedef typename __move_traits<_Tp>::implemented _MovableTp; return type_to_bool(_MovableTp()); } template static bool is_move_complete(const _Tp&) { typedef __move_traits<_Tp> _TpMoveTraits; typedef typename _TpMoveTraits::complete _TpMoveComplete; return type_to_bool(_TpMoveComplete()); } struct specially_allocated_struct { bool operator < (const specially_allocated_struct&) const; # if defined (__DMC__) // slist<_Tp,_Alloc>::remove error bool operator==(const specially_allocated_struct&) const; # endif }; #if defined (__DMC__) bool specially_allocated_struct::operator < (const specially_allocated_struct&) const { return false; } #endif struct struct_with_specialized_less {}; # if defined (_STLP_USE_NAMESPACES) namespace std { # endif _STLP_TEMPLATE_NULL class allocator { //This allocator just represent what a STLport could do and in this //case the STL containers implemented with it should still be movable //but not completely as we cannot do any hypothesis on what is in this //allocator. public: typedef specially_allocated_struct value_type; typedef value_type * pointer; typedef const value_type* const_pointer; typedef value_type& reference; typedef const value_type& const_reference; typedef size_t size_type; typedef ptrdiff_t difference_type; # if defined (_STLP_MEMBER_TEMPLATE_CLASSES) template struct rebind { typedef allocator<_Tp1> other; }; # endif allocator() _STLP_NOTHROW {} # if defined (_STLP_MEMBER_TEMPLATES) template allocator(const allocator<_Tp1>&) _STLP_NOTHROW {} # endif allocator(const allocator&) _STLP_NOTHROW {} ~allocator() _STLP_NOTHROW {} pointer address(reference __x) const { return &__x; } const_pointer address(const_reference __x) const { return &__x; } pointer allocate(size_type, const void* = 0) { return 0; } void deallocate(pointer, size_type) {} size_type max_size() const _STLP_NOTHROW { return 0; } void construct(pointer, const_reference) {} void destroy(pointer) {} }; _STLP_TEMPLATE_NULL struct less { bool operator() (struct_with_specialized_less const&, struct_with_specialized_less const&) const; }; # if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) # if !defined (_STLP_NO_MOVE_SEMANTIC) # if defined (__BORLANDC__) && (__BORLANDC__ >= 0x564) _STLP_TEMPLATE_NULL struct __move_traits > { typedef __true_type implemented; typedef __false_type complete; }; _STLP_TEMPLATE_NULL struct __move_traits > { typedef __true_type implemented; typedef __false_type complete; }; _STLP_TEMPLATE_NULL struct __move_traits > { typedef __true_type implemented; typedef __false_type complete; }; _STLP_TEMPLATE_NULL struct __move_traits > { typedef __true_type implemented; typedef __false_type complete; }; _STLP_TEMPLATE_NULL struct __move_traits > { typedef __true_type implemented; typedef __false_type complete; }; _STLP_TEMPLATE_NULL struct __move_traits > { typedef __true_type implemented; typedef __false_type complete; }; _STLP_TEMPLATE_NULL struct __move_traits > { typedef __true_type implemented; typedef __false_type complete; }; # endif # endif # endif # if defined (_STLP_USE_NAMESPACES) } # endif #endif void MoveConstructorTest::movable_declaration() { #if defined (STLPORT) && !defined (_STLP_DONT_SIMULATE_PARTIAL_SPEC_FOR_TYPE_TRAITS) && \ !defined (_STLP_NO_MOVE_SEMANTIC) //This test purpose is to check correct detection of the STL movable //traits declaration { //string, wstring: CPPUNIT_ASSERT( is_movable(string()) ); # if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) CPPUNIT_ASSERT( is_move_complete(string()) ); # else CPPUNIT_ASSERT( !is_move_complete(string()) ); # endif # if defined (_STLP_HAS_WCHAR_T) CPPUNIT_ASSERT( is_movable(wstring()) ); # if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) CPPUNIT_ASSERT( is_move_complete(wstring()) ); # else CPPUNIT_ASSERT( !is_move_complete(wstring()) ); # endif # endif } # if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) { //crope, wrope: CPPUNIT_ASSERT( is_movable(crope()) ); # if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) CPPUNIT_ASSERT( is_move_complete(crope()) ); # else CPPUNIT_ASSERT( !is_move_complete(crope()) ); # endif # if defined (_STLP_HAS_WCHAR_T) CPPUNIT_ASSERT( is_movable(wrope()) ); # if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) CPPUNIT_ASSERT( is_move_complete(wrope()) ); # else CPPUNIT_ASSERT( !is_move_complete(wrope()) ); # endif # endif } # endif { //vector: CPPUNIT_ASSERT( is_movable(vector()) ); CPPUNIT_ASSERT( is_movable(vector()) ); # if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) CPPUNIT_ASSERT( is_move_complete(vector()) ); CPPUNIT_ASSERT( !is_move_complete(vector()) ); # else CPPUNIT_ASSERT( !is_move_complete(vector()) ); # endif } { //deque: CPPUNIT_ASSERT( is_movable(deque()) ); CPPUNIT_ASSERT( is_movable(deque()) ); # if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) CPPUNIT_ASSERT( is_move_complete(deque()) ); CPPUNIT_ASSERT( !is_move_complete(deque()) ); # else CPPUNIT_ASSERT( !is_move_complete(deque()) ); # endif } { //list: CPPUNIT_ASSERT( is_movable(list()) ); CPPUNIT_ASSERT( is_movable(list()) ); # if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) CPPUNIT_ASSERT( is_move_complete(list()) ); CPPUNIT_ASSERT( !is_move_complete(list()) ); # else CPPUNIT_ASSERT( !is_move_complete(list()) ); # endif } # if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) { //slist: CPPUNIT_ASSERT( is_movable(slist()) ); CPPUNIT_ASSERT( is_movable(slist()) ); # if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) CPPUNIT_ASSERT( is_move_complete(slist()) ); CPPUNIT_ASSERT( !is_move_complete(slist()) ); # else CPPUNIT_ASSERT( !is_move_complete(slist()) ); # endif } # endif { //queue: CPPUNIT_ASSERT( is_movable(queue()) ); CPPUNIT_ASSERT( is_movable(queue()) ); # if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) CPPUNIT_ASSERT( is_move_complete(queue()) ); CPPUNIT_ASSERT( !is_move_complete(queue()) ); # else CPPUNIT_ASSERT( !is_move_complete(queue()) ); # endif } { //stack: CPPUNIT_ASSERT( is_movable(stack()) ); CPPUNIT_ASSERT( is_movable(stack()) ); # if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) CPPUNIT_ASSERT( is_move_complete(stack()) ); CPPUNIT_ASSERT( !is_move_complete(stack()) ); # else CPPUNIT_ASSERT( !is_move_complete(stack()) ); # endif } #endif } void MoveConstructorTest::movable_declaration_assoc() { #if defined (STLPORT) && !defined (_STLP_DONT_SIMULATE_PARTIAL_SPEC_FOR_TYPE_TRAITS) && \ !defined (_STLP_NO_MOVE_SEMANTIC) { //associative containers, set multiset, map, multimap: //For associative containers it is important that less is correctly recognize as //the STLport less or a user specialized less: # if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) CPPUNIT_ASSERT( is_move_complete(less()) ); # endif CPPUNIT_ASSERT( !is_move_complete(less()) ); //set CPPUNIT_ASSERT( is_movable(set()) ); CPPUNIT_ASSERT( is_movable(set()) ); # if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) CPPUNIT_ASSERT( is_move_complete(set()) ); CPPUNIT_ASSERT( !is_move_complete(set()) ); # else CPPUNIT_ASSERT( !is_move_complete(set()) ); # endif //multiset CPPUNIT_ASSERT( is_movable(multiset()) ); CPPUNIT_ASSERT( is_movable(multiset()) ); # if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) CPPUNIT_ASSERT( is_move_complete(multiset()) ); CPPUNIT_ASSERT( !is_move_complete(multiset()) ); # else CPPUNIT_ASSERT( !is_move_complete(multiset()) ); # endif //map CPPUNIT_ASSERT( is_movable(map()) ); CPPUNIT_ASSERT( is_movable(map()) ); # if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) CPPUNIT_ASSERT( is_move_complete(map()) ); //Here even if allocator has been specialized for specially_allocated_struct //this pecialization won't be used in default map instanciation as the default //allocator is allocator > CPPUNIT_ASSERT( is_move_complete(map()) ); # else CPPUNIT_ASSERT( !is_move_complete(map()) ); # endif //multimap CPPUNIT_ASSERT( is_movable(multimap()) ); CPPUNIT_ASSERT( is_movable(multimap()) ); # if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) CPPUNIT_ASSERT( is_move_complete(multimap()) ); //Idem map remark CPPUNIT_ASSERT( is_move_complete(multimap()) ); # else CPPUNIT_ASSERT( !is_move_complete(multimap()) ); # endif } #endif } void MoveConstructorTest::movable_declaration_hash() { #if defined (STLPORT) && !defined (_STLP_DONT_SIMULATE_PARTIAL_SPEC_FOR_TYPE_TRAITS) && \ !defined (_STLP_NO_MOVE_SEMANTIC) { //hashed containers, unordered_set unordered_multiset, unordered_map, unordered_multimap, // hash_set, hash_multiset, hash_map, hash_multimap: //We only check that they are movable, completness is not yet supported CPPUNIT_ASSERT( is_movable(unordered_set()) ); CPPUNIT_ASSERT( is_movable(unordered_multiset()) ); CPPUNIT_ASSERT( is_movable(unordered_map()) ); CPPUNIT_ASSERT( is_movable(unordered_multimap()) ); # if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) CPPUNIT_ASSERT( is_movable(hash_set()) ); CPPUNIT_ASSERT( is_movable(hash_multiset()) ); CPPUNIT_ASSERT( is_movable(hash_map()) ); CPPUNIT_ASSERT( is_movable(hash_multimap()) ); # endif } #endif }