construct_in_place.hpp 2.9 KB

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