Loading...
Searching...
No Matches
referencehelper.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_COMMON_REFERENCE_HELPER_HH
#define DUNE_COMMON_REFERENCE_HELPER_HH
#include <type_traits>
#include <functional>
namespace Dune {
namespace Impl {
template<class T>
class IsReferenceWrapper : public std::false_type {};
template<class T>
class IsReferenceWrapper<std::reference_wrapper<T>> : public std::true_type {};
template<class T>
class IsReferenceWrapper<const std::reference_wrapper<T>> : public std::true_type {};
} // namespace Dune::Impl
template<class T>
constexpr bool IsReferenceWrapper_v = Impl::IsReferenceWrapper<T>::value;
template<class T>
constexpr T& resolveRef(T& gf) noexcept
{
return gf;
}
// There's no overload for non std::reference_wrapper r-values,
// because this may lead to undefined behavior whenever the
// return value is stored.
// Notice that deleting the overload is not necessary, but
// helps to document that it is missing on purpose. It also
// leads to nicer error messages.
template<class T>
const auto& resolveRef(T&& gf) = delete;
template<class T>
constexpr T& resolveRef(std::reference_wrapper<T> gf) noexcept
{
return gf.get();
}
template<class T>
using ResolveRef_t = std::remove_reference_t<decltype(Dune::resolveRef(std::declval<T&>()))>;
} // namespace Dune
#endif // DUNE_COMMON_REFERENCE_HELPER_HH
Dune::ResolveRef_t
std::remove_reference_t< decltype(Dune::resolveRef(std::declval< T & >()))> ResolveRef_t
Type trait to resolve std::reference_wrapper.
Definition referencehelper.hh:100
Dune::IsReferenceWrapper_v
constexpr bool IsReferenceWrapper_v
Helper to detect if given type is a std::reference_wrapper.
Definition referencehelper.hh:35
Dune::resolveRef
constexpr T & resolveRef(T &gf) noexcept
Helper function to resolve std::reference_wrapper.
Definition referencehelper.hh:47
Dune
Dune namespace
Definition alignedallocator.hh:13