Loading...
Searching...
No Matches
type_traits.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_STD_TYPE_TRAITS_HH
#define DUNE_COMMON_STD_TYPE_TRAITS_HH
#include <type_traits>
#include <dune-common-config.hh> // DUNE_HAVE_CXX_EXPERIMENTAL_IS_DETECTED
#include <dune/common/typetraits.hh>
#include <dune/common/typeutilities.hh>
#if DUNE_HAVE_CXX_EXPERIMENTAL_IS_DETECTED
#include <experimental/type_traits>
#endif
namespace Dune
{
namespace Std
{
#if DUNE_HAVE_CXX_EXPERIMENTAL_IS_DETECTED
using std::experimental::nonesuch;
using std::experimental::detected_or;
using std::experimental::is_detected;
using std::experimental::detected_t;
using std::experimental::is_detected_v;
using std::experimental::detected_or_t;
using std::experimental::is_detected_exact;
using std::experimental::is_detected_exact_v;
using std::experimental::is_detected_convertible;
using std::experimental::is_detected_convertible_v;
#else // DUNE_HAVE_CXX_EXPERIMENTAL_IS_DETECTED
// fallback version of std::experimental::is_detected et al., heavily scribbled
// from cppreference.com (but there is actually not much implementation to the thing)
#ifndef DOXYGEN
namespace Impl {
// default version of detector, this gets matched on failure
template<typename Default, typename Void, template<typename...> class Op, typename... Args>
struct detector
{
using value_t = std::false_type;
using type = Default;
};
// specialization of detector that matches if Op<Args...> can be instantiated
template<typename Default, template<typename...> class Op, typename... Args>
struct detector<Default, std::void_t<Op<Args...>>, Op, Args...>
{
using value_t = std::true_type;
using type = Op<Args...>;
};
}
#endif // DOXYGEN
struct nonesuch
{
nonesuch() = delete;
~nonesuch() = delete;
nonesuch(const nonesuch&) = delete;
void operator=(const nonesuch&) = delete;
};
template<typename Default, template<typename...> class Op, typename... Args>
using detected_or = Impl::detector<Default,void,Op,Args...>;
template<template<typename...> class Op, typename... Args>
using is_detected = typename detected_or<nonesuch,Op,Args...>::value_t;
#ifdef __cpp_variable_templates
template<template<typename...> class Op, typename... Args>
constexpr bool is_detected_v = is_detected<Op,Args...>::value;
#endif // __cpp_variable_templates
template<template<typename...> class Op, typename... Args>
using detected_t = typename detected_or<nonesuch,Op,Args...>::type;
template<typename Default, template<typename...> class Op, typename... Args>
using detected_or_t = typename detected_or<Default,Op,Args...>::type;
template<typename Expected, template<typename...> class Op, typename... Args>
using is_detected_exact = std::is_same<Expected,detected_t<Op,Args...>>;
#ifdef __cpp_variable_templates
template<typename Expected, template<typename...> class Op, typename... Args>
constexpr bool is_detected_exact_v = is_detected_exact<Expected,Op,Args...>::value;
#endif // __cpp_variable_templates
template<typename Target, template<typename...> class Op, typename... Args>
using is_detected_convertible = std::is_convertible<Target,detected_t<Op,Args...>>;
#ifdef __cpp_variable_templates
template<typename Target, template<typename...> class Op, typename... Args>
constexpr bool is_detected_convertible_v = is_detected_convertible<Target,Op,Args...>::value;
#endif // __cpp_variable_templates
#endif // DUNE_HAVE_CXX_EXPERIMENTAL_IS_DETECTED
} // namespace Std
namespace detail
{
template <class Type>
[[deprecated("Type extraction of `TargetType` has failed. Inspect the code calling `detected_or_fallback_t` for getting the source of this warning!")]]
Type warningIfNotDefined(const Std::nonesuch*);
template <class Type, class T>
Type warningIfNotDefined(const T*);
}
template <template<typename...> class Fallback,
template<typename...> class TargetType, typename... Args>
using detected_or_fallback_t = Std::detected_or_t<decltype(
detail::warningIfNotDefined<Std::detected_t<Fallback, Args...> >(std::declval<const Std::detected_t<TargetType, Args...>*>())),
TargetType, Args...>;
} // namespace Dune
#endif // #ifndef DUNE_COMMON_STD_TYPE_TRAITS_HH
typetraits.hh
Traits for type conversions and type information.
typeutilities.hh
Utilities for type computations, constraining overloads, ...
Dune::void_t
typename Impl::voider< Types... >::type void_t
Is void for all valid input types. The workhorse for C++11 SFINAE-techniques.
Definition typetraits.hh:40
Dune::Std::detected_t
typename detected_or< nonesuch, Op, Args... >::type detected_t
Returns Op<Args...> if that is valid; otherwise returns nonesuch.
Definition type_traits.hh:170
Dune::Std::detected_or
Impl::detector< Default, void, Op, Args... > detected_or
Detects whether Op<Args...> is valid and makes the result available.
Definition type_traits.hh:128
Dune::Std::is_detected_convertible
std::is_convertible< Target, detected_t< Op, Args... > > is_detected_convertible
Checks whether Op<Args...> is convertible to Target without causing an error if Op<Args....
Definition type_traits.hh:217
Dune::Std::is_detected
typename detected_or< nonesuch, Op, Args... >::value_t is_detected
Detects whether Op<Args...> is valid.
Definition type_traits.hh:141
Dune::Std::detected_or_t
typename detected_or< Default, Op, Args... >::type detected_or_t
Returns Op<Args...> if that is valid; otherwise returns the fallback type Default.
Definition type_traits.hh:185
Dune::Std::is_detected_exact
std::is_same< Expected, detected_t< Op, Args... > > is_detected_exact
Checks whether Op<Args...> is Expected without causing an error if Op<Args...> is invalid.
Definition type_traits.hh:195
Dune
Dune namespace
Definition alignedallocator.hh:13
Dune::detected_or_fallback_t
Std::detected_or_t< decltype( detail::warningIfNotDefined< Std::detected_t< Fallback, Args... > >(std::declval< const Std::detected_t< TargetType, Args... > * >())), TargetType, Args... > detected_or_fallback_t
This type will be either TargetType<Args...> if it exists, or the Fallback<Args......
Definition type_traits.hh:249
Dune::Std
Namespace for features backported from new C++ standards.
Definition algorithm.hh:19
Dune::Std::nonesuch
Type representing a lookup failure by std::detected_or and friends.
Definition type_traits.hh:85
Dune::Std::nonesuch::nonesuch
nonesuch()=delete
Dune::Std::nonesuch::nonesuch
nonesuch(const nonesuch &)=delete
Dune::Std::nonesuch::operator=
void operator=(const nonesuch &)=delete
Dune::Std::nonesuch::~nonesuch
~nonesuch()=delete
Dune::type