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-2018 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 
18 
19 */
20 
21 #ifndef __TBB_template_helpers_H
22 #define __TBB_template_helpers_H
23 
24 #include <utility>
25 #include <cstddef>
26 
27 namespace tbb { namespace internal {
28 
30 template<bool Condition, typename T = void> struct enable_if {};
31 template<typename T> struct enable_if<true, T> { typedef T type; };
32 
34 template<typename T> struct strip { typedef T type; };
35 template<typename T> struct strip<const T> { typedef T type; };
36 template<typename T> struct strip<volatile T> { typedef T type; };
37 template<typename T> struct strip<const volatile T> { typedef T type; };
38 template<typename T> struct strip<T&> { typedef T type; };
39 template<typename T> struct strip<const T&> { typedef T type; };
40 template<typename T> struct strip<volatile T&> { typedef T type; };
41 template<typename T> struct strip<const volatile T&> { typedef T type; };
43 template<typename T> struct strip<T(&)()> { typedef T(*type)(); };
44 #if __TBB_CPP11_RVALUE_REF_PRESENT
45 template<typename T> struct strip<T&&> { typedef T type; };
46 template<typename T> struct strip<const T&&> { typedef T type; };
47 template<typename T> struct strip<volatile T&&> { typedef T type; };
48 template<typename T> struct strip<const volatile T&&> { typedef T type; };
49 #endif
50 template<typename T, std::size_t N> struct strip<T(&)[N]> { typedef T* type; };
52 template<typename T, std::size_t N> struct strip<const T(&)[N]> { typedef const T* type; };
53 template<typename T, std::size_t N> struct strip<volatile T(&)[N]> { typedef volatile T* type; };
54 template<typename T, std::size_t N> struct strip<const volatile T(&)[N]> { typedef const volatile T* type; };
55 
57 template<class U, class V> struct is_same_type { static const bool value = false; };
58 template<class W> struct is_same_type<W,W> { static const bool value = true; };
59 
60 template<typename T> struct is_ref { static const bool value = false; };
61 template<typename U> struct is_ref<U&> { static const bool value = true; };
62 
63 #if __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT
64 template<typename...> struct void_t { typedef void type; };
66 #endif
67 
68 #if __TBB_CPP11_RVALUE_REF_PRESENT && __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT
69 
71 template< typename... Types >
72 struct stored_pack;
73 
74 template<>
75 struct stored_pack<>
76 {
79 
80  // Friend front-end functions
81  template< typename F, typename Pack > friend void call( F&& f, Pack&& p );
82  template< typename Ret, typename F, typename Pack > friend Ret call_and_return( F&& f, Pack&& p );
83 
84 protected:
85  // Ideally, ref-qualified non-static methods would be used,
86  // but that would greatly reduce the set of compilers where it works.
87  template< typename Ret, typename F, typename... Preceding >
88  static Ret call( F&& f, const pack_type& /*pack*/, Preceding&&... params ) {
89  return std::forward<F>(f)( std::forward<Preceding>(params)... );
90  }
91  template< typename Ret, typename F, typename... Preceding >
92  static Ret call( F&& f, pack_type&& /*pack*/, Preceding&&... params ) {
93  return std::forward<F>(f)( std::forward<Preceding>(params)... );
94  }
95 };
96 
97 template< typename T, typename... Types >
98 struct stored_pack<T, Types...> : stored_pack<Types...>
99 {
100  typedef stored_pack<T, Types...> pack_type;
101  typedef stored_pack<Types...> pack_remainder;
102  // Since lifetime of original values is out of control, copies should be made.
103  // Thus references should be stripped away from the deduced type.
105 
106  // Here rvalue references act in the same way as forwarding references,
107  // as long as class template parameters were deduced via forwarding references.
108  stored_pack( T&& t, Types&&... types )
109  : pack_remainder(std::forward<Types>(types)...), leftmost_value(std::forward<T>(t)) {}
110 
111  // Friend front-end functions
112  template< typename F, typename Pack > friend void call( F&& f, Pack&& p );
113  template< typename Ret, typename F, typename Pack > friend Ret call_and_return( F&& f, Pack&& p );
114 
115 protected:
116  template< typename Ret, typename F, typename... Preceding >
117  static Ret call( F&& f, pack_type& pack, Preceding&&... params ) {
118  return pack_remainder::template call<Ret>(
119  std::forward<F>(f), static_cast<pack_remainder&>(pack),
120  std::forward<Preceding>(params)... , pack.leftmost_value
121  );
122  }
123  template< typename Ret, typename F, typename... Preceding >
124  static Ret call( F&& f, const pack_type& pack, Preceding&&... params ) {
125  return pack_remainder::template call<Ret>(
126  std::forward<F>(f), static_cast<const pack_remainder&>(pack),
127  std::forward<Preceding>(params)... , pack.leftmost_value
128  );
129  }
130  template< typename Ret, typename F, typename... Preceding >
131  static Ret call( F&& f, pack_type&& pack, Preceding&&... params ) {
132  return pack_remainder::template call<Ret>(
133  std::forward<F>(f), static_cast<pack_remainder&&>(pack),
134  std::forward<Preceding>(params)... , std::move(pack.leftmost_value)
135  );
136  }
137 };
138 
140 template< typename F, typename Pack >
141 void call( F&& f, Pack&& p ) {
142  strip<Pack>::type::template call<void>( std::forward<F>(f), std::forward<Pack>(p) );
143 }
144 
145 template< typename Ret, typename F, typename Pack >
146 Ret call_and_return( F&& f, Pack&& p ) {
147  return strip<Pack>::type::template call<Ret>( std::forward<F>(f), std::forward<Pack>(p) );
148 }
149 
150 template< typename... Types >
151 stored_pack<Types...> save_pack( Types&&... types ) {
152  return stored_pack<Types...>( std::forward<Types>(types)... );
153 }
154 
155 #endif /* __TBB_CPP11_RVALUE_REF_PRESENT && __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT */
156 
157 #if __TBB_CPP14_INTEGER_SEQUENCE_PRESENT
158 
159 using std::index_sequence;
161 
162 #elif __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT && __TBB_CPP11_TEMPLATE_ALIASES_PRESENT
163 
164 template<std::size_t... S> class index_sequence {};
165 
166 template<std::size_t N, std::size_t... S>
167 struct make_index_sequence_impl : make_index_sequence_impl < N - 1, N - 1, S... > {};
168 
169 template<std::size_t... S>
170 struct make_index_sequence_impl <0, S...> {
171  using type = index_sequence<S...>;
172 };
173 
174 template<std::size_t N>
176 
177 #endif /* __TBB_CPP14_INTEGER_SEQUENCE_PRESENT */
178 
179 } } // namespace internal, namespace tbb
180 
181 #endif /* __TBB_template_helpers_H */
Ret call_and_return(F &&f, Pack &&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_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 ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle __itt_metadata_type type
Detects whether two given types are the same.
static Ret call(F &&f, pack_type &&, Preceding &&... params)
static const bool value
static Ret call(F &&f, const pack_type &, Preceding &&... params)
Strips its template type argument from cv- and ref-qualifiers.
Allows to store a function parameter pack as a variable and later pass it to another function.
void const char const char int ITT_FORMAT __itt_group_sync p
std::void_t internal implementation (to avoid GCC < 4.7 "template aliases" absence)
void move(tbb_thread &t1, tbb_thread &t2)
Definition: tbb_thread.h:309
static Ret call(F &&f, pack_type &pack, Preceding &&... params)
static Ret call(F &&f, pack_type &&pack, Preceding &&... params)
The graph class.
void call(F &&f, Pack &&p)
Calls the given function with arguments taken from a stored_pack.
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
typename tbb::internal::make_index_sequence_impl< N >::type make_index_sequence
static Ret call(F &&f, const pack_type &pack, Preceding &&... params)
Enables one or the other code branches.
stored_pack< Types... > save_pack(Types &&... types)

Copyright © 2005-2018 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.