summaryrefslogtreecommitdiff
path: root/boost/smart_ptr/allocate_shared_array.hpp
diff options
context:
space:
mode:
authorChanho Park <chanho61.park@samsung.com>2014-12-11 18:55:56 +0900
committerChanho Park <chanho61.park@samsung.com>2014-12-11 18:55:56 +0900
commit08c1e93fa36a49f49325a07fe91ff92c964c2b6c (patch)
tree7a7053ceb8874b28ec4b868d4c49b500008a102e /boost/smart_ptr/allocate_shared_array.hpp
parentbb4dd8289b351fae6b55e303f189127a394a1edd (diff)
downloadboost-08c1e93fa36a49f49325a07fe91ff92c964c2b6c.tar.gz
boost-08c1e93fa36a49f49325a07fe91ff92c964c2b6c.tar.bz2
boost-08c1e93fa36a49f49325a07fe91ff92c964c2b6c.zip
Imported Upstream version 1.57.0upstream/1.57.0
Diffstat (limited to 'boost/smart_ptr/allocate_shared_array.hpp')
-rw-r--r--boost/smart_ptr/allocate_shared_array.hpp181
1 files changed, 181 insertions, 0 deletions
diff --git a/boost/smart_ptr/allocate_shared_array.hpp b/boost/smart_ptr/allocate_shared_array.hpp
new file mode 100644
index 0000000000..1ae5cc7832
--- /dev/null
+++ b/boost/smart_ptr/allocate_shared_array.hpp
@@ -0,0 +1,181 @@
+/*
+ * Copyright (c) 2012-2014 Glen Joseph Fernandes
+ * glenfe at live dot com
+ *
+ * Distributed under the Boost Software License,
+ * Version 1.0. (See accompanying file LICENSE_1_0.txt
+ * or copy at http://boost.org/LICENSE_1_0.txt)
+ */
+#ifndef BOOST_SMART_PTR_ALLOCATE_SHARED_ARRAY_HPP
+#define BOOST_SMART_PTR_ALLOCATE_SHARED_ARRAY_HPP
+
+#include <boost/smart_ptr/detail/array_count_impl.hpp>
+#include <boost/smart_ptr/detail/sp_if_array.hpp>
+
+namespace boost {
+ template<class T, class A>
+ inline typename boost::detail::sp_if_array<T>::type
+ allocate_shared(const A& allocator, std::size_t size) {
+ typedef typename boost::detail::array_inner<T>::type T1;
+ typedef typename boost::detail::array_base<T1>::type T2;
+ typedef boost::detail::ms_init_tag R1;
+ typedef boost::detail::as_allocator<A, T, R1> A1;
+ typedef boost::detail::ms_in_allocator_tag D1;
+ std::size_t n1 = size * boost::detail::array_total<T1>::size;
+ T1* p1 = 0;
+ T2* p2 = 0;
+ D1 d1;
+ A1 a1(allocator, size, &p2);
+ shared_ptr<T> s1(p1, d1, a1);
+ A1* a2 = static_cast<A1*>(s1._internal_get_untyped_deleter());
+ a2->set(0);
+#if !defined(BOOST_NO_CXX11_ALLOCATOR)
+ boost::detail::as_init(allocator, p2, n1);
+#else
+ boost::detail::ms_init(p2, n1);
+#endif
+ a2->set(p2);
+ p1 = reinterpret_cast<T1*>(p2);
+ return shared_ptr<T>(s1, p1);
+ }
+
+ template<class T, class A>
+ inline typename boost::detail::sp_if_size_array<T>::type
+ allocate_shared(const A& allocator) {
+ typedef typename boost::detail::array_inner<T>::type T1;
+ typedef typename boost::detail::array_base<T1>::type T2;
+ typedef boost::detail::ms_init_tag R1;
+ typedef boost::detail::as_allocator<A, T, R1> A1;
+ typedef boost::detail::ms_in_allocator_tag D1;
+ enum {
+ N = boost::detail::array_total<T>::size
+ };
+ T1* p1 = 0;
+ T2* p2 = 0;
+ D1 d1;
+ A1 a1(allocator, &p2);
+ shared_ptr<T> s1(p1, d1, a1);
+ A1* a2 = static_cast<A1*>(s1._internal_get_untyped_deleter());
+ a2->set(0);
+#if !defined(BOOST_NO_CXX11_ALLOCATOR)
+ boost::detail::as_init(allocator, p2, N);
+#else
+ boost::detail::ms_init(p2, N);
+#endif
+ a2->set(p2);
+ p1 = reinterpret_cast<T1*>(p2);
+ return shared_ptr<T>(s1, p1);
+ }
+
+ template<class T, class A>
+ inline typename boost::detail::sp_if_array<T>::type
+ allocate_shared(const A& allocator, std::size_t size,
+ const typename boost::detail::array_inner<T>::type& value) {
+ typedef typename boost::detail::array_inner<T>::type T1;
+ typedef typename boost::detail::array_base<T1>::type T2;
+ typedef const T2 T3;
+ typedef boost::detail::ms_init_tag R1;
+ typedef boost::detail::as_allocator<A, T, R1> A1;
+ typedef boost::detail::ms_in_allocator_tag D1;
+ enum {
+ M = boost::detail::array_total<T1>::size
+ };
+ std::size_t n1 = M * size;
+ T1* p1 = 0;
+ T2* p2 = 0;
+ T3* p3 = reinterpret_cast<T3*>(&value);
+ D1 d1;
+ A1 a1(allocator, size, &p2);
+ shared_ptr<T> s1(p1, d1, a1);
+ A1* a2 = static_cast<A1*>(s1._internal_get_untyped_deleter());
+ a2->set(0);
+#if !defined(BOOST_NO_CXX11_ALLOCATOR)
+ boost::detail::as_init<T2, A, M>(allocator, p2, n1, p3);
+#else
+ boost::detail::ms_init<T2, M>(p2, n1, p3);
+#endif
+ a2->set(p2);
+ p1 = reinterpret_cast<T1*>(p2);
+ return shared_ptr<T>(s1, p1);
+ }
+
+ template<class T, class A>
+ inline typename boost::detail::sp_if_size_array<T>::type
+ allocate_shared(const A& allocator,
+ const typename boost::detail::array_inner<T>::type& value) {
+ typedef typename boost::detail::array_inner<T>::type T1;
+ typedef typename boost::detail::array_base<T1>::type T2;
+ typedef const T2 T3;
+ typedef boost::detail::ms_init_tag R1;
+ typedef boost::detail::as_allocator<A, T, R1> A1;
+ typedef boost::detail::ms_in_allocator_tag D1;
+ enum {
+ N = boost::detail::array_total<T>::size,
+ M = boost::detail::array_total<T1>::size
+ };
+ T1* p1 = 0;
+ T2* p2 = 0;
+ T3* p3 = reinterpret_cast<T3*>(&value);
+ D1 d1;
+ A1 a1(allocator, &p2);
+ shared_ptr<T> s1(p1, d1, a1);
+ A1* a2 = static_cast<A1*>(s1._internal_get_untyped_deleter());
+ a2->set(0);
+#if !defined(BOOST_NO_CXX11_ALLOCATOR)
+ boost::detail::as_init<T2, A, M>(allocator, p2, N, p3);
+#else
+ boost::detail::ms_init<T2, M>(p2, N, p3);
+#endif
+ a2->set(p2);
+ p1 = reinterpret_cast<T1*>(p2);
+ return shared_ptr<T>(s1, p1);
+ }
+
+ template<class T, class A>
+ inline typename boost::detail::sp_if_array<T>::type
+ allocate_shared_noinit(const A& allocator, std::size_t size) {
+ typedef typename boost::detail::array_inner<T>::type T1;
+ typedef typename boost::detail::array_base<T1>::type T2;
+ typedef boost::detail::ms_noinit_tag R1;
+ typedef boost::detail::as_allocator<A, T, R1> A1;
+ typedef boost::detail::ms_in_allocator_tag D1;
+ std::size_t n1 = size * boost::detail::array_total<T1>::size;
+ T1* p1 = 0;
+ T2* p2 = 0;
+ D1 d1;
+ A1 a1(allocator, size, &p2);
+ shared_ptr<T> s1(p1, d1, a1);
+ A1* a2 = static_cast<A1*>(s1._internal_get_untyped_deleter());
+ a2->set(0);
+ boost::detail::ms_noinit(p2, n1);
+ a2->set(p2);
+ p1 = reinterpret_cast<T1*>(p2);
+ return shared_ptr<T>(s1, p1);
+ }
+
+ template<class T, class A>
+ inline typename boost::detail::sp_if_size_array<T>::type
+ allocate_shared_noinit(const A& allocator) {
+ typedef typename boost::detail::array_inner<T>::type T1;
+ typedef typename boost::detail::array_base<T1>::type T2;
+ typedef boost::detail::ms_noinit_tag R1;
+ typedef boost::detail::as_allocator<A, T, R1> A1;
+ typedef boost::detail::ms_in_allocator_tag D1;
+ enum {
+ N = boost::detail::array_total<T>::size
+ };
+ T1* p1 = 0;
+ T2* p2 = 0;
+ D1 d1;
+ A1 a1(allocator, &p2);
+ shared_ptr<T> s1(p1, d1, a1);
+ A1* a2 = static_cast<A1*>(s1._internal_get_untyped_deleter());
+ a2->set(0);
+ boost::detail::ms_noinit(p2, N);
+ a2->set(p2);
+ p1 = reinterpret_cast<T1*>(p2);
+ return shared_ptr<T>(s1, p1);
+ }
+}
+
+#endif