5#ifndef DUNE_TYPETRAITS_HH
6#define DUNE_TYPETRAITS_HH
39 template <
class... Types>
63 template<
class T1,
class T2>
70 constexpr static bool value = std::is_convertible<T1,T2>::value || std::is_convertible<T2,T1>::value;
78 template<
class T1,
class T2,
class Type>
80 :
public std::enable_if<IsInteroperable<T1,T2>::value, Type>
100 typedef void FrobnicateType;
103 This will trigger static_assert() as soon as the compiler reads the
104 definition for the Traits template, since it knows that "false" can
105 never become true, no matter what the template parameters of Traits are.
106 As a workaround you can use AlwaysFalse: replace <tt>false</tt> by
107 <tt>AlwaysFalse<T>::value</tt>, like this:
111 static_assert(AlwaysFalse<T>::value,
112 "Instantiating this non-specialized template is an "
113 "error. You should use one of the specializations "
116 typedef void FrobnicateType;
119 Since there might be an specialization of AlwaysFalse for template
120 parameter T, the compiler cannot trigger static_assert() until the
121 type of T is known, that is, until Traits<T> is instantiated.
161 template<
typename D,
typename R =
void>
168 template<
typename R,
typename F,
typename... Args>
170 :
public std::bool_constant<
171 std::is_invocable_r_v<R, F, Args...>
172 && !std::is_member_pointer_v<std::decay_t<F>>
192 template <
typename T>
194 :
public std::integral_constant<bool, std::is_arithmetic<T>::value> {
199 template <
typename T>
201 :
public std::integral_constant<bool, IsNumber<T>::value> {
210 template <
typename T>
212 :
public std::integral_constant<bool, std::is_floating_point<T>::value> {
217 template <
typename T>
219 :
public std::integral_constant<bool, std::is_floating_point<T>::value> {
228 template<
typename T,
typename I,
typename =
int>
230 :
public std::false_type
233 template<
typename T,
typename I>
234 struct IsIndexable<T,I,typename std::enable_if<(sizeof(std::declval<T>()[std::declval<I>()]) > 0),int>
::type>
235 :
public std::true_type
247 template<
typename T,
typename I = std::
size_t>
249 :
public Impl::IsIndexable<T,I>
270 template<
typename T,
typename =
void>
272 :
public std::false_type
279 std::declval<T>().begin(),
280 std::declval<T>().end(),
281 std::declval<T>().begin() != std::declval<T>().end(),
282 decltype(std::declval<T>().begin()){std::declval<T>().end()},
283 ++(std::declval<std::add_lvalue_reference_t<decltype(std::declval<T>().begin())>>()),
284 *(std::declval<T>().begin())
286 :
public std::true_type
292 template <
class>
struct FieldTraits;
296 template <
class Type>
300 template <
class Type>
310 struct IsTuple :
public std::false_type
314 struct IsTuple<
std::tuple<T...>> :
public std::true_type
328 public Impl::IsTuple<T>
337 template<
class... T,
class Dummy>
338 std::true_type isTupleOrDerived(
const std::tuple<T...>*, Dummy)
341 template<
class Dummy>
342 std::false_type isTupleOrDerived(
const void*, Dummy)
356 public decltype(Impl::isTupleOrDerived(std::declval<T*>(), true))
369 template<
class T, T t>
370 struct IsIntegralConstant<
std::integral_constant<T, t>> :
public std::true_type
393 template <
class T, T value>
394 static std::true_type check(std::integral_constant<T,value>);
395 static std::false_type check(...);
410 :
public decltype(Impl::IsCompileTimeConstant::check(std::declval<T>()))
430 template<
typename... T>
432 [[deprecated(
"This class is deprecated and will be removed after Dune 2.10. Use sizeof...(T) instead.")]]
434 :
public std::integral_constant<std::size_t,
sizeof...(T)>
442 template<
class T, T...>
443 struct IntegerSequenceHelper;
451 template<
class T, T
head, T...
tail>
452 struct IntegerSequenceHelper<T,
head,
tail...>
456 static constexpr auto get(std::integral_constant<std::size_t, 0>)
458 return std::integral_constant<T, head>();
462 template<std::size_t index,
463 std::enable_if_t<(index > 0) and (index <
sizeof...(tail)+1),
int> = 0>
464 static constexpr auto get(std::integral_constant<std::size_t, index>)
466 return IntegerSequenceHelper<T, tail...>::get(std::integral_constant<std::size_t, index-1>());
470 template<std::size_t index,
471 std::enable_if_t<(index >=
sizeof...(tail)+1),
int> = 0>
472 static constexpr auto get(std::integral_constant<std::size_t, index>)
474 static_assert(index <
sizeof...(tail)+1,
"index used in IntegerSequenceEntry exceed size");
491 template<
class T, T... t, std::size_t index>
492 constexpr auto integerSequenceEntry(std::integer_sequence<T, t...> , std::integral_constant<std::size_t, index> i)
494 static_assert(index <
sizeof...(t),
"index used in IntegerSequenceEntry exceed size");
495 return Impl::IntegerSequenceHelper<T, t...>::get(i);
505 template<
class IntegerSequence, std::
size_t index>
510 template<
class T, T... t, std::size_t i>
512 :
public decltype(Impl::IntegerSequenceHelper<T, t...>::get(std::integral_constant<std::size_t, i>()))
constexpr auto integerSequenceEntry(std::integer_sequence< T, t... >, std::integral_constant< std::size_t, index > i)
Get entry of std::integer_sequence.
Definition typetraits.hh:492
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
typename FieldTraits< Type >::real_type real_t
Convenient access to FieldTraits<Type>::real_type.
Definition typetraits.hh:301
typename FieldTraits< Type >::field_type field_t
Convenient access to FieldTraits<Type>::field_type.
Definition typetraits.hh:297
constexpr AutonomousValue< T > autoCopy(T &&v)
Autonomous copy of an expression's value for use in auto type deduction.
Definition typetraits.hh:672
typename AutonomousValueType< T >::type AutonomousValue
Type free of internal references that T can be converted to.
Definition typetraits.hh:588
MPI_Datatype MPITraits< ParallelLocalIndex< T > >::type
Definition plocalindex.hh:317
Dune namespace.
Definition alignedallocator.hh:13
constexpr std::integer_sequence< T, II... > tail(std::integer_sequence< T, I0, II... >)
For a sequence [head,tail...) return the tail sequence.
Definition integersequence.hh:58
constexpr std::integral_constant< T, I0 > head(std::integer_sequence< T, I0, II... >)
For a sequence [head,tail...) return the single head element.
Definition integersequence.hh:53
constexpr auto get(std::integer_sequence< T, II... >, std::integral_constant< std::size_t, pos >={})
Return the entry at position pos of the given sequence.
Definition integersequence.hh:22
Whether this type acts as a scalar in the context of (hierarchically blocked) containers.
Definition typetraits.hh:194
T field_type
export the type representing the field
Definition ftraits.hh:28
T real_type
export the type representing the real type of the field
Definition ftraits.hh:30
Just an empty class.
Definition typetraits.hh:55
Checks whether two types are interoperable.
Definition typetraits.hh:65
static constexpr bool value
True if either a conversion from T1 to T2 or vice versa exists.
Definition typetraits.hh:70
Enable typedef if two types are interoperable.
Definition typetraits.hh:81
template which always yields a false value
Definition typetraits.hh:124
template which always yields a true value
Definition typetraits.hh:134
Check if a type is callable with ()-operator and given arguments.
Definition typetraits.hh:162
Whether this type has a value of NaN.
Definition typetraits.hh:212
Type trait to determine whether an instance of T has an operator[](I), i.e. whether it can be indexed...
Definition typetraits.hh:250
typetrait to check that a class has begin() and end() members
Definition typetraits.hh:273
Check if T is a std::tuple<...>.
Definition typetraits.hh:329
Check if T derived from a std::tuple<...>.
Definition typetraits.hh:357
Check if T is an std::integral_constant<I, i>.
Definition typetraits.hh:384
Check if T is an integral constant or any type derived from std::integral_constant.
Definition typetraits.hh:411
Compute size of variadic type list.
Definition typetraits.hh:435
Get entry of std::integer_sequence.
Definition typetraits.hh:506
Type free of internal references that T can be converted to.
Definition typetraits.hh:531
T type
Definition typetraits.hh:531
bool type
Definition typetraits.hh:553