/libs/container/test/scoped_allocator_adaptor_test.cpp

https://bitbucket.org/kbw/boost_svn · C++ · 1247 lines · 1044 code · 95 blank · 108 comment · 143 complexity · c6ecd42f230758b3237a7183afdb9f22 MD5 · raw file

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2011-2012. Distributed under the Boost
  4. // Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/container for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. #include <boost/container/detail/config_begin.hpp>
  11. #include <boost/container/scoped_allocator_fwd.hpp>
  12. #include <boost/container/detail/utilities.hpp>
  13. #include <cstddef>
  14. #include <boost/container/detail/mpl.hpp>
  15. #include <boost/move/utility.hpp>
  16. #include <boost/type_traits/integral_constant.hpp>
  17. #include <memory>
  18. using namespace boost::container;
  19. template<class T, unsigned int Id, bool Propagate = false>
  20. class test_allocator
  21. {
  22. BOOST_COPYABLE_AND_MOVABLE(test_allocator)
  23. public:
  24. template<class U>
  25. struct rebind
  26. {
  27. typedef test_allocator<U, Id, Propagate> other;
  28. };
  29. typedef container_detail::bool_<Propagate> propagate_on_container_copy_assignment;
  30. typedef container_detail::bool_<Propagate> propagate_on_container_move_assignment;
  31. typedef container_detail::bool_<Propagate> propagate_on_container_swap;
  32. typedef T value_type;
  33. test_allocator()
  34. {}
  35. test_allocator(const test_allocator&)
  36. {}
  37. test_allocator(BOOST_RV_REF(test_allocator) )
  38. {}
  39. template<class U>
  40. test_allocator(BOOST_RV_REF_BEG test_allocator<U, Id, Propagate> BOOST_RV_REF_END)
  41. {}
  42. template<class U>
  43. test_allocator(const test_allocator<U, Id, Propagate> &)
  44. {}
  45. test_allocator & operator=(BOOST_COPY_ASSIGN_REF(test_allocator))
  46. { return *this; }
  47. test_allocator & operator=(BOOST_RV_REF(test_allocator))
  48. { return *this; }
  49. std::size_t max_size() const
  50. { return std::size_t(Id); }
  51. T* allocate(std::size_t n)
  52. { return (T*)::new char[n*sizeof(T)]; }
  53. void deallocate(T*p, std::size_t)
  54. { delete []static_cast<char*>(static_cast<void*>(p)); }
  55. };
  56. template <class T1, class T2, unsigned int Id, bool Propagate>
  57. bool operator==( const test_allocator<T1, Id, Propagate>&
  58. , const test_allocator<T2, Id, Propagate>&)
  59. { return true; }
  60. template <class T1, class T2, unsigned int Id, bool Propagate>
  61. bool operator!=( const test_allocator<T1, Id, Propagate>&
  62. , const test_allocator<T2, Id, Propagate>&)
  63. { return false; }
  64. template<unsigned int Type>
  65. struct tagged_integer
  66. {};
  67. struct mark_on_destructor
  68. {
  69. mark_on_destructor()
  70. : destroyed(false)
  71. {}
  72. ~mark_on_destructor()
  73. {
  74. destroyed = true;
  75. }
  76. bool destroyed;
  77. };
  78. //This enum lists the construction options
  79. //for an allocator-aware type
  80. enum ConstructionTypeEnum
  81. {
  82. ConstructiblePrefix,
  83. ConstructibleSuffix,
  84. NotUsesAllocator,
  85. };
  86. //This base class provices types for
  87. //the derived class to implement each construction
  88. //type. If a construction type does not apply
  89. //the typedef is set to an internal nat
  90. //so that the class is not constructible from
  91. //the user arguments.
  92. template<ConstructionTypeEnum ConstructionType, unsigned int AllocatorTag>
  93. struct uses_allocator_base;
  94. template<unsigned int AllocatorTag>
  95. struct uses_allocator_base<ConstructibleSuffix, AllocatorTag>
  96. {
  97. typedef test_allocator<int, AllocatorTag> allocator_type;
  98. typedef allocator_type allocator_constructor_type;
  99. struct nat{};
  100. typedef nat allocator_arg_type;
  101. };
  102. template<unsigned int AllocatorTag>
  103. struct uses_allocator_base<ConstructiblePrefix, AllocatorTag>
  104. {
  105. typedef test_allocator<int, AllocatorTag> allocator_type;
  106. typedef allocator_type allocator_constructor_type;
  107. typedef allocator_arg_t allocator_arg_type;
  108. };
  109. template<unsigned int AllocatorTag>
  110. struct uses_allocator_base<NotUsesAllocator, AllocatorTag>
  111. {
  112. struct nat{};
  113. typedef nat allocator_constructor_type;
  114. typedef nat allocator_arg_type;
  115. };
  116. template<ConstructionTypeEnum ConstructionType, unsigned int AllocatorTag>
  117. struct mark_on_scoped_allocation
  118. : uses_allocator_base<ConstructionType, AllocatorTag>
  119. {
  120. private:
  121. BOOST_COPYABLE_AND_MOVABLE(mark_on_scoped_allocation)
  122. public:
  123. typedef uses_allocator_base<ConstructionType, AllocatorTag> base_type;
  124. //0 user argument constructors
  125. mark_on_scoped_allocation()
  126. : construction_type(NotUsesAllocator), value(0)
  127. {}
  128. explicit mark_on_scoped_allocation
  129. (typename base_type::allocator_constructor_type)
  130. : construction_type(ConstructibleSuffix), value(0)
  131. {}
  132. explicit mark_on_scoped_allocation
  133. (typename base_type::allocator_arg_type, typename base_type::allocator_constructor_type)
  134. : construction_type(ConstructiblePrefix), value(0)
  135. {}
  136. //1 user argument constructors
  137. explicit mark_on_scoped_allocation(int i)
  138. : construction_type(NotUsesAllocator), value(i)
  139. {}
  140. mark_on_scoped_allocation
  141. (int i, typename base_type::allocator_constructor_type)
  142. : construction_type(ConstructibleSuffix), value(i)
  143. {}
  144. mark_on_scoped_allocation
  145. ( typename base_type::allocator_arg_type
  146. , typename base_type::allocator_constructor_type
  147. , int i)
  148. : construction_type(ConstructiblePrefix), value(i)
  149. {}
  150. //Copy constructors
  151. mark_on_scoped_allocation(const mark_on_scoped_allocation &other)
  152. : construction_type(NotUsesAllocator), value(other.value)
  153. {}
  154. mark_on_scoped_allocation( const mark_on_scoped_allocation &other
  155. , typename base_type::allocator_constructor_type)
  156. : construction_type(ConstructibleSuffix), value(other.value)
  157. {}
  158. mark_on_scoped_allocation( typename base_type::allocator_arg_type
  159. , typename base_type::allocator_constructor_type
  160. , const mark_on_scoped_allocation &other)
  161. : construction_type(ConstructiblePrefix), value(other.value)
  162. {}
  163. //Move constructors
  164. mark_on_scoped_allocation(BOOST_RV_REF(mark_on_scoped_allocation) other)
  165. : construction_type(NotUsesAllocator), value(other.value)
  166. { other.value = 0; other.construction_type = NotUsesAllocator; }
  167. mark_on_scoped_allocation( BOOST_RV_REF(mark_on_scoped_allocation) other
  168. , typename base_type::allocator_constructor_type)
  169. : construction_type(ConstructibleSuffix), value(other.value)
  170. { other.value = 0; other.construction_type = ConstructibleSuffix; }
  171. mark_on_scoped_allocation( typename base_type::allocator_arg_type
  172. , typename base_type::allocator_constructor_type
  173. , BOOST_RV_REF(mark_on_scoped_allocation) other)
  174. : construction_type(ConstructiblePrefix), value(other.value)
  175. { other.value = 0; other.construction_type = ConstructiblePrefix; }
  176. ConstructionTypeEnum construction_type;
  177. int value;
  178. };
  179. namespace boost {
  180. namespace container {
  181. template<unsigned int AllocatorTag>
  182. struct constructible_with_allocator_prefix
  183. < ::mark_on_scoped_allocation<ConstructiblePrefix, AllocatorTag> >
  184. : ::boost::true_type
  185. {};
  186. template<unsigned int AllocatorTag>
  187. struct constructible_with_allocator_suffix
  188. < ::mark_on_scoped_allocation<ConstructibleSuffix, AllocatorTag> >
  189. : ::boost::true_type
  190. {};
  191. } //namespace container {
  192. } //namespace boost {
  193. #include <boost/container/scoped_allocator.hpp>
  194. #include <boost/type_traits/is_same.hpp>
  195. #include <boost/static_assert.hpp>
  196. #include <boost/container/vector.hpp>
  197. #include <boost/container/detail/pair.hpp>
  198. int main()
  199. {
  200. typedef test_allocator<tagged_integer<0>, 0> OuterAlloc;
  201. typedef test_allocator<tagged_integer<0>, 10> Outer10IdAlloc;
  202. typedef test_allocator<tagged_integer<9>, 0> Rebound9OuterAlloc;
  203. typedef test_allocator<tagged_integer<1>, 1> InnerAlloc1;
  204. typedef test_allocator<tagged_integer<2>, 2> InnerAlloc2;
  205. typedef test_allocator<tagged_integer<1>, 11> Inner11IdAlloc1;
  206. typedef test_allocator<tagged_integer<1>, 12> Inner12IdAlloc2;
  207. typedef test_allocator<tagged_integer<0>, 0, false> OuterAllocFalsePropagate;
  208. typedef test_allocator<tagged_integer<0>, 0, true> OuterAllocTruePropagate;
  209. typedef test_allocator<tagged_integer<1>, 1, false> InnerAlloc1FalsePropagate;
  210. typedef test_allocator<tagged_integer<1>, 1, true> InnerAlloc1TruePropagate;
  211. typedef test_allocator<tagged_integer<2>, 2, false> InnerAlloc2FalsePropagate;
  212. typedef test_allocator<tagged_integer<2>, 2, true> InnerAlloc2TruePropagate;
  213. //
  214. typedef scoped_allocator_adaptor< OuterAlloc > Scoped0Inner;
  215. typedef scoped_allocator_adaptor< OuterAlloc
  216. , InnerAlloc1 > Scoped1Inner;
  217. typedef scoped_allocator_adaptor< OuterAlloc
  218. , InnerAlloc1
  219. , InnerAlloc2 > Scoped2Inner;
  220. typedef scoped_allocator_adaptor
  221. < scoped_allocator_adaptor
  222. <Outer10IdAlloc>
  223. > ScopedScoped0Inner;
  224. typedef scoped_allocator_adaptor
  225. < scoped_allocator_adaptor
  226. <Outer10IdAlloc, Inner11IdAlloc1>
  227. , InnerAlloc1
  228. > ScopedScoped1Inner;
  229. typedef scoped_allocator_adaptor
  230. < scoped_allocator_adaptor
  231. <Outer10IdAlloc, Inner11IdAlloc1, Inner12IdAlloc2>
  232. , InnerAlloc1, InnerAlloc2
  233. > ScopedScoped2Inner;
  234. typedef scoped_allocator_adaptor< Rebound9OuterAlloc > Rebound9Scoped0Inner;
  235. typedef scoped_allocator_adaptor< Rebound9OuterAlloc
  236. , InnerAlloc1 > Rebound9Scoped1Inner;
  237. typedef scoped_allocator_adaptor< Rebound9OuterAlloc
  238. , InnerAlloc1
  239. , InnerAlloc2 > Rebound9Scoped2Inner;
  240. //outer_allocator_type
  241. BOOST_STATIC_ASSERT(( boost::container::container_detail::is_same< OuterAlloc
  242. , Scoped0Inner::outer_allocator_type>::value ));
  243. BOOST_STATIC_ASSERT(( boost::container::container_detail::is_same< OuterAlloc
  244. , Scoped1Inner::outer_allocator_type>::value ));
  245. BOOST_STATIC_ASSERT(( boost::container::container_detail::is_same< OuterAlloc
  246. , Scoped2Inner::outer_allocator_type>::value ));
  247. //value_type
  248. BOOST_STATIC_ASSERT(( boost::container::container_detail::is_same< allocator_traits<OuterAlloc>::value_type
  249. , Scoped0Inner::value_type>::value ));
  250. BOOST_STATIC_ASSERT(( boost::container::container_detail::is_same< allocator_traits<OuterAlloc>::value_type
  251. , Scoped1Inner::value_type>::value ));
  252. BOOST_STATIC_ASSERT(( boost::container::container_detail::is_same< allocator_traits<OuterAlloc>::value_type
  253. , Scoped2Inner::value_type>::value ));
  254. //size_type
  255. BOOST_STATIC_ASSERT(( boost::container::container_detail::is_same< allocator_traits<OuterAlloc>::size_type
  256. , Scoped0Inner::size_type>::value ));
  257. BOOST_STATIC_ASSERT(( boost::container::container_detail::is_same< allocator_traits<OuterAlloc>::size_type
  258. , Scoped1Inner::size_type>::value ));
  259. BOOST_STATIC_ASSERT(( boost::container::container_detail::is_same< allocator_traits<OuterAlloc>::size_type
  260. , Scoped2Inner::size_type>::value ));
  261. //difference_type
  262. BOOST_STATIC_ASSERT(( boost::container::container_detail::is_same< allocator_traits<OuterAlloc>::difference_type
  263. , Scoped0Inner::difference_type>::value ));
  264. BOOST_STATIC_ASSERT(( boost::container::container_detail::is_same< allocator_traits<OuterAlloc>::difference_type
  265. , Scoped1Inner::difference_type>::value ));
  266. BOOST_STATIC_ASSERT(( boost::container::container_detail::is_same< allocator_traits<OuterAlloc>::difference_type
  267. , Scoped2Inner::difference_type>::value ));
  268. //pointer
  269. BOOST_STATIC_ASSERT(( boost::container::container_detail::is_same< allocator_traits<OuterAlloc>::pointer
  270. , Scoped0Inner::pointer>::value ));
  271. BOOST_STATIC_ASSERT(( boost::container::container_detail::is_same< allocator_traits<OuterAlloc>::pointer
  272. , Scoped1Inner::pointer>::value ));
  273. BOOST_STATIC_ASSERT(( boost::container::container_detail::is_same< allocator_traits<OuterAlloc>::pointer
  274. , Scoped2Inner::pointer>::value ));
  275. //const_pointer
  276. BOOST_STATIC_ASSERT(( boost::container::container_detail::is_same< allocator_traits<OuterAlloc>::const_pointer
  277. , Scoped0Inner::const_pointer>::value ));
  278. BOOST_STATIC_ASSERT(( boost::container::container_detail::is_same< allocator_traits<OuterAlloc>::const_pointer
  279. , Scoped1Inner::const_pointer>::value ));
  280. BOOST_STATIC_ASSERT(( boost::container::container_detail::is_same< allocator_traits<OuterAlloc>::const_pointer
  281. , Scoped2Inner::const_pointer>::value ));
  282. //void_pointer
  283. BOOST_STATIC_ASSERT(( boost::container::container_detail::is_same< allocator_traits<OuterAlloc>::void_pointer
  284. , Scoped0Inner::void_pointer>::value ));
  285. BOOST_STATIC_ASSERT(( boost::container::container_detail::is_same< allocator_traits<OuterAlloc>::void_pointer
  286. , Scoped1Inner::void_pointer>::value ));
  287. BOOST_STATIC_ASSERT(( boost::container::container_detail::is_same< allocator_traits<OuterAlloc>::void_pointer
  288. , Scoped2Inner::void_pointer>::value ));
  289. //const_void_pointer
  290. BOOST_STATIC_ASSERT(( boost::container::container_detail::is_same< allocator_traits<OuterAlloc>::const_void_pointer
  291. , Scoped0Inner::const_void_pointer>::value ));
  292. BOOST_STATIC_ASSERT(( boost::container::container_detail::is_same< allocator_traits<OuterAlloc>::const_void_pointer
  293. , Scoped1Inner::const_void_pointer>::value ));
  294. BOOST_STATIC_ASSERT(( boost::container::container_detail::is_same< allocator_traits<OuterAlloc>::const_void_pointer
  295. , Scoped2Inner::const_void_pointer>::value ));
  296. //rebind
  297. BOOST_STATIC_ASSERT(( boost::container::container_detail::is_same<Scoped0Inner::rebind< tagged_integer<9> >::other
  298. , Rebound9Scoped0Inner >::value ));
  299. BOOST_STATIC_ASSERT(( boost::container::container_detail::is_same<Scoped1Inner::rebind< tagged_integer<9> >::other
  300. , Rebound9Scoped1Inner >::value ));
  301. BOOST_STATIC_ASSERT(( boost::container::container_detail::is_same<Scoped2Inner::rebind< tagged_integer<9> >::other
  302. , Rebound9Scoped2Inner >::value ));
  303. //inner_allocator_type
  304. BOOST_STATIC_ASSERT(( boost::container::container_detail::is_same< Scoped0Inner
  305. , Scoped0Inner::inner_allocator_type>::value ));
  306. BOOST_STATIC_ASSERT(( boost::container::container_detail::is_same< scoped_allocator_adaptor<InnerAlloc1>
  307. , Scoped1Inner::inner_allocator_type>::value ));
  308. BOOST_STATIC_ASSERT(( boost::container::container_detail::is_same< scoped_allocator_adaptor<InnerAlloc1, InnerAlloc2>
  309. , Scoped2Inner::inner_allocator_type>::value ));
  310. {
  311. //Propagation test
  312. typedef scoped_allocator_adaptor< OuterAllocFalsePropagate > Scoped0InnerF;
  313. typedef scoped_allocator_adaptor< OuterAllocTruePropagate > Scoped0InnerT;
  314. typedef scoped_allocator_adaptor< OuterAllocFalsePropagate
  315. , InnerAlloc1FalsePropagate > Scoped1InnerFF;
  316. typedef scoped_allocator_adaptor< OuterAllocFalsePropagate
  317. , InnerAlloc1TruePropagate > Scoped1InnerFT;
  318. typedef scoped_allocator_adaptor< OuterAllocTruePropagate
  319. , InnerAlloc1FalsePropagate > Scoped1InnerTF;
  320. typedef scoped_allocator_adaptor< OuterAllocTruePropagate
  321. , InnerAlloc1TruePropagate > Scoped1InnerTT;
  322. typedef scoped_allocator_adaptor< OuterAllocFalsePropagate
  323. , InnerAlloc1FalsePropagate
  324. , InnerAlloc2FalsePropagate > Scoped2InnerFFF;
  325. typedef scoped_allocator_adaptor< OuterAllocFalsePropagate
  326. , InnerAlloc1FalsePropagate
  327. , InnerAlloc2TruePropagate > Scoped2InnerFFT;
  328. typedef scoped_allocator_adaptor< OuterAllocFalsePropagate
  329. , InnerAlloc1TruePropagate
  330. , InnerAlloc2FalsePropagate > Scoped2InnerFTF;
  331. typedef scoped_allocator_adaptor< OuterAllocFalsePropagate
  332. , InnerAlloc1TruePropagate
  333. , InnerAlloc2TruePropagate > Scoped2InnerFTT;
  334. typedef scoped_allocator_adaptor< OuterAllocTruePropagate
  335. , InnerAlloc1FalsePropagate
  336. , InnerAlloc2FalsePropagate > Scoped2InnerTFF;
  337. typedef scoped_allocator_adaptor< OuterAllocTruePropagate
  338. , InnerAlloc1FalsePropagate
  339. , InnerAlloc2TruePropagate > Scoped2InnerTFT;
  340. typedef scoped_allocator_adaptor< OuterAllocTruePropagate
  341. , InnerAlloc1TruePropagate
  342. , InnerAlloc2FalsePropagate > Scoped2InnerTTF;
  343. typedef scoped_allocator_adaptor< OuterAllocTruePropagate
  344. , InnerAlloc1TruePropagate
  345. , InnerAlloc2TruePropagate > Scoped2InnerTTT;
  346. //propagate_on_container_copy_assignment
  347. //0 inner
  348. BOOST_STATIC_ASSERT(( !Scoped0InnerF::propagate_on_container_copy_assignment::value ));
  349. BOOST_STATIC_ASSERT(( Scoped0InnerT::propagate_on_container_copy_assignment::value ));
  350. //1 inner
  351. BOOST_STATIC_ASSERT(( !Scoped1InnerFF::propagate_on_container_copy_assignment::value ));
  352. BOOST_STATIC_ASSERT(( Scoped1InnerFT::propagate_on_container_copy_assignment::value ));
  353. BOOST_STATIC_ASSERT(( Scoped1InnerTF::propagate_on_container_copy_assignment::value ));
  354. BOOST_STATIC_ASSERT(( Scoped1InnerTT::propagate_on_container_copy_assignment::value ));
  355. //2 inner
  356. BOOST_STATIC_ASSERT(( !Scoped2InnerFFF::propagate_on_container_copy_assignment::value ));
  357. BOOST_STATIC_ASSERT(( Scoped2InnerFFT::propagate_on_container_copy_assignment::value ));
  358. BOOST_STATIC_ASSERT(( Scoped2InnerFTF::propagate_on_container_copy_assignment::value ));
  359. BOOST_STATIC_ASSERT(( Scoped2InnerFTT::propagate_on_container_copy_assignment::value ));
  360. BOOST_STATIC_ASSERT(( Scoped2InnerTFF::propagate_on_container_copy_assignment::value ));
  361. BOOST_STATIC_ASSERT(( Scoped2InnerTFT::propagate_on_container_copy_assignment::value ));
  362. BOOST_STATIC_ASSERT(( Scoped2InnerTTF::propagate_on_container_copy_assignment::value ));
  363. BOOST_STATIC_ASSERT(( Scoped2InnerTTT::propagate_on_container_copy_assignment::value ));
  364. //propagate_on_container_move_assignment
  365. //0 inner
  366. BOOST_STATIC_ASSERT(( !Scoped0InnerF::propagate_on_container_move_assignment::value ));
  367. BOOST_STATIC_ASSERT(( Scoped0InnerT::propagate_on_container_move_assignment::value ));
  368. //1 inner
  369. BOOST_STATIC_ASSERT(( !Scoped1InnerFF::propagate_on_container_move_assignment::value ));
  370. BOOST_STATIC_ASSERT(( Scoped1InnerFT::propagate_on_container_move_assignment::value ));
  371. BOOST_STATIC_ASSERT(( Scoped1InnerTF::propagate_on_container_move_assignment::value ));
  372. BOOST_STATIC_ASSERT(( Scoped1InnerTT::propagate_on_container_move_assignment::value ));
  373. //2 inner
  374. BOOST_STATIC_ASSERT(( !Scoped2InnerFFF::propagate_on_container_move_assignment::value ));
  375. BOOST_STATIC_ASSERT(( Scoped2InnerFFT::propagate_on_container_move_assignment::value ));
  376. BOOST_STATIC_ASSERT(( Scoped2InnerFTF::propagate_on_container_move_assignment::value ));
  377. BOOST_STATIC_ASSERT(( Scoped2InnerFTT::propagate_on_container_move_assignment::value ));
  378. BOOST_STATIC_ASSERT(( Scoped2InnerTFF::propagate_on_container_move_assignment::value ));
  379. BOOST_STATIC_ASSERT(( Scoped2InnerTFT::propagate_on_container_move_assignment::value ));
  380. BOOST_STATIC_ASSERT(( Scoped2InnerTTF::propagate_on_container_move_assignment::value ));
  381. BOOST_STATIC_ASSERT(( Scoped2InnerTTT::propagate_on_container_move_assignment::value ));
  382. //propagate_on_container_swap
  383. //0 inner
  384. BOOST_STATIC_ASSERT(( !Scoped0InnerF::propagate_on_container_swap::value ));
  385. BOOST_STATIC_ASSERT(( Scoped0InnerT::propagate_on_container_swap::value ));
  386. //1 inner
  387. BOOST_STATIC_ASSERT(( !Scoped1InnerFF::propagate_on_container_swap::value ));
  388. BOOST_STATIC_ASSERT(( Scoped1InnerFT::propagate_on_container_swap::value ));
  389. BOOST_STATIC_ASSERT(( Scoped1InnerTF::propagate_on_container_swap::value ));
  390. BOOST_STATIC_ASSERT(( Scoped1InnerTT::propagate_on_container_swap::value ));
  391. //2 inner
  392. BOOST_STATIC_ASSERT(( !Scoped2InnerFFF::propagate_on_container_swap::value ));
  393. BOOST_STATIC_ASSERT(( Scoped2InnerFFT::propagate_on_container_swap::value ));
  394. BOOST_STATIC_ASSERT(( Scoped2InnerFTF::propagate_on_container_swap::value ));
  395. BOOST_STATIC_ASSERT(( Scoped2InnerFTT::propagate_on_container_swap::value ));
  396. BOOST_STATIC_ASSERT(( Scoped2InnerTFF::propagate_on_container_swap::value ));
  397. BOOST_STATIC_ASSERT(( Scoped2InnerTFT::propagate_on_container_swap::value ));
  398. BOOST_STATIC_ASSERT(( Scoped2InnerTTF::propagate_on_container_swap::value ));
  399. BOOST_STATIC_ASSERT(( Scoped2InnerTTT::propagate_on_container_swap::value ));
  400. }
  401. //Default constructor
  402. {
  403. Scoped0Inner s0i;
  404. Scoped1Inner s1i;
  405. //Swap
  406. {
  407. Scoped0Inner s0i2;
  408. Scoped1Inner s1i2;
  409. boost::container::swap_dispatch(s0i, s0i2);
  410. boost::container::swap_dispatch(s1i, s1i2);
  411. }
  412. }
  413. //Default constructor
  414. {
  415. Scoped0Inner s0i;
  416. Scoped1Inner s1i;
  417. }
  418. //inner_allocator()
  419. {
  420. Scoped0Inner s0i;
  421. Scoped1Inner s1i;
  422. Scoped2Inner s2i;
  423. const Scoped0Inner const_s0i;
  424. const Scoped1Inner const_s1i;
  425. const Scoped2Inner const_s2i;
  426. Scoped0Inner::inner_allocator_type &s0i_inner = s0i.inner_allocator();
  427. (void)s0i_inner;
  428. const Scoped0Inner::inner_allocator_type &const_s0i_inner = const_s0i.inner_allocator();
  429. (void)const_s0i_inner;
  430. Scoped1Inner::inner_allocator_type &s1i_inner = s1i.inner_allocator();
  431. (void)s1i_inner;
  432. const Scoped1Inner::inner_allocator_type &const_s1i_inner = const_s1i.inner_allocator();
  433. (void)const_s1i_inner;
  434. Scoped2Inner::inner_allocator_type &s2i_inner = s2i.inner_allocator();
  435. (void)s2i_inner;
  436. const Scoped2Inner::inner_allocator_type &const_s2i_inner = const_s2i.inner_allocator();
  437. (void)const_s2i_inner;
  438. }
  439. //operator==/!=
  440. {
  441. const Scoped0Inner const_s0i;
  442. const Rebound9Scoped0Inner const_rs0i;
  443. if(!(const_s0i == const_s0i) ||
  444. !(const_rs0i == const_s0i)){
  445. return 1;
  446. }
  447. if( const_s0i != const_s0i ||
  448. const_s0i != const_rs0i ){
  449. return 1;
  450. }
  451. const Scoped1Inner const_s1i;
  452. const Rebound9Scoped1Inner const_rs1i;
  453. if(!(const_s1i == const_s1i) ||
  454. !(const_rs1i == const_s1i)){
  455. return 1;
  456. }
  457. if( const_s1i != const_s1i ||
  458. const_s1i != const_rs1i ){
  459. return 1;
  460. }
  461. const Scoped2Inner const_s2i;
  462. const Rebound9Scoped2Inner const_rs2i;
  463. if(!(const_s2i == const_s2i) ||
  464. !(const_s2i == const_rs2i) ){
  465. return 1;
  466. }
  467. if( const_s2i != const_s2i ||
  468. const_s2i != const_rs2i ){
  469. return 1;
  470. }
  471. }
  472. //outer_allocator()
  473. {
  474. Scoped0Inner s0i;
  475. Scoped1Inner s1i;
  476. Scoped2Inner s2i;
  477. const Scoped0Inner const_s0i;
  478. const Scoped1Inner const_s1i;
  479. const Scoped2Inner const_s2i;
  480. Scoped0Inner::outer_allocator_type &s0i_inner = s0i.outer_allocator();
  481. (void)s0i_inner;
  482. const Scoped0Inner::outer_allocator_type &const_s0i_inner = const_s0i.outer_allocator();
  483. (void)const_s0i_inner;
  484. Scoped1Inner::outer_allocator_type &s1i_inner = s1i.outer_allocator();
  485. (void)s1i_inner;
  486. const Scoped1Inner::outer_allocator_type &const_s1i_inner = const_s1i.outer_allocator();
  487. (void)const_s1i_inner;
  488. Scoped2Inner::outer_allocator_type &s2i_inner = s2i.outer_allocator();
  489. (void)s2i_inner;
  490. const Scoped2Inner::outer_allocator_type &const_s2i_inner = const_s2i.outer_allocator();
  491. (void)const_s2i_inner;
  492. }
  493. //max_size()
  494. {
  495. const Scoped0Inner const_s0i;
  496. const Scoped1Inner const_s1i;
  497. const Scoped2Inner const_s2i;
  498. const OuterAlloc const_oa;
  499. const InnerAlloc1 const_ia1;
  500. const InnerAlloc2 const_ia2;
  501. if(const_s0i.max_size() != const_oa.max_size()){
  502. return 1;
  503. }
  504. if(const_s1i.max_size() != const_oa.max_size()){
  505. return 1;
  506. }
  507. if(const_s2i.max_size() != const_oa.max_size()){
  508. return 1;
  509. }
  510. if(const_s1i.inner_allocator().max_size() != const_ia1.max_size()){
  511. return 1;
  512. }
  513. if(const_s2i.inner_allocator().inner_allocator().max_size() != const_ia2.max_size()){
  514. return 1;
  515. }
  516. }
  517. //Copy and move operations
  518. {
  519. //Construction
  520. {
  521. Scoped0Inner s0i_a, s0i_b(s0i_a), s0i_c(::boost::move(s0i_b));
  522. Scoped1Inner s1i_a, s1i_b(s1i_a), s1i_c(::boost::move(s1i_b));
  523. Scoped2Inner s2i_a, s2i_b(s2i_a), s2i_c(::boost::move(s2i_b));
  524. }
  525. //Assignment
  526. {
  527. Scoped0Inner s0i_a, s0i_b;
  528. s0i_a = s0i_b;
  529. s0i_a = ::boost::move(s0i_b);
  530. Scoped1Inner s1i_a, s1i_b;
  531. s1i_a = s1i_b;
  532. s1i_a = ::boost::move(s1i_b);
  533. Scoped2Inner s2i_a, s2i_b;
  534. s2i_a = s2i_b;
  535. s2i_a = ::boost::move(s2i_b);
  536. }
  537. OuterAlloc oa;
  538. InnerAlloc1 ia1;
  539. InnerAlloc2 ia2;
  540. Rebound9OuterAlloc roa;
  541. Rebound9Scoped0Inner rs0i;
  542. Rebound9Scoped1Inner rs1i;
  543. Rebound9Scoped2Inner rs2i;
  544. //Copy from outer
  545. {
  546. Scoped0Inner s0i(oa);
  547. Scoped1Inner s1i(oa, ia1);
  548. Scoped2Inner s2i(oa, ia1, ia2);
  549. }
  550. //Move from outer
  551. {
  552. Scoped0Inner s0i(::boost::move(oa));
  553. Scoped1Inner s1i(::boost::move(oa), ia1);
  554. Scoped2Inner s2i(::boost::move(oa), ia1, ia2);
  555. }
  556. //Copy from rebound outer
  557. {
  558. Scoped0Inner s0i(roa);
  559. Scoped1Inner s1i(roa, ia1);
  560. Scoped2Inner s2i(roa, ia1, ia2);
  561. }
  562. //Move from rebound outer
  563. {
  564. Scoped0Inner s0i(::boost::move(roa));
  565. Scoped1Inner s1i(::boost::move(roa), ia1);
  566. Scoped2Inner s2i(::boost::move(roa), ia1, ia2);
  567. }
  568. //Copy from rebound scoped
  569. {
  570. Scoped0Inner s0i(rs0i);
  571. Scoped1Inner s1i(rs1i);
  572. Scoped2Inner s2i(rs2i);
  573. }
  574. //Move from rebound scoped
  575. {
  576. Scoped0Inner s0i(::boost::move(rs0i));
  577. Scoped1Inner s1i(::boost::move(rs1i));
  578. Scoped2Inner s2i(::boost::move(rs2i));
  579. }
  580. }
  581. {
  582. vector<int, scoped_allocator_adaptor< test_allocator<int, 0> > > dummy;
  583. dummy.push_back(0);
  584. }
  585. //destroy()
  586. {
  587. {
  588. Scoped0Inner s0i;
  589. mark_on_destructor mod;
  590. s0i.destroy(&mod);
  591. if(!mod.destroyed){
  592. return 1;
  593. }
  594. }
  595. {
  596. Scoped1Inner s1i;
  597. mark_on_destructor mod;
  598. s1i.destroy(&mod);
  599. if(!mod.destroyed){
  600. return 1;
  601. }
  602. }
  603. {
  604. Scoped2Inner s2i;
  605. mark_on_destructor mod;
  606. s2i.destroy(&mod);
  607. if(!mod.destroyed){
  608. return 1;
  609. }
  610. }
  611. }
  612. //construct
  613. {
  614. BOOST_STATIC_ASSERT(( !boost::container::uses_allocator
  615. < ::mark_on_scoped_allocation<NotUsesAllocator, 0>
  616. , test_allocator<float, 0>
  617. >::value ));
  618. BOOST_STATIC_ASSERT(( boost::container::uses_allocator
  619. < ::mark_on_scoped_allocation<ConstructiblePrefix, 0>
  620. , test_allocator<float, 0>
  621. >::value ));
  622. BOOST_STATIC_ASSERT(( boost::container::uses_allocator
  623. < ::mark_on_scoped_allocation<ConstructibleSuffix, 0>
  624. , test_allocator<float, 0>
  625. >::value ));
  626. BOOST_STATIC_ASSERT(( boost::container::constructible_with_allocator_prefix
  627. < ::mark_on_scoped_allocation<ConstructiblePrefix, 0> >::value ));
  628. BOOST_STATIC_ASSERT(( boost::container::constructible_with_allocator_suffix
  629. < ::mark_on_scoped_allocation<ConstructibleSuffix, 0> >::value ));
  630. ////////////////////////////////////////////////////////////
  631. //First check scoped allocator with just OuterAlloc.
  632. //In this case OuterAlloc (test_allocator with tag 0) should be
  633. //used to construct types.
  634. ////////////////////////////////////////////////////////////
  635. {
  636. Scoped0Inner s0i;
  637. //Check construction with 0 user arguments
  638. {
  639. typedef ::mark_on_scoped_allocation<NotUsesAllocator, 0> MarkType;
  640. MarkType dummy;
  641. dummy.~MarkType();
  642. s0i.construct(&dummy);
  643. if(dummy.construction_type != NotUsesAllocator ||
  644. dummy.value != 0){
  645. dummy.~MarkType();
  646. return 1;
  647. }
  648. dummy.~MarkType();
  649. }
  650. {
  651. typedef ::mark_on_scoped_allocation<ConstructibleSuffix, 0> MarkType;
  652. MarkType dummy;
  653. dummy.~MarkType();
  654. s0i.construct(&dummy);
  655. if(dummy.construction_type != ConstructibleSuffix ||
  656. dummy.value != 0){
  657. dummy.~MarkType();
  658. return 1;
  659. }
  660. dummy.~MarkType();
  661. }
  662. {
  663. typedef ::mark_on_scoped_allocation<ConstructiblePrefix, 0> MarkType;
  664. MarkType dummy;
  665. dummy.~MarkType();
  666. s0i.construct(&dummy);
  667. if(dummy.construction_type != ConstructiblePrefix ||
  668. dummy.value != 0){
  669. dummy.~MarkType();
  670. return 1;
  671. }
  672. dummy.~MarkType();
  673. }
  674. //Check construction with 1 user arguments
  675. {
  676. typedef ::mark_on_scoped_allocation<NotUsesAllocator, 0> MarkType;
  677. MarkType dummy;
  678. dummy.~MarkType();
  679. s0i.construct(&dummy, 1);
  680. if(dummy.construction_type != NotUsesAllocator ||
  681. dummy.value != 1){
  682. dummy.~MarkType();
  683. return 1;
  684. }
  685. dummy.~MarkType();
  686. }
  687. {
  688. typedef ::mark_on_scoped_allocation<ConstructibleSuffix, 0> MarkType;
  689. MarkType dummy;
  690. dummy.~MarkType();
  691. s0i.construct(&dummy, 2);
  692. if(dummy.construction_type != ConstructibleSuffix ||
  693. dummy.value != 2){
  694. dummy.~MarkType();
  695. return 1;
  696. }
  697. dummy.~MarkType();
  698. }
  699. {
  700. typedef ::mark_on_scoped_allocation<ConstructiblePrefix, 0> MarkType;
  701. MarkType dummy;
  702. dummy.~MarkType();
  703. s0i.construct(&dummy, 3);
  704. if(dummy.construction_type != ConstructiblePrefix ||
  705. dummy.value != 3){
  706. dummy.~MarkType();
  707. return 1;
  708. }
  709. dummy.~MarkType();
  710. }
  711. }
  712. ////////////////////////////////////////////////////////////
  713. //Then check scoped allocator with OuterAlloc and InnerAlloc.
  714. //In this case InnerAlloc (test_allocator with tag 1) should be
  715. //used to construct types.
  716. ////////////////////////////////////////////////////////////
  717. {
  718. Scoped1Inner s1i;
  719. //Check construction with 0 user arguments
  720. {
  721. typedef ::mark_on_scoped_allocation<NotUsesAllocator, 1> MarkType;
  722. MarkType dummy;
  723. dummy.~MarkType();
  724. s1i.construct(&dummy);
  725. if(dummy.construction_type != NotUsesAllocator ||
  726. dummy.value != 0){
  727. dummy.~MarkType();
  728. return 1;
  729. }
  730. dummy.~MarkType();
  731. }
  732. {
  733. typedef ::mark_on_scoped_allocation<ConstructibleSuffix, 1> MarkType;
  734. MarkType dummy;
  735. dummy.~MarkType();
  736. s1i.construct(&dummy);
  737. if(dummy.construction_type != ConstructibleSuffix ||
  738. dummy.value != 0){
  739. dummy.~MarkType();
  740. return 1;
  741. }
  742. dummy.~MarkType();
  743. }
  744. {
  745. typedef ::mark_on_scoped_allocation<ConstructiblePrefix, 1> MarkType;
  746. MarkType dummy;
  747. dummy.~MarkType();
  748. s1i.construct(&dummy);
  749. if(dummy.construction_type != ConstructiblePrefix ||
  750. dummy.value != 0){
  751. dummy.~MarkType();
  752. return 1;
  753. }
  754. dummy.~MarkType();
  755. }
  756. //Check construction with 1 user arguments
  757. {
  758. typedef ::mark_on_scoped_allocation<NotUsesAllocator, 1> MarkType;
  759. MarkType dummy;
  760. dummy.~MarkType();
  761. s1i.construct(&dummy, 1);
  762. if(dummy.construction_type != NotUsesAllocator ||
  763. dummy.value != 1){
  764. dummy.~MarkType();
  765. return 1;
  766. }
  767. dummy.~MarkType();
  768. }
  769. {
  770. typedef ::mark_on_scoped_allocation<ConstructibleSuffix, 1> MarkType;
  771. MarkType dummy;
  772. dummy.~MarkType();
  773. s1i.construct(&dummy, 2);
  774. if(dummy.construction_type != ConstructibleSuffix ||
  775. dummy.value != 2){
  776. dummy.~MarkType();
  777. return 1;
  778. }
  779. dummy.~MarkType();
  780. }
  781. {
  782. typedef ::mark_on_scoped_allocation<ConstructiblePrefix, 1> MarkType;
  783. MarkType dummy;
  784. dummy.~MarkType();
  785. s1i.construct(&dummy, 3);
  786. if(dummy.construction_type != ConstructiblePrefix ||
  787. dummy.value != 3){
  788. dummy.~MarkType();
  789. return 1;
  790. }
  791. dummy.~MarkType();
  792. }
  793. }
  794. //////////////////////////////////////////////////////////////////////////////////
  795. //Now test recursive OuterAllocator types (OuterAllocator is an scoped_allocator)
  796. //////////////////////////////////////////////////////////////////////////////////
  797. ////////////////////////////////////////////////////////////
  798. //First check scoped allocator with just OuterAlloc.
  799. //In this case OuterAlloc (test_allocator with tag 0) should be
  800. //used to construct types.
  801. ////////////////////////////////////////////////////////////
  802. {
  803. //Check outer_allocator_type is scoped
  804. BOOST_STATIC_ASSERT(( boost::container::is_scoped_allocator
  805. <ScopedScoped0Inner::outer_allocator_type>::value ));
  806. BOOST_STATIC_ASSERT(( ::boost::container::container_detail::is_same
  807. < boost::container::outermost_allocator<ScopedScoped0Inner>::type
  808. , Outer10IdAlloc
  809. >::value ));
  810. BOOST_STATIC_ASSERT(( ::boost::container::container_detail::is_same
  811. < ScopedScoped0Inner::outer_allocator_type
  812. , scoped_allocator_adaptor<Outer10IdAlloc>
  813. >::value ));
  814. BOOST_STATIC_ASSERT(( ::boost::container::container_detail::is_same
  815. < scoped_allocator_adaptor<Outer10IdAlloc>::outer_allocator_type
  816. , Outer10IdAlloc
  817. >::value ));
  818. ScopedScoped0Inner ssro0i;
  819. Outer10IdAlloc & val = boost::container::outermost_allocator<ScopedScoped0Inner>::get(ssro0i);
  820. (void)val;
  821. //Check construction with 0 user arguments
  822. {
  823. typedef ::mark_on_scoped_allocation<NotUsesAllocator, 10> MarkType;
  824. MarkType dummy;
  825. dummy.~MarkType();
  826. ssro0i.construct(&dummy);
  827. if(dummy.construction_type != NotUsesAllocator ||
  828. dummy.value != 0){
  829. dummy.~MarkType();
  830. return 1;
  831. }
  832. dummy.~MarkType();
  833. }
  834. {
  835. typedef ::mark_on_scoped_allocation<ConstructibleSuffix, 10> MarkType;
  836. MarkType dummy;
  837. dummy.~MarkType();
  838. ssro0i.construct(&dummy);
  839. if(dummy.construction_type != ConstructibleSuffix ||
  840. dummy.value != 0){
  841. dummy.~MarkType();
  842. return 1;
  843. }
  844. dummy.~MarkType();
  845. }
  846. {
  847. typedef ::mark_on_scoped_allocation<ConstructiblePrefix, 10> MarkType;
  848. MarkType dummy;
  849. dummy.~MarkType();
  850. ssro0i.construct(&dummy);
  851. if(dummy.construction_type != ConstructiblePrefix ||
  852. dummy.value != 0){
  853. dummy.~MarkType();
  854. return 1;
  855. }
  856. dummy.~MarkType();
  857. }
  858. //Check construction with 1 user arguments
  859. {
  860. typedef ::mark_on_scoped_allocation<NotUsesAllocator, 10> MarkType;
  861. MarkType dummy;
  862. dummy.~MarkType();
  863. ssro0i.construct(&dummy, 1);
  864. if(dummy.construction_type != NotUsesAllocator ||
  865. dummy.value != 1){
  866. dummy.~MarkType();
  867. return 1;
  868. }
  869. dummy.~MarkType();
  870. }
  871. {
  872. typedef ::mark_on_scoped_allocation<ConstructibleSuffix, 10> MarkType;
  873. MarkType dummy;
  874. dummy.~MarkType();
  875. ssro0i.construct(&dummy, 2);
  876. if(dummy.construction_type != ConstructibleSuffix ||
  877. dummy.value != 2){
  878. dummy.~MarkType();
  879. return 1;
  880. }
  881. dummy.~MarkType();
  882. }
  883. {
  884. typedef ::mark_on_scoped_allocation<ConstructiblePrefix, 10> MarkType;
  885. MarkType dummy;
  886. dummy.~MarkType();
  887. ssro0i.construct(&dummy, 3);
  888. if(dummy.construction_type != ConstructiblePrefix ||
  889. dummy.value != 3){
  890. dummy.~MarkType();
  891. return 1;
  892. }
  893. dummy.~MarkType();
  894. }
  895. }
  896. ////////////////////////////////////////////////////////////
  897. //Then check scoped allocator with OuterAlloc and InnerAlloc.
  898. //In this case inner_allocator_type is not convertible to
  899. //::mark_on_scoped_allocation<XXX, 10> so uses_allocator
  900. //should be false on all tests.
  901. ////////////////////////////////////////////////////////////
  902. {
  903. //Check outer_allocator_type is scoped
  904. BOOST_STATIC_ASSERT(( boost::container::is_scoped_allocator
  905. <ScopedScoped1Inner::outer_allocator_type>::value ));
  906. BOOST_STATIC_ASSERT(( ::boost::container::container_detail::is_same
  907. < boost::container::outermost_allocator<ScopedScoped1Inner>::type
  908. , Outer10IdAlloc
  909. >::value ));
  910. BOOST_STATIC_ASSERT(( ::boost::container::container_detail::is_same
  911. < ScopedScoped1Inner::outer_allocator_type
  912. , scoped_allocator_adaptor<Outer10IdAlloc, Inner11IdAlloc1>
  913. >::value ));
  914. BOOST_STATIC_ASSERT(( ::boost::container::container_detail::is_same
  915. < scoped_allocator_adaptor<Outer10IdAlloc, Inner11IdAlloc1>::outer_allocator_type
  916. , Outer10IdAlloc
  917. >::value ));
  918. BOOST_STATIC_ASSERT(( !
  919. ::boost::container::uses_allocator
  920. < ::mark_on_scoped_allocation<ConstructibleSuffix, 10>
  921. , ScopedScoped1Inner::inner_allocator_type::outer_allocator_type
  922. >::value ));
  923. ScopedScoped1Inner ssro1i;
  924. Outer10IdAlloc & val = boost::container::outermost_allocator<ScopedScoped1Inner>::get(ssro1i);
  925. (void)val;
  926. //Check construction with 0 user arguments
  927. {
  928. typedef ::mark_on_scoped_allocation<NotUsesAllocator, 10> MarkType;
  929. MarkType dummy;
  930. dummy.~MarkType();
  931. ssro1i.construct(&dummy);
  932. if(dummy.construction_type != NotUsesAllocator ||
  933. dummy.value != 0){
  934. dummy.~MarkType();
  935. return 1;
  936. }
  937. dummy.~MarkType();
  938. }
  939. {
  940. typedef ::mark_on_scoped_allocation<ConstructibleSuffix, 10> MarkType;
  941. MarkType dummy;
  942. dummy.~MarkType();
  943. ssro1i.construct(&dummy);
  944. if(dummy.construction_type != NotUsesAllocator ||
  945. dummy.value != 0){
  946. dummy.~MarkType();
  947. return 1;
  948. }
  949. dummy.~MarkType();
  950. }
  951. {
  952. typedef ::mark_on_scoped_allocation<ConstructiblePrefix, 10> MarkType;
  953. MarkType dummy;
  954. dummy.~MarkType();
  955. ssro1i.construct(&dummy);
  956. if(dummy.construction_type != NotUsesAllocator ||
  957. dummy.value != 0){
  958. dummy.~MarkType();
  959. return 1;
  960. }
  961. dummy.~MarkType();
  962. }
  963. //Check construction with 1 user arguments
  964. {
  965. typedef ::mark_on_scoped_allocation<NotUsesAllocator, 10> MarkType;
  966. MarkType dummy;
  967. dummy.~MarkType();
  968. ssro1i.construct(&dummy, 1);
  969. if(dummy.construction_type != NotUsesAllocator ||
  970. dummy.value != 1){
  971. dummy.~MarkType();
  972. return 1;
  973. }
  974. dummy.~MarkType();
  975. }
  976. {
  977. typedef ::mark_on_scoped_allocation<ConstructibleSuffix, 10> MarkType;
  978. MarkType dummy;
  979. dummy.~MarkType();
  980. ssro1i.construct(&dummy, 2);
  981. if(dummy.construction_type != NotUsesAllocator ||
  982. dummy.value != 2){
  983. dummy.~MarkType();
  984. return 1;
  985. }
  986. dummy.~MarkType();
  987. }
  988. {
  989. typedef ::mark_on_scoped_allocation<ConstructiblePrefix, 10> MarkType;
  990. MarkType dummy;
  991. dummy.~MarkType();
  992. ssro1i.construct(&dummy, 3);
  993. if(dummy.construction_type != NotUsesAllocator ||
  994. dummy.value != 3){
  995. dummy.~MarkType();
  996. return 1;
  997. }
  998. dummy.~MarkType();
  999. }
  1000. }
  1001. ////////////////////////////////////////////////////////////
  1002. //Now check propagation to pair
  1003. ////////////////////////////////////////////////////////////
  1004. //First check scoped allocator with just OuterAlloc.
  1005. //In this case OuterAlloc (test_allocator with tag 0) should be
  1006. //used to construct types.
  1007. ////////////////////////////////////////////////////////////
  1008. {
  1009. using boost::container::container_detail::pair;
  1010. typedef test_allocator< pair< tagged_integer<0>
  1011. , tagged_integer<0> >, 0> OuterPairAlloc;
  1012. typedef test_allocator< pair< tagged_integer<1>
  1013. , tagged_integer<1> >, 1> InnerPairAlloc1;
  1014. typedef test_allocator< pair< tagged_integer<2>
  1015. , tagged_integer<2> >, 2> InnerPairAlloc2;
  1016. //
  1017. typedef scoped_allocator_adaptor < OuterPairAlloc > ScopedPair0Inner;
  1018. typedef scoped_allocator_adaptor < OuterPairAlloc
  1019. , InnerPairAlloc1 > ScopedPair1Inner;
  1020. typedef scoped_allocator_adaptor < OuterPairAlloc
  1021. , InnerPairAlloc1
  1022. , InnerPairAlloc2 > ScopedPair2Inner;
  1023. ScopedPair0Inner s0i;
  1024. //Check construction with 0 user arguments
  1025. {
  1026. typedef ::mark_on_scoped_allocation<NotUsesAllocator, 0> MarkType;
  1027. typedef pair<MarkType, MarkType> MarkTypePair;
  1028. MarkTypePair dummy;
  1029. dummy.~MarkTypePair();
  1030. s0i.construct(&dummy);
  1031. if(dummy.first.construction_type != NotUsesAllocator ||
  1032. dummy.second.construction_type != NotUsesAllocator ||
  1033. dummy.first.value != 0 ||
  1034. dummy.second.value != 0 ){
  1035. dummy.~MarkTypePair();
  1036. return 1;
  1037. }
  1038. dummy.~MarkTypePair();
  1039. }
  1040. {
  1041. typedef ::mark_on_scoped_allocation<ConstructibleSuffix, 0> MarkType;
  1042. typedef pair<MarkType, MarkType> MarkTypePair;
  1043. MarkTypePair dummy;
  1044. dummy.~MarkTypePair();
  1045. s0i.construct(&dummy);
  1046. if(dummy.first.construction_type != ConstructibleSuffix ||
  1047. dummy.second.construction_type != ConstructibleSuffix ||
  1048. dummy.first.value != 0 ||
  1049. dummy.second.value != 0 ){
  1050. dummy.~MarkTypePair();
  1051. return 1;
  1052. }
  1053. dummy.~MarkTypePair();
  1054. }
  1055. {
  1056. typedef ::mark_on_scoped_allocation<ConstructiblePrefix, 0> MarkType;
  1057. typedef pair<MarkType, MarkType> MarkTypePair;
  1058. MarkTypePair dummy;
  1059. dummy.~MarkTypePair();
  1060. s0i.construct(&dummy);
  1061. if(dummy.first.construction_type != ConstructiblePrefix ||
  1062. dummy.second.construction_type != ConstructiblePrefix ||
  1063. dummy.first.value != 0 ||
  1064. dummy.second.value != 0 ){
  1065. dummy.~MarkTypePair();
  1066. return 1;
  1067. }
  1068. dummy.~MarkTypePair();
  1069. }
  1070. //Check construction with 1 user arguments for each pair
  1071. {
  1072. typedef ::mark_on_scoped_allocation<NotUsesAllocator, 0> MarkType;
  1073. typedef pair<MarkType, MarkType> MarkTypePair;
  1074. MarkTypePair dummy;
  1075. dummy.~MarkTypePair();
  1076. s0i.construct(&dummy, 1, 1);
  1077. if(dummy.first.construction_type != NotUsesAllocator ||
  1078. dummy.second.construction_type != NotUsesAllocator ||
  1079. dummy.first.value != 1 ||
  1080. dummy.second.value != 1 ){
  1081. dummy.~MarkTypePair();
  1082. return 1;
  1083. }
  1084. dummy.~MarkTypePair();
  1085. }
  1086. {
  1087. typedef ::mark_on_scoped_allocation<ConstructibleSuffix, 0> MarkType;
  1088. typedef pair<MarkType, MarkType> MarkTypePair;
  1089. MarkTypePair dummy;
  1090. dummy.~MarkTypePair();
  1091. s0i.construct(&dummy, 1, 1);
  1092. if(dummy.first.construction_type != ConstructibleSuffix ||
  1093. dummy.second.construction_type != ConstructibleSuffix ||
  1094. dummy.first.value != 1 ||
  1095. dummy.second.value != 1 ){
  1096. dummy.~MarkTypePair();
  1097. return 1;
  1098. }
  1099. dummy.~MarkTypePair();
  1100. }
  1101. {
  1102. typedef ::mark_on_scoped_allocation<ConstructiblePrefix, 0> MarkType;
  1103. typedef pair<MarkType, MarkType> MarkTypePair;
  1104. MarkTypePair dummy;
  1105. dummy.~MarkTypePair();
  1106. s0i.construct(&dummy, 2, 2);
  1107. if(dummy.first.construction_type != ConstructiblePrefix ||
  1108. dummy.second.construction_type != ConstructiblePrefix ||
  1109. dummy.first.value != 2 ||
  1110. dummy.second.value != 2 ){
  1111. dummy.~MarkTypePair();
  1112. return 1;
  1113. }
  1114. dummy.~MarkTypePair();
  1115. }
  1116. //Check construction with pair copy construction
  1117. {
  1118. typedef ::mark_on_scoped_allocation<NotUsesAllocator, 0> MarkType;
  1119. typedef pair<MarkType, MarkType> MarkTypePair;
  1120. MarkTypePair dummy, dummy2;
  1121. dummy.~MarkTypePair();
  1122. s0i.construct(&dummy, dummy2);
  1123. if(dummy.first.construction_type != NotUsesAllocator ||
  1124. dummy.second.construction_type != NotUsesAllocator ||
  1125. dummy.first.value != 0 ||
  1126. dummy.second.value != 0 ){
  1127. dummy.~MarkTypePair();
  1128. return 1;
  1129. }
  1130. dummy.~MarkTypePair();
  1131. }
  1132. {
  1133. typedef ::mark_on_scoped_allocation<ConstructibleSuffix, 0> MarkType;
  1134. typedef pair<MarkType, MarkType> MarkTypePair;
  1135. MarkTypePair dummy, dummy2(1, 1);
  1136. dummy.~MarkTypePair();
  1137. s0i.construct(&dummy, dummy2);
  1138. if(dummy.first.construction_type != ConstructibleSuffix ||
  1139. dummy.second.construction_type != ConstructibleSuffix ||
  1140. dummy.first.value != 1 ||
  1141. dummy.second.value != 1 ){
  1142. dummy.~MarkTypePair();
  1143. return 1;
  1144. }
  1145. dummy.~MarkTypePair();
  1146. }
  1147. {
  1148. typedef ::mark_on_scoped_allocation<ConstructiblePrefix, 0> MarkType;
  1149. typedef pair<MarkType, MarkType> MarkTypePair;
  1150. MarkTypePair dummy, dummy2(2, 2);
  1151. dummy.~MarkTypePair();
  1152. s0i.construct(&du