Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
type_traits.hpp
Go to the documentation of this file.
1
6/*
7 * This file is part of Algorithms library toolkit.
8 * Copyright (C) 2017 Jan Travnicek (jan.travnicek@fit.cvut.cz)
9
10 * Algorithms library toolkit is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14
15 * Algorithms library toolkit is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19
20 * You should have received a copy of the GNU General Public License
21 * along with Algorithms library toolkit. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24#pragma once
25
26#include <type_traits>
27#include <utility>
28#include <cstdlib>
29
30namespace ext {
31
38 template<class T>
39 struct has_clone {
40 private:
41 template < class U >
42 static std::true_type test ( U * data )
43 requires ( std::is_pointer_v < decltype ( data->clone ( ) ) > );
44 static std::false_type test ( ... );
45 public:
50 static const bool value = decltype ( has_clone::test ( std::declval < std::decay_t < T > * > ( ) ) )::value;
51 };
52
53
63 template < class F, class ... Ts, typename = decltype ( std::declval < F > ( ) ( std::declval < Ts > ( ) ... ) ) >
64 std::true_type supports_test ( const F &, const Ts & ... );
65
72 std::false_type supports_test ( ... );
73
77 template < class > struct supports;
78
87 template < class F, class ... Ts > struct supports < F ( Ts ... ) > : decltype ( supports_test ( std::declval < F > ( ), std::declval < Ts > ( ) ... ) ) { };
88
89// ----------------------------------------------------------------------------------------------------
90
98 template < typename T, typename ... Ts >
99 using is_in = std::integral_constant < bool, ( std::is_same < T, Ts >::value || ... ) >;
100
101// ----------------------------------------------------------------------------------------------------
102
110 template < typename T, typename ... Ts >
111 struct index_in;
112
119 template < typename T >
120 struct index_in < T > : std::integral_constant < size_t, 0 > { };
121
128 template < typename T, typename U, typename ... Ts >
129 struct index_in < T, U, Ts ... > : std::integral_constant < size_t, index_in < T, Ts ... >::value + 1 > { };
130
139 template < typename T, typename ... Ts >
140 struct index_in < T, T, Ts ... > : std::integral_constant < size_t, 0 > { };
141
142// ----------------------------------------------------------------------------------------------------
143
144 template < bool value>
145 using boolean = typename std::conditional < value, std::true_type, std::false_type >::type;
146
147 template < class ... Ts >
148 struct casional;
149
150 template < >
151 struct casional < > {
152 typedef void type;
153 };
154
155 template < class T >
156 struct casional < T > {
157 typedef T type;
158 };
159
160 template < class R, class ... Ts >
161 struct casional < std::true_type, R, Ts ... > : public casional < R > {
162 };
163
164 template < class R, class ... Ts >
165 struct casional < std::false_type, R, Ts ... > : public casional < Ts ... > {
166 };
167
168 // Helper which adds a reference to a type when given a reference_wrapper
169 template < typename T >
171 typedef T type;
172 };
173
174 template < typename T >
176 typedef T & type;
177 };
178
179} /* namespace ext */
180
Class extending the reference wrapper class from the standard library. Original reason is to allow it...
Definition: functional.hpp:108
Definition: sigHandler.cpp:20
std::true_type supports_test(const F &, const Ts &...)
Positive supports test implementation. The test is designed to detect call availability on callable F...
std::integral_constant< bool,(std::is_same< T, Ts >::value||...) > is_in
Trait to test whether type T is in a types pack. The trait provides field value set to true if the ty...
Definition: type_traits.hpp:99
Definition: FordFulkerson.hpp:16
T type
Definition: type_traits.hpp:157
void type
Definition: type_traits.hpp:152
Definition: type_traits.hpp:148
Type trait to determine existence of clone method. A boolean field namd value is set to true if provi...
Definition: type_traits.hpp:39
static const bool value
True if the type decayed type T has clone method.
Definition: type_traits.hpp:50
Trait to get index of type T is in a types pack. The trait provides field value set to an integral va...
Definition: type_traits.hpp:111
Definition: type_traits.hpp:170
T type
Definition: type_traits.hpp:171
Definition: type_traits.hpp:77