Loading...
Searching...
No Matches
shared_ptr.hh
Go to the documentation of this file.
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
#ifndef DUNE_SHARED_PTR_HH
#define DUNE_SHARED_PTR_HH
#include <memory>
#include <dune/common/typetraits.hh>
namespace Dune
{
template<class T>
struct null_deleter
{
void operator() (T*) const {}
};
template<typename T>
inline std::shared_ptr<T> stackobject_to_shared_ptr(T & t)
{
return std::shared_ptr<T>(&t, null_deleter<T>());
}
template<class T>
auto wrap_or_move(T&& t)
{
return std::make_shared<std::decay_t<T>>(std::forward<T>(t));
}
template<class T>
auto wrap_or_move(T& t)
{
return stackobject_to_shared_ptr(t);
}
}
#endif
typetraits.hh
Traits for type conversions and type information.
Dune
Dune namespace
Definition alignedallocator.hh:13
Dune::stackobject_to_shared_ptr
std::shared_ptr< T > stackobject_to_shared_ptr(T &t)
Create a shared_ptr for a stack-allocated object.
Definition shared_ptr.hh:72
Dune::wrap_or_move
auto wrap_or_move(T &&t)
Capture R-value reference to shared_ptr.
Definition shared_ptr.hh:96
Dune::null_deleter
implements the Deleter concept of shared_ptr without deleting anything
Definition shared_ptr.hh:49
Dune::null_deleter::stackobject_to_shared_ptr
std::shared_ptr< T > stackobject_to_shared_ptr(T &t)
Create a shared_ptr for a stack-allocated object.
Definition shared_ptr.hh:72
Dune::null_deleter::operator()
void operator()(T *) const
Definition shared_ptr.hh:50