nss: upgrade to release 3.73
[LibreOffice.git] / include / o3tl / make_shared.hxx
blob5d4d98e42b3a35e5cd1c0c0db1fb6ea89f6e5608
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 <o3tl/deleter.hxx>
14 #include <memory>
15 #include <type_traits>
17 namespace o3tl
19 /** Allocate an array stored in a shared_ptr, calling operator delete[].
20 Note that this is only allowed for arithmetic types because shared_ptr
21 implicitly converts to sub-types.
23 template <typename T> 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 /** To markup std::shared_ptr that coverity warns might throw exceptions
30 which won't throw in practice, or where std::terminate is
31 an acceptable response if they do
33 template <class T, class... Args> std::shared_ptr<T> make_shared(Args&&... args)
35 #if defined(__COVERITY__)
36 return std::shared_ptr<T>(new T(std::forward<Args>(args)...), o3tl::default_delete<T>());
37 #else
38 return std::make_shared<T>(std::forward<Args>(args)...);
39 #endif
42 } // namespace o3tl
44 #endif // INCLUDED_O3TL_MAKE_SHARED_HXX
46 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */