LibreOffice Module o3tl (master)  1
make_shared.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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  */
9 
10 #ifndef INCLUDED_O3TL_MAKE_SHARED_HXX
11 #define INCLUDED_O3TL_MAKE_SHARED_HXX
12 
13 #include <memory>
14 #include <type_traits>
15 
16 namespace o3tl {
17 
22 template<typename T>
23 std::shared_ptr<T> make_shared_array(size_t const size)
24 {
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[]>());
27 }
28 
29 } // namespace o3tl
30 
31 #endif // INCLUDED_O3TL_MAKE_SHARED_HXX
32 
33 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< T > make_shared_array(size_t const size)
Allocate an array stored in a shared_ptr, calling operator delete[].
Definition: make_shared.hxx:23