construct_in_place.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2014-2014.
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // See http://www.boost.org/libs/container for documentation.
  10. //
  11. //////////////////////////////////////////////////////////////////////////////
  12. #ifndef BOOST_CONTAINER_DETAIL_CONSTRUCT_IN_PLACE_HPP
  13. #define BOOST_CONTAINER_DETAIL_CONSTRUCT_IN_PLACE_HPP
  14. #ifndef BOOST_CONFIG_HPP
  15. # include <boost/config.hpp>
  16. #endif
  17. #if defined(BOOST_HAS_PRAGMA_ONCE)
  18. # pragma once
  19. #endif
  20. #include <boost/container/allocator_traits.hpp>
  21. #include <boost/container/detail/iterators.hpp>
  22. #include <boost/container/detail/value_init.hpp>
  23. #include <boost/container/detail/is_pair.hpp>
  24. namespace boost {
  25. namespace container {
  26. //In place construction
  27. struct iterator_arg_t{};
  28. template<class Allocator, class T, class InpIt>
  29. BOOST_CONTAINER_FORCEINLINE void construct_in_place(Allocator &a, T* dest, InpIt source)
  30. { boost::container::allocator_traits<Allocator>::construct(a, dest, *source); }
  31. template<class Allocator, class T, class U>
  32. BOOST_CONTAINER_FORCEINLINE void construct_in_place(Allocator &a, T *dest, value_init_construct_iterator<U>)
  33. {
  34. boost::container::allocator_traits<Allocator>::construct(a, dest);
  35. }
  36. template <class T>
  37. class default_init_construct_iterator;
  38. template<class Allocator, class T, class U>
  39. BOOST_CONTAINER_FORCEINLINE void construct_in_place(Allocator &a, T *dest, default_init_construct_iterator<U>)
  40. {
  41. boost::container::allocator_traits<Allocator>::construct(a, dest, default_init);
  42. }
  43. template <class T, class EmplaceFunctor>
  44. class emplace_iterator;
  45. template<class Allocator, class T, class U, class EF>
  46. BOOST_CONTAINER_FORCEINLINE void construct_in_place(Allocator &a, T *dest, emplace_iterator<U, EF> ei)
  47. {
  48. ei.construct_in_place(a, dest);
  49. }
  50. //Assignment
  51. template<class T, class U>
  52. BOOST_CONTAINER_FORCEINLINE
  53. typename dtl::disable_if_c
  54. < dtl::is_pair<typename dtl::remove_reference<T>::type>::value
  55. && dtl::is_pair<typename dtl::remove_reference<U>::type>::value
  56. , void>::type
  57. assign_in_place_ref(T &t, BOOST_FWD_REF(U) u)
  58. { t = ::boost::forward<U>(u); }
  59. template<class T, class U>
  60. BOOST_CONTAINER_FORCEINLINE
  61. typename dtl::enable_if_c
  62. < dtl::is_pair<typename dtl::remove_reference<T>::type>::value
  63. && dtl::is_pair<typename dtl::remove_reference<U>::type>::value
  64. , void>::type
  65. assign_in_place_ref(T &t, const U &u)
  66. {
  67. assign_in_place_ref(t.first, u.first);
  68. assign_in_place_ref(t.second, u.second);
  69. }
  70. template<class T, class U>
  71. BOOST_CONTAINER_FORCEINLINE
  72. typename dtl::enable_if_c
  73. < dtl::is_pair<typename dtl::remove_reference<T>::type>::value
  74. && dtl::is_pair<typename dtl::remove_reference<U>::type>::value
  75. , void>::type
  76. assign_in_place_ref(T &t, BOOST_RV_REF(U) u)
  77. {
  78. assign_in_place_ref(t.first, ::boost::move(u.first));
  79. assign_in_place_ref(t.second, ::boost::move(u.second));
  80. }
  81. template<class DstIt, class InpIt>
  82. BOOST_CONTAINER_FORCEINLINE void assign_in_place(DstIt dest, InpIt source)
  83. { assign_in_place_ref(*dest, *source); }
  84. template<class DstIt, class U>
  85. BOOST_CONTAINER_FORCEINLINE void assign_in_place(DstIt dest, value_init_construct_iterator<U>)
  86. {
  87. dtl::value_init<U> val;
  88. *dest = boost::move(val.get());
  89. }
  90. template <class DstIt>
  91. class default_init_construct_iterator;
  92. template<class DstIt, class U, class D>
  93. BOOST_CONTAINER_FORCEINLINE void assign_in_place(DstIt dest, default_init_construct_iterator<U>)
  94. {
  95. U u;
  96. *dest = boost::move(u);
  97. }
  98. template <class T, class EmplaceFunctor>
  99. class emplace_iterator;
  100. template<class DstIt, class U, class EF>
  101. BOOST_CONTAINER_FORCEINLINE void assign_in_place(DstIt dest, emplace_iterator<U, EF> ei)
  102. {
  103. ei.assign_in_place(dest);
  104. }
  105. } //namespace container {
  106. } //namespace boost {
  107. #endif //#ifndef BOOST_CONTAINER_DETAIL_CONSTRUCT_IN_PLACE_HPP