ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

mvctor_declaration_test.cpp
Go to the documentation of this file.
00001 #include <vector>
00002 #include <algorithm>
00003 #include <string>
00004 #if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
00005 #  include <rope>
00006 #endif
00007 #if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
00008 #  include <slist>
00009 #endif
00010 #include <list>
00011 #include <deque>
00012 #include <set>
00013 #include <map>
00014 #if defined (STLPORT)
00015 #  include <unordered_set>
00016 #  include <unordered_map>
00017 #endif
00018 #if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
00019 #  include <hash_set>
00020 #  include <hash_map>
00021 #endif
00022 #include <queue>
00023 #include <stack>
00024 
00025 #include "mvctor_test.h"
00026 
00027 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
00028 using namespace std;
00029 #  if defined (STLPORT)
00030 using namespace std::tr1;
00031 #  endif
00032 #endif
00033 
00034 #if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
00035 
00036 #  if defined (__GNUC__) && defined (_STLP_USE_NAMESPACES)
00037 // libstdc++ sometimes exposed its own __true_type in
00038 // global namespace resulting in an ambiguity.
00039 #    define __true_type std::__true_type
00040 #    define __false_type std::__false_type
00041 #  endif
00042 
00043 static bool type_to_bool(__true_type)
00044 { return true; }
00045 static bool type_to_bool(__false_type)
00046 { return false; }
00047 
00048 template <class _Tp>
00049 static bool is_movable(const _Tp&) {
00050   typedef typename __move_traits<_Tp>::implemented _MovableTp;
00051   return type_to_bool(_MovableTp());
00052 }
00053 
00054 template <class _Tp>
00055 static bool is_move_complete(const _Tp&) {
00056   typedef __move_traits<_Tp> _TpMoveTraits;
00057   typedef typename _TpMoveTraits::complete _TpMoveComplete;
00058   return type_to_bool(_TpMoveComplete());
00059 }
00060 
00061 struct specially_allocated_struct {
00062   bool operator < (const specially_allocated_struct&) const;
00063 #  if defined (__DMC__) // slist<_Tp,_Alloc>::remove error
00064   bool operator==(const specially_allocated_struct&) const;
00065 #  endif
00066 };
00067 
00068 #if defined (__DMC__)
00069 bool specially_allocated_struct::operator < (const specially_allocated_struct&) const
00070 { return false; }
00071 #endif
00072 
00073 struct struct_with_specialized_less {};
00074 
00075 #  if defined (_STLP_USE_NAMESPACES)
00076 namespace std {
00077 #  endif
00078   _STLP_TEMPLATE_NULL
00079   class allocator<specially_allocated_struct> {
00080     //This allocator just represent what a STLport could do and in this
00081     //case the STL containers implemented with it should still be movable
00082     //but not completely as we cannot do any hypothesis on what is in this
00083     //allocator.
00084   public:
00085     typedef specially_allocated_struct value_type;
00086     typedef value_type *       pointer;
00087     typedef const value_type* const_pointer;
00088     typedef value_type&       reference;
00089     typedef const value_type& const_reference;
00090     typedef size_t     size_type;
00091     typedef ptrdiff_t  difference_type;
00092 #  if defined (_STLP_MEMBER_TEMPLATE_CLASSES)
00093     template <class _Tp1> struct rebind {
00094       typedef allocator<_Tp1> other;
00095     };
00096 #  endif
00097     allocator() _STLP_NOTHROW {}
00098 #  if defined (_STLP_MEMBER_TEMPLATES)
00099     template <class _Tp1> allocator(const allocator<_Tp1>&) _STLP_NOTHROW {}
00100 #  endif
00101     allocator(const allocator&) _STLP_NOTHROW {}
00102     ~allocator() _STLP_NOTHROW {}
00103     pointer address(reference __x) const { return &__x; }
00104     const_pointer address(const_reference __x) const { return &__x; }
00105     pointer allocate(size_type, const void* = 0) { return 0; }
00106     void deallocate(pointer, size_type) {}
00107     size_type max_size() const _STLP_NOTHROW  { return 0; }
00108     void construct(pointer, const_reference) {}
00109     void destroy(pointer) {}
00110   };
00111 
00112   _STLP_TEMPLATE_NULL
00113   struct less<struct_with_specialized_less> {
00114     bool operator() (struct_with_specialized_less const&,
00115                      struct_with_specialized_less const&) const;
00116   };
00117 
00118 #  if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
00119 #    if !defined (_STLP_NO_MOVE_SEMANTIC)
00120 #      if defined (__BORLANDC__) && (__BORLANDC__ >= 0x564)
00121   _STLP_TEMPLATE_NULL
00122   struct __move_traits<vector<specially_allocated_struct> > {
00123     typedef __true_type implemented;
00124     typedef __false_type complete;
00125   };
00126   _STLP_TEMPLATE_NULL
00127   struct __move_traits<deque<specially_allocated_struct> > {
00128     typedef __true_type implemented;
00129     typedef __false_type complete;
00130   };
00131   _STLP_TEMPLATE_NULL
00132   struct __move_traits<list<specially_allocated_struct> > {
00133     typedef __true_type implemented;
00134     typedef __false_type complete;
00135   };
00136   _STLP_TEMPLATE_NULL
00137   struct __move_traits<slist<specially_allocated_struct> > {
00138     typedef __true_type implemented;
00139     typedef __false_type complete;
00140   };
00141   _STLP_TEMPLATE_NULL
00142   struct __move_traits<less<struct_with_specialized_less> > {
00143     typedef __true_type implemented;
00144     typedef __false_type complete;
00145   };
00146   _STLP_TEMPLATE_NULL
00147   struct __move_traits<set<specially_allocated_struct> > {
00148     typedef __true_type implemented;
00149     typedef __false_type complete;
00150   };
00151   _STLP_TEMPLATE_NULL
00152   struct __move_traits<multiset<specially_allocated_struct> > {
00153     typedef __true_type implemented;
00154     typedef __false_type complete;
00155   };
00156 #      endif
00157 #    endif
00158 #  endif
00159 
00160 #  if defined (_STLP_USE_NAMESPACES)
00161 }
00162 #  endif
00163 #endif
00164 
00165 void MoveConstructorTest::movable_declaration()
00166 {
00167 #if defined (STLPORT) && !defined (_STLP_DONT_SIMULATE_PARTIAL_SPEC_FOR_TYPE_TRAITS) && \
00168                          !defined (_STLP_NO_MOVE_SEMANTIC)
00169   //This test purpose is to check correct detection of the STL movable
00170   //traits declaration
00171   {
00172     //string, wstring:
00173     CPPUNIT_ASSERT( is_movable(string()) );
00174 #  if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
00175     CPPUNIT_ASSERT( is_move_complete(string()) );
00176 #  else
00177     CPPUNIT_ASSERT( !is_move_complete(string()) );
00178 #  endif
00179 #  if defined (_STLP_HAS_WCHAR_T)
00180     CPPUNIT_ASSERT( is_movable(wstring()) );
00181 #    if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
00182     CPPUNIT_ASSERT( is_move_complete(wstring()) );
00183 #    else
00184     CPPUNIT_ASSERT( !is_move_complete(wstring()) );
00185 #    endif
00186 #  endif
00187   }
00188 
00189 #  if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
00190   {
00191     //crope, wrope:
00192     CPPUNIT_ASSERT( is_movable(crope()) );
00193 #    if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
00194     CPPUNIT_ASSERT( is_move_complete(crope()) );
00195 #    else
00196     CPPUNIT_ASSERT( !is_move_complete(crope()) );
00197 #    endif
00198 #    if defined (_STLP_HAS_WCHAR_T)
00199     CPPUNIT_ASSERT( is_movable(wrope()) );
00200 #      if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
00201     CPPUNIT_ASSERT( is_move_complete(wrope()) );
00202 #      else
00203     CPPUNIT_ASSERT( !is_move_complete(wrope()) );
00204 #      endif
00205 #    endif
00206   }
00207 #  endif
00208 
00209   {
00210     //vector:
00211     CPPUNIT_ASSERT( is_movable(vector<char>()) );
00212     CPPUNIT_ASSERT( is_movable(vector<specially_allocated_struct>()) );
00213 #  if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
00214     CPPUNIT_ASSERT( is_move_complete(vector<char>()) );
00215     CPPUNIT_ASSERT( !is_move_complete(vector<specially_allocated_struct>()) );
00216 #  else
00217     CPPUNIT_ASSERT( !is_move_complete(vector<char>()) );
00218 #  endif
00219   }
00220 
00221   {
00222     //deque:
00223     CPPUNIT_ASSERT( is_movable(deque<char>()) );
00224     CPPUNIT_ASSERT( is_movable(deque<specially_allocated_struct>()) );
00225 #  if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
00226     CPPUNIT_ASSERT( is_move_complete(deque<char>()) );
00227     CPPUNIT_ASSERT( !is_move_complete(deque<specially_allocated_struct>()) );
00228 #  else
00229     CPPUNIT_ASSERT( !is_move_complete(deque<char>()) );
00230 #  endif
00231   }
00232 
00233   {
00234     //list:
00235     CPPUNIT_ASSERT( is_movable(list<char>()) );
00236     CPPUNIT_ASSERT( is_movable(list<specially_allocated_struct>()) );
00237 #  if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
00238     CPPUNIT_ASSERT( is_move_complete(list<char>()) );
00239     CPPUNIT_ASSERT( !is_move_complete(list<specially_allocated_struct>()) );
00240 #  else
00241     CPPUNIT_ASSERT( !is_move_complete(list<char>()) );
00242 #  endif
00243   }
00244 
00245 #  if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
00246   {
00247     //slist:
00248     CPPUNIT_ASSERT( is_movable(slist<char>()) );
00249     CPPUNIT_ASSERT( is_movable(slist<specially_allocated_struct>()) );
00250 #    if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
00251     CPPUNIT_ASSERT( is_move_complete(slist<char>()) );
00252     CPPUNIT_ASSERT( !is_move_complete(slist<specially_allocated_struct>()) );
00253 #    else
00254     CPPUNIT_ASSERT( !is_move_complete(slist<char>()) );
00255 #    endif
00256   }
00257 #  endif
00258 
00259   {
00260     //queue:
00261     CPPUNIT_ASSERT( is_movable(queue<char>()) );
00262     CPPUNIT_ASSERT( is_movable(queue<specially_allocated_struct>()) );
00263 #  if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
00264     CPPUNIT_ASSERT( is_move_complete(queue<char>()) );
00265     CPPUNIT_ASSERT( !is_move_complete(queue<specially_allocated_struct>()) );
00266 #  else
00267     CPPUNIT_ASSERT( !is_move_complete(queue<char>()) );
00268 #  endif
00269   }
00270 
00271   {
00272     //stack:
00273     CPPUNIT_ASSERT( is_movable(stack<char>()) );
00274     CPPUNIT_ASSERT( is_movable(stack<specially_allocated_struct>()) );
00275 #  if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
00276     CPPUNIT_ASSERT( is_move_complete(stack<char>()) );
00277     CPPUNIT_ASSERT( !is_move_complete(stack<specially_allocated_struct>()) );
00278 #  else
00279     CPPUNIT_ASSERT( !is_move_complete(stack<char>()) );
00280 #  endif
00281   }
00282 
00283 #endif
00284 }
00285 
00286 void MoveConstructorTest::movable_declaration_assoc()
00287 {
00288 #if defined (STLPORT) && !defined (_STLP_DONT_SIMULATE_PARTIAL_SPEC_FOR_TYPE_TRAITS) && \
00289                          !defined (_STLP_NO_MOVE_SEMANTIC)
00290   {
00291     //associative containers, set multiset, map, multimap:
00292 
00293     //For associative containers it is important that less is correctly recognize as
00294     //the STLport less or a user specialized less:
00295 #  if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
00296     CPPUNIT_ASSERT( is_move_complete(less<char>()) );
00297 #  endif
00298     CPPUNIT_ASSERT( !is_move_complete(less<struct_with_specialized_less>()) );
00299 
00300     //set
00301     CPPUNIT_ASSERT( is_movable(set<char>()) );
00302     CPPUNIT_ASSERT( is_movable(set<specially_allocated_struct>()) );
00303 #  if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
00304     CPPUNIT_ASSERT( is_move_complete(set<char>()) );
00305     CPPUNIT_ASSERT( !is_move_complete(set<specially_allocated_struct>()) );
00306 #  else
00307     CPPUNIT_ASSERT( !is_move_complete(set<char>()) );
00308 #  endif
00309 
00310     //multiset
00311     CPPUNIT_ASSERT( is_movable(multiset<char>()) );
00312     CPPUNIT_ASSERT( is_movable(multiset<specially_allocated_struct>()) );
00313 #  if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
00314     CPPUNIT_ASSERT( is_move_complete(multiset<char>()) );
00315     CPPUNIT_ASSERT( !is_move_complete(multiset<specially_allocated_struct>()) );
00316 #  else
00317     CPPUNIT_ASSERT( !is_move_complete(multiset<char>()) );
00318 #  endif
00319 
00320     //map
00321     CPPUNIT_ASSERT( is_movable(map<char, char>()) );
00322     CPPUNIT_ASSERT( is_movable(map<specially_allocated_struct, char>()) );
00323 #  if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
00324     CPPUNIT_ASSERT( is_move_complete(map<char, char>()) );
00325     //Here even if allocator has been specialized for specially_allocated_struct
00326     //this pecialization won't be used in default map instanciation as the default
00327     //allocator is allocator<pair<specially_allocated_struct, char> >
00328     CPPUNIT_ASSERT( is_move_complete(map<specially_allocated_struct, char>()) );
00329 #  else
00330     CPPUNIT_ASSERT( !is_move_complete(map<char, char>()) );
00331 #  endif
00332 
00333     //multimap
00334     CPPUNIT_ASSERT( is_movable(multimap<char, char>()) );
00335     CPPUNIT_ASSERT( is_movable(multimap<specially_allocated_struct, char>()) );
00336 #  if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
00337     CPPUNIT_ASSERT( is_move_complete(multimap<char, char>()) );
00338     //Idem map remark
00339     CPPUNIT_ASSERT( is_move_complete(multimap<specially_allocated_struct, char>()) );
00340 #  else
00341     CPPUNIT_ASSERT( !is_move_complete(multimap<char, char>()) );
00342 #  endif
00343   }
00344 #endif
00345 }
00346 
00347 void MoveConstructorTest::movable_declaration_hash()
00348 {
00349 #if defined (STLPORT) && !defined (_STLP_DONT_SIMULATE_PARTIAL_SPEC_FOR_TYPE_TRAITS) && \
00350                          !defined (_STLP_NO_MOVE_SEMANTIC)
00351   {
00352     //hashed containers, unordered_set unordered_multiset, unordered_map, unordered_multimap,
00353     //                   hash_set, hash_multiset, hash_map, hash_multimap:
00354 
00355     //We only check that they are movable, completness is not yet supported
00356     CPPUNIT_ASSERT( is_movable(unordered_set<char>()) );
00357     CPPUNIT_ASSERT( is_movable(unordered_multiset<char>()) );
00358     CPPUNIT_ASSERT( is_movable(unordered_map<char, char>()) );
00359     CPPUNIT_ASSERT( is_movable(unordered_multimap<char, char>()) );
00360 #  if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
00361     CPPUNIT_ASSERT( is_movable(hash_set<char>()) );
00362     CPPUNIT_ASSERT( is_movable(hash_multiset<char>()) );
00363     CPPUNIT_ASSERT( is_movable(hash_map<char, char>()) );
00364     CPPUNIT_ASSERT( is_movable(hash_multimap<char, char>()) );
00365 #  endif
00366   }
00367 #endif
00368 }
00369 

Generated on Sun May 27 2012 04:35:31 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.