advanced_insert_int.hpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2008-2013. 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. #ifndef BOOST_CONTAINER_ADVANCED_INSERT_INT_HPP
  11. #define BOOST_CONTAINER_ADVANCED_INSERT_INT_HPP
  12. #ifndef BOOST_CONFIG_HPP
  13. # include <boost/config.hpp>
  14. #endif
  15. #if defined(BOOST_HAS_PRAGMA_ONCE)
  16. # pragma once
  17. #endif
  18. #include <boost/container/detail/config_begin.hpp>
  19. #include <boost/container/detail/workaround.hpp>
  20. // container
  21. #include <boost/container/allocator_traits.hpp>
  22. // container/detail
  23. #include <boost/container/detail/copy_move_algo.hpp>
  24. #include <boost/container/detail/destroyers.hpp>
  25. #include <boost/container/detail/mpl.hpp>
  26. #include <boost/container/detail/type_traits.hpp>
  27. #include <boost/container/detail/iterator.hpp>
  28. #include <boost/container/detail/iterators.hpp>
  29. #include <boost/move/detail/iterator_to_raw_pointer.hpp>
  30. #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  31. #include <boost/move/detail/fwd_macros.hpp>
  32. #endif
  33. // move
  34. #include <boost/move/utility_core.hpp>
  35. // other
  36. #include <boost/assert.hpp>
  37. #include <boost/core/no_exceptions_support.hpp>
  38. namespace boost { namespace container { namespace dtl {
  39. template<class Allocator, class FwdIt, class Iterator>
  40. struct move_insert_range_proxy
  41. {
  42. typedef typename allocator_traits<Allocator>::size_type size_type;
  43. typedef typename allocator_traits<Allocator>::value_type value_type;
  44. BOOST_CONTAINER_FORCEINLINE explicit move_insert_range_proxy(FwdIt first)
  45. : first_(first)
  46. {}
  47. BOOST_CONTAINER_FORCEINLINE void uninitialized_copy_n_and_update(Allocator &a, Iterator p, size_type n)
  48. {
  49. this->first_ = ::boost::container::uninitialized_move_alloc_n_source
  50. (a, this->first_, n, p);
  51. }
  52. BOOST_CONTAINER_FORCEINLINE void copy_n_and_update(Allocator &, Iterator p, size_type n)
  53. {
  54. this->first_ = ::boost::container::move_n_source(this->first_, n, p);
  55. }
  56. FwdIt first_;
  57. };
  58. template<class Allocator, class FwdIt, class Iterator>
  59. struct insert_range_proxy
  60. {
  61. typedef typename allocator_traits<Allocator>::size_type size_type;
  62. typedef typename allocator_traits<Allocator>::value_type value_type;
  63. BOOST_CONTAINER_FORCEINLINE explicit insert_range_proxy(FwdIt first)
  64. : first_(first)
  65. {}
  66. BOOST_CONTAINER_FORCEINLINE void uninitialized_copy_n_and_update(Allocator &a, Iterator p, size_type n)
  67. {
  68. this->first_ = ::boost::container::uninitialized_copy_alloc_n_source(a, this->first_, n, p);
  69. }
  70. BOOST_CONTAINER_FORCEINLINE void copy_n_and_update(Allocator &, Iterator p, size_type n)
  71. {
  72. this->first_ = ::boost::container::copy_n_source(this->first_, n, p);
  73. }
  74. FwdIt first_;
  75. };
  76. template<class Allocator, class Iterator>
  77. struct insert_n_copies_proxy
  78. {
  79. typedef typename allocator_traits<Allocator>::size_type size_type;
  80. typedef typename allocator_traits<Allocator>::value_type value_type;
  81. BOOST_CONTAINER_FORCEINLINE explicit insert_n_copies_proxy(const value_type &v)
  82. : v_(v)
  83. {}
  84. BOOST_CONTAINER_FORCEINLINE void uninitialized_copy_n_and_update(Allocator &a, Iterator p, size_type n) const
  85. { boost::container::uninitialized_fill_alloc_n(a, v_, n, p); }
  86. BOOST_CONTAINER_FORCEINLINE void copy_n_and_update(Allocator &, Iterator p, size_type n) const
  87. {
  88. while (n){
  89. --n;
  90. *p = v_;
  91. ++p;
  92. }
  93. }
  94. const value_type &v_;
  95. };
  96. template<class Allocator, class Iterator>
  97. struct insert_value_initialized_n_proxy
  98. {
  99. typedef ::boost::container::allocator_traits<Allocator> alloc_traits;
  100. typedef typename allocator_traits<Allocator>::size_type size_type;
  101. typedef typename allocator_traits<Allocator>::value_type value_type;
  102. typedef typename dtl::aligned_storage<sizeof(value_type), dtl::alignment_of<value_type>::value>::type storage_t;
  103. BOOST_CONTAINER_FORCEINLINE void uninitialized_copy_n_and_update(Allocator &a, Iterator p, size_type n) const
  104. { boost::container::uninitialized_value_init_alloc_n(a, n, p); }
  105. void copy_n_and_update(Allocator &a, Iterator p, size_type n) const
  106. {
  107. while (n){
  108. --n;
  109. storage_t v;
  110. value_type *vp = reinterpret_cast<value_type *>(v.data);
  111. alloc_traits::construct(a, vp);
  112. value_destructor<Allocator> on_exit(a, *vp); (void)on_exit;
  113. *p = ::boost::move(*vp);
  114. ++p;
  115. }
  116. }
  117. };
  118. template<class Allocator, class Iterator>
  119. struct insert_default_initialized_n_proxy
  120. {
  121. typedef ::boost::container::allocator_traits<Allocator> alloc_traits;
  122. typedef typename allocator_traits<Allocator>::size_type size_type;
  123. typedef typename allocator_traits<Allocator>::value_type value_type;
  124. typedef typename dtl::aligned_storage<sizeof(value_type), dtl::alignment_of<value_type>::value>::type storage_t;
  125. BOOST_CONTAINER_FORCEINLINE void uninitialized_copy_n_and_update(Allocator &a, Iterator p, size_type n) const
  126. { boost::container::uninitialized_default_init_alloc_n(a, n, p); }
  127. void copy_n_and_update(Allocator &a, Iterator p, size_type n) const
  128. {
  129. if(!is_pod<value_type>::value){
  130. while (n){
  131. --n;
  132. typename dtl::aligned_storage<sizeof(value_type), dtl::alignment_of<value_type>::value>::type v;
  133. value_type *vp = reinterpret_cast<value_type *>(v.data);
  134. alloc_traits::construct(a, vp, default_init);
  135. value_destructor<Allocator> on_exit(a, *vp); (void)on_exit;
  136. *p = ::boost::move(*vp);
  137. ++p;
  138. }
  139. }
  140. }
  141. };
  142. template<class Allocator, class Iterator>
  143. struct insert_copy_proxy
  144. {
  145. typedef boost::container::allocator_traits<Allocator> alloc_traits;
  146. typedef typename alloc_traits::size_type size_type;
  147. typedef typename alloc_traits::value_type value_type;
  148. static const bool single_value = true;
  149. BOOST_CONTAINER_FORCEINLINE explicit insert_copy_proxy(const value_type &v)
  150. : v_(v)
  151. {}
  152. BOOST_CONTAINER_FORCEINLINE void uninitialized_copy_n_and_update(Allocator &a, Iterator p, size_type n) const
  153. {
  154. BOOST_ASSERT(n == 1); (void)n;
  155. alloc_traits::construct( a, boost::movelib::iterator_to_raw_pointer(p), v_);
  156. }
  157. BOOST_CONTAINER_FORCEINLINE void copy_n_and_update(Allocator &, Iterator p, size_type n) const
  158. {
  159. BOOST_ASSERT(n == 1); (void)n;
  160. *p = v_;
  161. }
  162. const value_type &v_;
  163. };
  164. template<class Allocator, class Iterator>
  165. struct insert_move_proxy
  166. {
  167. typedef boost::container::allocator_traits<Allocator> alloc_traits;
  168. typedef typename alloc_traits::size_type size_type;
  169. typedef typename alloc_traits::value_type value_type;
  170. static const bool single_value = true;
  171. BOOST_CONTAINER_FORCEINLINE explicit insert_move_proxy(value_type &v)
  172. : v_(v)
  173. {}
  174. BOOST_CONTAINER_FORCEINLINE void uninitialized_copy_n_and_update(Allocator &a, Iterator p, size_type n) const
  175. {
  176. BOOST_ASSERT(n == 1); (void)n;
  177. alloc_traits::construct( a, boost::movelib::iterator_to_raw_pointer(p), ::boost::move(v_) );
  178. }
  179. BOOST_CONTAINER_FORCEINLINE void copy_n_and_update(Allocator &, Iterator p, size_type n) const
  180. {
  181. BOOST_ASSERT(n == 1); (void)n;
  182. *p = ::boost::move(v_);
  183. }
  184. value_type &v_;
  185. };
  186. template<class It, class Allocator>
  187. BOOST_CONTAINER_FORCEINLINE insert_move_proxy<Allocator, It> get_insert_value_proxy(BOOST_RV_REF(typename boost::container::iterator_traits<It>::value_type) v)
  188. {
  189. return insert_move_proxy<Allocator, It>(v);
  190. }
  191. template<class It, class Allocator>
  192. BOOST_CONTAINER_FORCEINLINE insert_copy_proxy<Allocator, It> get_insert_value_proxy(const typename boost::container::iterator_traits<It>::value_type &v)
  193. {
  194. return insert_copy_proxy<Allocator, It>(v);
  195. }
  196. }}} //namespace boost { namespace container { namespace dtl {
  197. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  198. #include <boost/container/detail/variadic_templates_tools.hpp>
  199. #include <boost/move/utility_core.hpp>
  200. namespace boost {
  201. namespace container {
  202. namespace dtl {
  203. template<class Allocator, class Iterator, class ...Args>
  204. struct insert_nonmovable_emplace_proxy
  205. {
  206. typedef boost::container::allocator_traits<Allocator> alloc_traits;
  207. typedef typename alloc_traits::size_type size_type;
  208. typedef typename alloc_traits::value_type value_type;
  209. typedef typename build_number_seq<sizeof...(Args)>::type index_tuple_t;
  210. static const bool single_value = true;
  211. BOOST_CONTAINER_FORCEINLINE explicit insert_nonmovable_emplace_proxy(BOOST_FWD_REF(Args)... args)
  212. : args_(args...)
  213. {}
  214. BOOST_CONTAINER_FORCEINLINE void uninitialized_copy_n_and_update(Allocator &a, Iterator p, size_type n)
  215. { this->priv_uninitialized_copy_some_and_update(a, index_tuple_t(), p, n); }
  216. private:
  217. template<std::size_t ...IdxPack>
  218. BOOST_CONTAINER_FORCEINLINE void priv_uninitialized_copy_some_and_update(Allocator &a, const index_tuple<IdxPack...>&, Iterator p, size_type n)
  219. {
  220. BOOST_ASSERT(n == 1); (void)n;
  221. alloc_traits::construct( a, boost::movelib::iterator_to_raw_pointer(p), ::boost::forward<Args>(get<IdxPack>(this->args_))... );
  222. }
  223. protected:
  224. tuple<Args&...> args_;
  225. };
  226. template<class Allocator, class Iterator, class ...Args>
  227. struct insert_emplace_proxy
  228. : public insert_nonmovable_emplace_proxy<Allocator, Iterator, Args...>
  229. {
  230. typedef insert_nonmovable_emplace_proxy<Allocator, Iterator, Args...> base_t;
  231. typedef boost::container::allocator_traits<Allocator> alloc_traits;
  232. typedef typename base_t::value_type value_type;
  233. typedef typename base_t::size_type size_type;
  234. typedef typename base_t::index_tuple_t index_tuple_t;
  235. static const bool single_value = true;
  236. BOOST_CONTAINER_FORCEINLINE explicit insert_emplace_proxy(BOOST_FWD_REF(Args)... args)
  237. : base_t(::boost::forward<Args>(args)...)
  238. {}
  239. BOOST_CONTAINER_FORCEINLINE void copy_n_and_update(Allocator &a, Iterator p, size_type n)
  240. { this->priv_copy_some_and_update(a, index_tuple_t(), p, n); }
  241. private:
  242. template<std::size_t ...IdxPack>
  243. BOOST_CONTAINER_FORCEINLINE void priv_copy_some_and_update(Allocator &a, const index_tuple<IdxPack...>&, Iterator p, size_type n)
  244. {
  245. BOOST_ASSERT(n ==1); (void)n;
  246. typename dtl::aligned_storage<sizeof(value_type), dtl::alignment_of<value_type>::value>::type v;
  247. value_type *vp = reinterpret_cast<value_type *>(v.data);
  248. alloc_traits::construct(a, vp, ::boost::forward<Args>(get<IdxPack>(this->args_))...);
  249. BOOST_TRY{
  250. *p = ::boost::move(*vp);
  251. }
  252. BOOST_CATCH(...){
  253. alloc_traits::destroy(a, vp);
  254. BOOST_RETHROW
  255. }
  256. BOOST_CATCH_END
  257. alloc_traits::destroy(a, vp);
  258. }
  259. };
  260. //Specializations to avoid an unneeded temporary when emplacing from a single argument o type value_type
  261. template<class Allocator, class Iterator>
  262. struct insert_emplace_proxy<Allocator, Iterator, typename boost::container::allocator_traits<Allocator>::value_type>
  263. : public insert_move_proxy<Allocator, Iterator>
  264. {
  265. static const bool single_value = true;
  266. BOOST_CONTAINER_FORCEINLINE explicit insert_emplace_proxy(typename boost::container::allocator_traits<Allocator>::value_type &&v)
  267. : insert_move_proxy<Allocator, Iterator>(v)
  268. {}
  269. };
  270. //We use "add_const" here as adding "const" only confuses MSVC12(and maybe later) provoking
  271. //compiler error C2752 ("more than one partial specialization matches").
  272. //Any problem is solvable with an extra layer of indirection? ;-)
  273. template<class Allocator, class Iterator>
  274. struct insert_emplace_proxy<Allocator, Iterator
  275. , typename boost::container::dtl::add_const<typename boost::container::allocator_traits<Allocator>::value_type>::type
  276. >
  277. : public insert_copy_proxy<Allocator, Iterator>
  278. {
  279. static const bool single_value = true;
  280. BOOST_CONTAINER_FORCEINLINE explicit insert_emplace_proxy(const typename boost::container::allocator_traits<Allocator>::value_type &v)
  281. : insert_copy_proxy<Allocator, Iterator>(v)
  282. {}
  283. };
  284. template<class Allocator, class Iterator>
  285. struct insert_emplace_proxy<Allocator, Iterator, typename boost::container::allocator_traits<Allocator>::value_type &>
  286. : public insert_copy_proxy<Allocator, Iterator>
  287. {
  288. static const bool single_value = true;
  289. BOOST_CONTAINER_FORCEINLINE explicit insert_emplace_proxy(const typename boost::container::allocator_traits<Allocator>::value_type &v)
  290. : insert_copy_proxy<Allocator, Iterator>(v)
  291. {}
  292. };
  293. template<class Allocator, class Iterator>
  294. struct insert_emplace_proxy<Allocator, Iterator
  295. , typename boost::container::dtl::add_const<typename boost::container::allocator_traits<Allocator>::value_type>::type &
  296. >
  297. : public insert_copy_proxy<Allocator, Iterator>
  298. {
  299. static const bool single_value = true;
  300. BOOST_CONTAINER_FORCEINLINE explicit insert_emplace_proxy(const typename boost::container::allocator_traits<Allocator>::value_type &v)
  301. : insert_copy_proxy<Allocator, Iterator>(v)
  302. {}
  303. };
  304. }}} //namespace boost { namespace container { namespace dtl {
  305. #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  306. #include <boost/container/detail/value_init.hpp>
  307. namespace boost {
  308. namespace container {
  309. namespace dtl {
  310. #define BOOST_CONTAINER_ADVANCED_INSERT_INT_CODE(N) \
  311. template< class Allocator, class Iterator BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\
  312. struct insert_nonmovable_emplace_proxy##N\
  313. {\
  314. typedef boost::container::allocator_traits<Allocator> alloc_traits;\
  315. typedef typename alloc_traits::size_type size_type;\
  316. typedef typename alloc_traits::value_type value_type;\
  317. \
  318. static const bool single_value = true;\
  319. \
  320. BOOST_CONTAINER_FORCEINLINE explicit insert_nonmovable_emplace_proxy##N(BOOST_MOVE_UREF##N)\
  321. BOOST_MOVE_COLON##N BOOST_MOVE_FWD_INIT##N {}\
  322. \
  323. BOOST_CONTAINER_FORCEINLINE void uninitialized_copy_n_and_update(Allocator &a, Iterator p, size_type n)\
  324. {\
  325. BOOST_ASSERT(n == 1); (void)n;\
  326. alloc_traits::construct(a, boost::movelib::iterator_to_raw_pointer(p) BOOST_MOVE_I##N BOOST_MOVE_MFWD##N);\
  327. }\
  328. \
  329. BOOST_CONTAINER_FORCEINLINE void copy_n_and_update(Allocator &, Iterator, size_type)\
  330. { BOOST_ASSERT(false); }\
  331. \
  332. protected:\
  333. BOOST_MOVE_MREF##N\
  334. };\
  335. \
  336. template< class Allocator, class Iterator BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\
  337. struct insert_emplace_proxy_arg##N\
  338. : insert_nonmovable_emplace_proxy##N< Allocator, Iterator BOOST_MOVE_I##N BOOST_MOVE_TARG##N >\
  339. {\
  340. typedef insert_nonmovable_emplace_proxy##N\
  341. < Allocator, Iterator BOOST_MOVE_I##N BOOST_MOVE_TARG##N > base_t;\
  342. typedef typename base_t::value_type value_type;\
  343. typedef typename base_t::size_type size_type;\
  344. typedef boost::container::allocator_traits<Allocator> alloc_traits;\
  345. \
  346. static const bool single_value = true;\
  347. \
  348. BOOST_CONTAINER_FORCEINLINE explicit insert_emplace_proxy_arg##N(BOOST_MOVE_UREF##N)\
  349. : base_t(BOOST_MOVE_FWD##N){}\
  350. \
  351. BOOST_CONTAINER_FORCEINLINE void copy_n_and_update(Allocator &a, Iterator p, size_type n)\
  352. {\
  353. BOOST_ASSERT(n == 1); (void)n;\
  354. typename dtl::aligned_storage<sizeof(value_type), dtl::alignment_of<value_type>::value>::type v;\
  355. value_type *vp = reinterpret_cast<value_type *>(v.data);\
  356. alloc_traits::construct(a, vp BOOST_MOVE_I##N BOOST_MOVE_MFWD##N);\
  357. BOOST_TRY{\
  358. *p = ::boost::move(*vp);\
  359. }\
  360. BOOST_CATCH(...){\
  361. alloc_traits::destroy(a, vp);\
  362. BOOST_RETHROW\
  363. }\
  364. BOOST_CATCH_END\
  365. alloc_traits::destroy(a, vp);\
  366. }\
  367. };\
  368. //
  369. BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_ADVANCED_INSERT_INT_CODE)
  370. #undef BOOST_CONTAINER_ADVANCED_INSERT_INT_CODE
  371. #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  372. //Specializations to avoid an unneeded temporary when emplacing from a single argument o type value_type
  373. template<class Allocator, class Iterator>
  374. struct insert_emplace_proxy_arg1<Allocator, Iterator, ::boost::rv<typename boost::container::allocator_traits<Allocator>::value_type> >
  375. : public insert_move_proxy<Allocator, Iterator>
  376. {
  377. static const bool single_value = true;
  378. BOOST_CONTAINER_FORCEINLINE explicit insert_emplace_proxy_arg1(typename boost::container::allocator_traits<Allocator>::value_type &v)
  379. : insert_move_proxy<Allocator, Iterator>(v)
  380. {}
  381. };
  382. template<class Allocator, class Iterator>
  383. struct insert_emplace_proxy_arg1<Allocator, Iterator, typename boost::container::allocator_traits<Allocator>::value_type>
  384. : public insert_copy_proxy<Allocator, Iterator>
  385. {
  386. static const bool single_value = true;
  387. BOOST_CONTAINER_FORCEINLINE explicit insert_emplace_proxy_arg1(const typename boost::container::allocator_traits<Allocator>::value_type &v)
  388. : insert_copy_proxy<Allocator, Iterator>(v)
  389. {}
  390. };
  391. #else //e.g. MSVC10 & MSVC11
  392. //Specializations to avoid an unneeded temporary when emplacing from a single argument o type value_type
  393. template<class Allocator, class Iterator>
  394. struct insert_emplace_proxy_arg1<Allocator, Iterator, typename boost::container::allocator_traits<Allocator>::value_type>
  395. : public insert_move_proxy<Allocator, Iterator>
  396. {
  397. static const bool single_value = true;
  398. BOOST_CONTAINER_FORCEINLINE explicit insert_emplace_proxy_arg1(typename boost::container::allocator_traits<Allocator>::value_type &&v)
  399. : insert_move_proxy<Allocator, Iterator>(v)
  400. {}
  401. };
  402. //We use "add_const" here as adding "const" only confuses MSVC10&11 provoking
  403. //compiler error C2752 ("more than one partial specialization matches").
  404. //Any problem is solvable with an extra layer of indirection? ;-)
  405. template<class Allocator, class Iterator>
  406. struct insert_emplace_proxy_arg1<Allocator, Iterator
  407. , typename boost::container::dtl::add_const<typename boost::container::allocator_traits<Allocator>::value_type>::type
  408. >
  409. : public insert_copy_proxy<Allocator, Iterator>
  410. {
  411. static const bool single_value = true;
  412. BOOST_CONTAINER_FORCEINLINE explicit insert_emplace_proxy_arg1(const typename boost::container::allocator_traits<Allocator>::value_type &v)
  413. : insert_copy_proxy<Allocator, Iterator>(v)
  414. {}
  415. };
  416. template<class Allocator, class Iterator>
  417. struct insert_emplace_proxy_arg1<Allocator, Iterator, typename boost::container::allocator_traits<Allocator>::value_type &>
  418. : public insert_copy_proxy<Allocator, Iterator>
  419. {
  420. static const bool single_value = true;
  421. BOOST_CONTAINER_FORCEINLINE explicit insert_emplace_proxy_arg1(const typename boost::container::allocator_traits<Allocator>::value_type &v)
  422. : insert_copy_proxy<Allocator, Iterator>(v)
  423. {}
  424. };
  425. template<class Allocator, class Iterator>
  426. struct insert_emplace_proxy_arg1<Allocator, Iterator
  427. , typename boost::container::dtl::add_const<typename boost::container::allocator_traits<Allocator>::value_type>::type &
  428. >
  429. : public insert_copy_proxy<Allocator, Iterator>
  430. {
  431. static const bool single_value = true;
  432. BOOST_CONTAINER_FORCEINLINE explicit insert_emplace_proxy_arg1(const typename boost::container::allocator_traits<Allocator>::value_type &v)
  433. : insert_copy_proxy<Allocator, Iterator>(v)
  434. {}
  435. };
  436. #endif
  437. }}} //namespace boost { namespace container { namespace dtl {
  438. #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  439. namespace boost { namespace container { namespace dtl {
  440. template <class T>
  441. struct has_single_value
  442. {
  443. private:
  444. struct two {char array_[2];};
  445. template<bool Arg> struct wrapper;
  446. template <class U> static two test(int, ...);
  447. template <class U> static char test(int, const wrapper<U::single_value>*);
  448. public:
  449. static const bool value = sizeof(test<T>(0, 0)) == 1;
  450. void dummy(){}
  451. };
  452. template<class InsertionProxy, bool = has_single_value<InsertionProxy>::value>
  453. struct is_single_value_proxy_impl
  454. {
  455. static const bool value = InsertionProxy::single_value;
  456. };
  457. template<class InsertionProxy>
  458. struct is_single_value_proxy_impl<InsertionProxy, false>
  459. {
  460. static const bool value = false;
  461. };
  462. template<class InsertionProxy>
  463. struct is_single_value_proxy
  464. : is_single_value_proxy_impl<InsertionProxy>
  465. {};
  466. }}} //namespace boost { namespace container { namespace dtl {
  467. #include <boost/container/detail/config_end.hpp>
  468. #endif //#ifndef BOOST_CONTAINER_ADVANCED_INSERT_INT_HPP