mCRL2
Loading...
Searching...
No Matches
type_traits.h
Go to the documentation of this file.
1// Author(s): Wieger Wesselink, Maurice Laveaux
2// Copyright: see the accompanying file COPYING or copy at
3// https://github.com/mCRL2org/mCRL2/blob/master/COPYING
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//
9
10#ifndef MCRL2_UTILITIES_TYPE_TRAITS_H
11#define MCRL2_UTILITIES_TYPE_TRAITS_H
12
13#include <type_traits>
14#include <functional>
15
16namespace mcrl2::utilities
17{
18
20template <typename T, typename = void>
21struct is_iterable : std::false_type {};
22
23template <typename T>
24struct is_iterable<T, std::void_t<decltype(std::begin(std::declval<T>())),
25 decltype(std::end(std::declval<T>()))
26 >
27 > : std::true_type {};
28
30template<typename T, typename = void>
31struct is_iterator : std::false_type {};
32
33template<typename T>
34struct is_iterator<T, typename std::enable_if<!std::is_same<typename std::iterator_traits<T>::value_type, void>::value>::type>
35 : std::true_type
36{};
37
39template<typename... Conds>
40struct forall: std::true_type
41{};
42
43template<typename Cond, typename... Conds>
44struct forall<Cond, Conds...>
45 : std::conditional<Cond::value, forall<Conds...>, std::false_type>::type
46{};
47
48// Helpers
49template <typename T>
51
52template <typename T>
54
55template <typename FunctionType, typename ResultType, typename = void>
57 : public std::false_type
58{
59};
60
61template <typename FunctionType, typename ResultType>
62struct is_constant_function_yielding<FunctionType, ResultType,
63 typename std::is_convertible<typename std::result_of<FunctionType()>::type, ResultType> >
64 : public std::true_type
65{};
66
67template <typename FunctionType, typename ArgumentType, typename = void>
69 : public std::false_type
70{
71};
72
73template <typename FunctionType, typename ArgumentType>
74struct is_applicable<FunctionType, ArgumentType,
75 typename std::result_of<FunctionType(ArgumentType)>::type>
76 : public std::true_type
77{};
78
79template <typename FunctionType, typename ArgumentType1, typename ArgumentType2, typename = void>
81 : public std::false_type
82{
83};
84
85template <typename FunctionType, typename ArgumentType1, typename ArgumentType2>
86struct is_applicable2<FunctionType, ArgumentType1, ArgumentType2,
87 typename std::result_of<FunctionType(ArgumentType1,ArgumentType2)>::type>
88 : public std::true_type
89{};
90
91template <typename T>
93 : public function_traits<decltype(&T::operator())>
94{};
95// For generic types, directly use the result of the signature of its 'operator()'
96
97template <typename ClassType, typename ReturnType, typename... Args>
98struct function_traits<ReturnType(ClassType::*)(Args...) const>
99// we specialize for pointers to member function
100{
101 enum { arity = sizeof...(Args) };
102 // arity is the number of arguments.
103
104 typedef ReturnType result_type;
105
106 template <size_t i>
107 struct arg
108 {
109 typedef typename std::tuple_element<i, std::tuple<Args...>>::type type;
110 // the i-th argument is equivalent to the i-th tuple element of a tuple
111 // composed of those arguments.
112 };
113};
114
115} // namespace mcrl2::utilities
116
117#endif // MCRL2_UTILITIES_TYPE_TRAITS_H
constexpr bool is_iterable_v
Definition type_traits.h:50
constexpr bool is_iterator_v
Definition type_traits.h:53
STL namespace.
Checks whether condition holds for all types passed as variadic template.
Definition type_traits.h:41
A typetrait that is std::true_type iff std::begin() and std::end() can be called on type T.
Definition type_traits.h:21
A typetrait that is std::true_type iff the given type has the iterator traits.
Definition type_traits.h:31