construct_in_place.hpp 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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