1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
// -*- 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_COMMON_STD_MEMORY_HH
#define DUNE_COMMON_STD_MEMORY_HH
#include <memory>
#include <type_traits>
#include <dune/common/typeutilities.hh>
namespace Dune::Std {
#if __cpp_lib_to_address >= 201711L
using std::to_address;
#else
namespace Impl {
template <class T>
constexpr T* toAddressImpl (T* p, Dune::PriorityTag<2>) noexcept
{
static_assert(!std::is_function_v<T>);
return p;
}
template <class T>
constexpr auto toAddressImpl (const T& p, Dune::PriorityTag<1>) noexcept
-> decltype(std::pointer_traits<T>::to_address(p))
{
return std::pointer_traits<T>::to_address(p);
}
template <class T>
constexpr auto toAddressImpl (const T& p, Dune::PriorityTag<0>) noexcept
{
return toAddressImpl(p.operator->(), Dune::PriorityTag<3>{});
}
} // end namespace Impl
/// \brief Obtain the address represented by `p` without forming a reference to the object pointed to by `p`.
template <class T>
constexpr auto to_address(T&& p) noexcept
{
return Impl::toAddressImpl(std::forward<T>(p), Dune::PriorityTag<3>{});
}
#endif
} // end namespace Dune::Std
#endif // DUNE_COMMON_STD_MEMORY_HH
|