Intel(R) Threading Building Blocks Doxygen Documentation version 4.2.3
_template_helpers.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2005-2020 Intel Corporation
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17#ifndef __TBB_template_helpers_H
18#define __TBB_template_helpers_H
19
20#include <utility>
21#include <cstddef>
22#include "../tbb_config.h"
23#if __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT && __TBB_CPP11_TEMPLATE_ALIASES_PRESENT
24#include <type_traits>
25#endif
26#if __TBB_CPP11_PRESENT
27#include <iterator>
28#include <memory> // allocator_traits
29#endif
30
31namespace tbb { namespace internal {
32
34template<bool Condition, typename T = void> struct enable_if {};
35template<typename T> struct enable_if<true, T> { typedef T type; };
36
38template<typename T> struct strip { typedef T type; };
39template<typename T> struct strip<const T> { typedef T type; };
40template<typename T> struct strip<volatile T> { typedef T type; };
41template<typename T> struct strip<const volatile T> { typedef T type; };
42template<typename T> struct strip<T&> { typedef T type; };
43template<typename T> struct strip<const T&> { typedef T type; };
44template<typename T> struct strip<volatile T&> { typedef T type; };
45template<typename T> struct strip<const volatile T&> { typedef T type; };
47template<typename T> struct strip<T(&)()> { typedef T(*type)(); };
48#if __TBB_CPP11_RVALUE_REF_PRESENT
49template<typename T> struct strip<T&&> { typedef T type; };
50template<typename T> struct strip<const T&&> { typedef T type; };
51template<typename T> struct strip<volatile T&&> { typedef T type; };
52template<typename T> struct strip<const volatile T&&> { typedef T type; };
53#endif
55template<typename T, std::size_t N> struct strip<T(&)[N]> { typedef T* type; };
56template<typename T, std::size_t N> struct strip<const T(&)[N]> { typedef const T* type; };
57template<typename T, std::size_t N> struct strip<volatile T(&)[N]> { typedef volatile T* type; };
58template<typename T, std::size_t N> struct strip<const volatile T(&)[N]> { typedef const volatile T* type; };
59
61template<class U, class V> struct is_same_type { static const bool value = false; };
62template<class W> struct is_same_type<W,W> { static const bool value = true; };
63
64template<typename T> struct is_ref { static const bool value = false; };
65template<typename U> struct is_ref<U&> { static const bool value = true; };
66
68template<typename T> struct is_integral_impl { static const bool value = false; };
69template<> struct is_integral_impl<bool> { static const bool value = true; };
70template<> struct is_integral_impl<char> { static const bool value = true; };
71#if __TBB_CPP11_PRESENT
72template<> struct is_integral_impl<char16_t> { static const bool value = true; };
73template<> struct is_integral_impl<char32_t> { static const bool value = true; };
74#endif
75template<> struct is_integral_impl<wchar_t> { static const bool value = true; };
76template<> struct is_integral_impl<short> { static const bool value = true; };
77template<> struct is_integral_impl<int> { static const bool value = true; };
78template<> struct is_integral_impl<long> { static const bool value = true; };
79template<> struct is_integral_impl<long long> { static const bool value = true; };
80
81template<typename T>
82struct is_integral : is_integral_impl<typename strip<T>::type> {};
83
84#if __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT
86template<typename...> struct void_t { typedef void type; };
87#endif
88
89#if __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT && __TBB_CPP11_TEMPLATE_ALIASES_PRESENT
90
91// Generic SFINAE helper for expression checks, based on the idea demonstrated in ISO C++ paper n4502
92template<typename T, typename, template<typename> class... Checks>
94template<typename T, template<typename> class... Checks>
95struct supports_impl<T, typename void_t<Checks<T>...>::type, Checks...> { typedef std::true_type type; };
96
97template<typename T, template<typename> class... Checks>
98using supports = typename supports_impl<T, void, Checks...>::type;
99
100#endif /* __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT && __TBB_CPP11_TEMPLATE_ALIASES_PRESENT */
101
102#if __TBB_CPP11_RVALUE_REF_PRESENT && __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT
103
105template< typename... Types >
107
108template<>
110{
113
114 // Friend front-end functions
115 template< typename F, typename Pack > friend void call( F&& f, Pack&& p );
116 template< typename Ret, typename F, typename Pack > friend Ret call_and_return( F&& f, Pack&& p );
117
118protected:
119 // Ideally, ref-qualified non-static methods would be used,
120 // but that would greatly reduce the set of compilers where it works.
121 template< typename Ret, typename F, typename... Preceding >
122 static Ret call( F&& f, const pack_type& /*pack*/, Preceding&&... params ) {
123 return std::forward<F>(f)( std::forward<Preceding>(params)... );
124 }
125 template< typename Ret, typename F, typename... Preceding >
126 static Ret call( F&& f, pack_type&& /*pack*/, Preceding&&... params ) {
127 return std::forward<F>(f)( std::forward<Preceding>(params)... );
128 }
129};
130
131template< typename T, typename... Types >
132struct stored_pack<T, Types...> : stored_pack<Types...>
133{
134 typedef stored_pack<T, Types...> pack_type;
135 typedef stored_pack<Types...> pack_remainder;
136 // Since lifetime of original values is out of control, copies should be made.
137 // Thus references should be stripped away from the deduced type.
139
140 // Here rvalue references act in the same way as forwarding references,
141 // as long as class template parameters were deduced via forwarding references.
142 stored_pack( T&& t, Types&&... types )
143 : pack_remainder(std::forward<Types>(types)...), leftmost_value(std::forward<T>(t)) {}
144
145 // Friend front-end functions
146 template< typename F, typename Pack > friend void call( F&& f, Pack&& p );
147 template< typename Ret, typename F, typename Pack > friend Ret call_and_return( F&& f, Pack&& p );
148
149protected:
150 template< typename Ret, typename F, typename... Preceding >
151 static Ret call( F&& f, pack_type& pack, Preceding&&... params ) {
152 return pack_remainder::template call<Ret>(
153 std::forward<F>(f), static_cast<pack_remainder&>(pack),
154 std::forward<Preceding>(params)... , pack.leftmost_value
155 );
156 }
157 template< typename Ret, typename F, typename... Preceding >
158 static Ret call( F&& f, const pack_type& pack, Preceding&&... params ) {
159 return pack_remainder::template call<Ret>(
160 std::forward<F>(f), static_cast<const pack_remainder&>(pack),
161 std::forward<Preceding>(params)... , pack.leftmost_value
162 );
163 }
164 template< typename Ret, typename F, typename... Preceding >
165 static Ret call( F&& f, pack_type&& pack, Preceding&&... params ) {
166 return pack_remainder::template call<Ret>(
167 std::forward<F>(f), static_cast<pack_remainder&&>(pack),
168 std::forward<Preceding>(params)... , std::move(pack.leftmost_value)
169 );
170 }
171};
172
174template< typename F, typename Pack >
175void call( F&& f, Pack&& p ) {
176 strip<Pack>::type::template call<void>( std::forward<F>(f), std::forward<Pack>(p) );
177}
178
179template< typename Ret, typename F, typename Pack >
180Ret call_and_return( F&& f, Pack&& p ) {
181 return strip<Pack>::type::template call<Ret>( std::forward<F>(f), std::forward<Pack>(p) );
182}
183
184template< typename... Types >
185stored_pack<Types...> save_pack( Types&&... types ) {
186 return stored_pack<Types...>( std::forward<Types>(types)... );
187}
188
189#endif /* __TBB_CPP11_RVALUE_REF_PRESENT && __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT */
190
191#if __TBB_CPP14_INTEGER_SEQUENCE_PRESENT
192
193using std::index_sequence;
195
196#elif __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT && __TBB_CPP11_TEMPLATE_ALIASES_PRESENT
197
198template<std::size_t... S> class index_sequence {};
199
200template<std::size_t N, std::size_t... S>
201struct make_index_sequence_impl : make_index_sequence_impl < N - 1, N - 1, S... > {};
202
203template<std::size_t... S>
205 using type = index_sequence<S...>;
206};
207
208template<std::size_t N>
210
211#endif /* __TBB_CPP14_INTEGER_SEQUENCE_PRESENT */
212
213#if __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT
214template<typename... Args>
216
217template<typename First, typename... Args>
218struct conjunction<First, Args...>
219 : std::conditional<bool(First::value), conjunction<Args...>, First>::type {};
220
221template<typename T>
222struct conjunction<T> : T {};
223
224template<>
226
227#endif
228
229#if __TBB_CPP11_PRESENT
230
231template< typename Iter >
232using iterator_value_t = typename std::iterator_traits<Iter>::value_type;
233
234template< typename Iter >
235using iterator_key_t = typename std::remove_const<typename iterator_value_t<Iter>::first_type>::type;
236
237template< typename Iter >
238using iterator_mapped_t = typename iterator_value_t<Iter>::second_type;
239
240template< typename A > using value_type = typename A::value_type;
241template< typename A > using alloc_ptr_t = typename std::allocator_traits<A>::pointer;
242template< typename A > using has_allocate = decltype(std::declval<alloc_ptr_t<A>&>() = std::declval<A>().allocate(0));
243template< typename A > using has_deallocate = decltype(std::declval<A>().deallocate(std::declval<alloc_ptr_t<A>>(), 0));
244
245// value_type should be checked first because it can be used in other checks (via allocator_traits)
246template< typename T >
248
249#if __TBB_CPP14_VARIABLE_TEMPLATES_PRESENT
250
251template< typename T >
252static constexpr bool is_allocator_v = is_allocator<T>::value;
253
254#endif /*__TBB_CPP14_VARIABLE_TEMPLATES */
255
256template< std::size_t N, typename... Args >
257struct pack_element {
258 using type = void;
259};
260
261template< std::size_t N, typename T, typename... Args >
262struct pack_element<N, T, Args...> {
263 using type = typename pack_element<N - 1, Args...>::type;
264};
265
266template< typename T, typename... Args >
267struct pack_element<0, T, Args...> {
268 using type = T;
269};
270
271template< std::size_t N, typename... Args >
272using pack_element_t = typename pack_element<N, Args...>::type;
273
274// Helper alias for heterogeneous lookup functions in containers
275// template parameter K and std::conditional are needed to provide immediate context
276// and postpone getting is_trasparent from the compare functor until method instantiation.
277template <typename Comp, typename K>
278using is_transparent = typename std::conditional<true, Comp, K>::type::is_transparent;
279
280#endif /* __TBB_CPP11_PRESENT */
281
282template <typename F>
284
285template <typename Callable, typename ReturnType, typename T>
286struct body_arg_detector<ReturnType(Callable::*)(T)> {
287 typedef T arg_type;
288};
289
290template <typename Callable, typename ReturnType, typename T>
291struct body_arg_detector<ReturnType(Callable::*)(T) const> {
292 typedef T arg_type;
293};
294
295#if __TBB_CPP11_PRESENT
296using std::conditional;
297#else
298template <bool C, typename T, typename U>
300 typedef U type;
301};
302
303template <typename T, typename U>
304struct conditional<true, T, U> {
305 typedef T type;
306};
307#endif
308
309} } // namespace internal, namespace tbb
310
311#endif /* __TBB_template_helpers_H */
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle __itt_metadata_type size_t void ITT_FORMAT p const __itt_domain __itt_id __itt_string_handle const wchar_t size_t ITT_FORMAT lu const __itt_domain __itt_id __itt_relation __itt_id ITT_FORMAT p const wchar_t int ITT_FORMAT __itt_group_mark S
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long value
void const char const char int ITT_FORMAT __itt_group_sync p
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle __itt_metadata_type size_t void ITT_FORMAT p const __itt_domain __itt_id __itt_string_handle const wchar_t size_t ITT_FORMAT lu const __itt_domain __itt_id __itt_relation __itt_id ITT_FORMAT p const wchar_t int ITT_FORMAT __itt_group_mark d int
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle __itt_metadata_type type
STL namespace.
The graph class.
void move(tbb_thread &t1, tbb_thread &t2)
Definition: tbb_thread.h:319
stored_pack< Types... > save_pack(Types &&... types)
typename supports_impl< T, void, Checks... >::type supports
Ret call_and_return(F &&f, Pack &&p)
void call(F &&f, Pack &&p)
Calls the given function with arguments taken from a stored_pack.
bool_constant< false > false_type
Definition: tbb_stddef.h:490
typename tbb::internal::make_index_sequence_impl< N >::type make_index_sequence
bool_constant< true > true_type
Definition: tbb_stddef.h:489
Enables one or the other code branches.
Strips its template type argument from cv- and ref-qualifiers.
Detects whether two given types are the same.
static const bool value
Partial support for std::is_integral.
std::void_t internal implementation (to avoid GCC < 4.7 "template aliases" absence)
Allows to store a function parameter pack as a variable and later pass it to another function.
static Ret call(F &&f, const pack_type &, Preceding &&... params)
static Ret call(F &&f, pack_type &&, Preceding &&... params)
static Ret call(F &&f, pack_type &pack, Preceding &&... params)
static Ret call(F &&f, pack_type &&pack, Preceding &&... params)
static Ret call(F &&f, const pack_type &pack, Preceding &&... params)

Copyright © 2005-2020 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.