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
28namespace boost {
29namespace container {
30
31//In place construction
32
33template<class Allocator, class T, class InpIt>
34BOOST_CONTAINER_FORCEINLINE void construct_in_place(Allocator &a, T* dest, InpIt source)
35{ boost::container::allocator_traits<Allocator>::construct(a, dest, *source); }
36
37template<class Allocator, class T, class U, class D>
38BOOST_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
43template <class T, class Difference>
44class default_init_construct_iterator;
45
46template<class Allocator, class T, class U, class D>
47BOOST_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
52template <class T, class EmplaceFunctor, class Difference>
53class emplace_iterator;
54
55template<class Allocator, class T, class U, class EF, class D>
56BOOST_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
63template<class DstIt, class InpIt>
64BOOST_CONTAINER_FORCEINLINE void assign_in_place(DstIt dest, InpIt source)
65{ *dest = *source; }
66
67template<class DstIt, class U, class D>
68BOOST_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
74template <class DstIt, class Difference>
75class default_init_construct_iterator;
76
77template<class DstIt, class U, class D>
78BOOST_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
84template <class T, class EmplaceFunctor, class Difference>
85class emplace_iterator;
86
87template<class DstIt, class U, class EF, class D>
88BOOST_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