construct_in_place.hpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. namespace boost {
  24. namespace container {
  25. //In place construction
  26. struct iterator_arg_t{};
  27. template<class Allocator, class T, class InpIt>
  28. BOOST_CONTAINER_FORCEINLINE void construct_in_place(Allocator &a, T* dest, InpIt source)
  29. { boost::container::allocator_traits<Allocator>::construct(a, dest, *source); }
  30. template<class Allocator, class T, class U>
  31. BOOST_CONTAINER_FORCEINLINE void construct_in_place(Allocator &a, T *dest, value_init_construct_iterator<U>)
  32. {
  33. boost::container::allocator_traits<Allocator>::construct(a, dest);
  34. }
  35. template <class T>
  36. class default_init_construct_iterator;
  37. template<class Allocator, class T, class U>
  38. BOOST_CONTAINER_FORCEINLINE void construct_in_place(Allocator &a, T *dest, default_init_construct_iterator<U>)
  39. {
  40. boost::container::allocator_traits<Allocator>::construct(a, dest, default_init);
  41. }
  42. template <class T, class EmplaceFunctor>
  43. class emplace_iterator;
  44. template<class Allocator, class T, class U, class EF>
  45. BOOST_CONTAINER_FORCEINLINE void construct_in_place(Allocator &a, T *dest, emplace_iterator<U, EF> ei)
  46. {
  47. ei.construct_in_place(a, dest);
  48. }
  49. //Assignment
  50. template<class DstIt, class InpIt>
  51. BOOST_CONTAINER_FORCEINLINE void assign_in_place(DstIt dest, InpIt source)
  52. { *dest = *source; }
  53. template<class DstIt, class U>
  54. BOOST_CONTAINER_FORCEINLINE void assign_in_place(DstIt dest, value_init_construct_iterator<U>)
  55. {
  56. dtl::value_init<U> val;
  57. *dest = boost::move(val.get());
  58. }
  59. template <class DstIt>
  60. class default_init_construct_iterator;
  61. template<class DstIt, class U, class D>
  62. BOOST_CONTAINER_FORCEINLINE void assign_in_place(DstIt dest, default_init_construct_iterator<U>)
  63. {
  64. U u;
  65. *dest = boost::move(u);
  66. }
  67. template <class T, class EmplaceFunctor>
  68. class emplace_iterator;
  69. template<class DstIt, class U, class EF>
  70. BOOST_CONTAINER_FORCEINLINE void assign_in_place(DstIt dest, emplace_iterator<U, EF> ei)
  71. {
  72. ei.assign_in_place(dest);
  73. }
  74. } //namespace container {
  75. } //namespace boost {
  76. #endif //#ifndef BOOST_CONTAINER_DETAIL_CONSTRUCT_IN_PLACE_HPP