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 <o3tl/deleter.hxx>
14#include <memory>
15#include <type_traits>
16
17namespace o3tl
18{
23template <typename T> 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
33template <class T, class... Args> std::shared_ptr<T> make_shared(Args&&... args)
34{
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
40}
41
42} // namespace o3tl
43
44#endif // INCLUDED_O3TL_MAKE_SHARED_HXX
45
46/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
size
std::shared_ptr< T > make_shared(Args &&... args)
To markup std::shared_ptr that coverity warns might throw exceptions which won't throw in practice,...
Definition: make_shared.hxx:33
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
args
To markup std::unique_ptr that coverity warns might throw exceptions which won't throw in practice,...
Definition: deleter.hxx:45