Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / o3tl / make_shared.hxx
blobd42783c301fa089282e80de421d14351d271c47f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #ifndef INCLUDED_O3TL_MAKE_SHARED_HXX
11 #define INCLUDED_O3TL_MAKE_SHARED_HXX
13 #include <memory>
14 #include <type_traits>
16 namespace o3tl {
18 /** Allocate an array stored in a shared_ptr, calling operator delete[].
19 Note that this is only allowed for arithmetic types because shared_ptr
20 implicitly converts to sub-types.
22 template<typename T>
23 std::shared_ptr<T> make_shared_array(size_t const size)
25 static_assert(std::is_arithmetic<T>::value, "only arrays of arithmetic types allowed");
26 return std::shared_ptr<T>(new T[size], std::default_delete<T[]>());
29 } // namespace o3tl
31 #endif // INCLUDED_O3TL_MAKE_SHARED_HXX
33 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */