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 | |
13 | #ifndef BOOST_CONTAINER_DETAIL_CONSTRUCT_IN_PLACE_HPP |
14 | #define BOOST_CONTAINER_DETAIL_CONSTRUCT_IN_PLACE_HPP |
15 | |
16 | #ifndef BOOST_CONFIG_HPP |
17 | # include <boost/config.hpp> |
18 | #endif |
19 | |
20 | #if defined(BOOST_HAS_PRAGMA_ONCE) |
21 | # pragma once |
22 | #endif |
23 | |
24 | #include <boost/container/allocator_traits.hpp> |
25 | #include <boost/container/detail/iterators.hpp> |
26 | #include <boost/container/detail/value_init.hpp> |
27 | |
28 | namespace boost { |
29 | namespace container { |
30 | |
31 | //In place construction |
32 | |
33 | template<class Allocator, class T, class InpIt> |
34 | BOOST_CONTAINER_FORCEINLINE void construct_in_place(Allocator &a, T* dest, InpIt source) |
35 | { boost::container::allocator_traits<Allocator>::construct(a, dest, *source); } |
36 | |
37 | template<class Allocator, class T, class U, class D> |
38 | BOOST_CONTAINER_FORCEINLINE void construct_in_place(Allocator &a, T *dest, value_init_construct_iterator<U, D>) |
39 | { |
40 | boost::container::allocator_traits<Allocator>::construct(a, dest); |
41 | } |
42 | |
43 | template <class T, class Difference> |
44 | class default_init_construct_iterator; |
45 | |
46 | template<class Allocator, class T, class U, class D> |
47 | BOOST_CONTAINER_FORCEINLINE void construct_in_place(Allocator &a, T *dest, default_init_construct_iterator<U, D>) |
48 | { |
49 | boost::container::allocator_traits<Allocator>::construct(a, dest, default_init); |
50 | } |
51 | |
52 | template <class T, class EmplaceFunctor, class Difference> |
53 | class emplace_iterator; |
54 | |
55 | template<class Allocator, class T, class U, class EF, class D> |
56 | BOOST_CONTAINER_FORCEINLINE void construct_in_place(Allocator &a, T *dest, emplace_iterator<U, EF, D> ei) |
57 | { |
58 | ei.construct_in_place(a, dest); |
59 | } |
60 | |
61 | //Assignment |
62 | |
63 | template<class DstIt, class InpIt> |
64 | BOOST_CONTAINER_FORCEINLINE void assign_in_place(DstIt dest, InpIt source) |
65 | { *dest = *source; } |
66 | |
67 | template<class DstIt, class U, class D> |
68 | BOOST_CONTAINER_FORCEINLINE void assign_in_place(DstIt dest, value_init_construct_iterator<U, D>) |
69 | { |
70 | container_detail::value_init<U> val; |
71 | *dest = boost::move(val.get()); |
72 | } |
73 | |
74 | template <class DstIt, class Difference> |
75 | class default_init_construct_iterator; |
76 | |
77 | template<class DstIt, class U, class D> |
78 | BOOST_CONTAINER_FORCEINLINE void assign_in_place(DstIt dest, default_init_construct_iterator<U, D>) |
79 | { |
80 | U u; |
81 | *dest = boost::move(u); |
82 | } |
83 | |
84 | template <class T, class EmplaceFunctor, class Difference> |
85 | class emplace_iterator; |
86 | |
87 | template<class DstIt, class U, class EF, class D> |
88 | BOOST_CONTAINER_FORCEINLINE void assign_in_place(DstIt dest, emplace_iterator<U, EF, D> ei) |
89 | { |
90 | ei.assign_in_place(dest); |
91 | } |
92 | |
93 | } //namespace container { |
94 | } //namespace boost { |
95 | |
96 | #endif //#ifndef BOOST_CONTAINER_DETAIL_CONSTRUCT_IN_PLACE_HPP |
97 | |