_template_helpers.h
Go to the documentation of this file.
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef __TBB_template_helpers_H
#define __TBB_template_helpers_H
#include <utility>
#include <cstddef>
#include "../tbb_config.h"
#if __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT && __TBB_CPP11_TEMPLATE_ALIASES_PRESENT
#include <type_traits>
#endif
#if __TBB_CPP11_PRESENT
#include <iterator>
#include <memory> // allocator_traits
#endif
namespace tbb { namespace internal {
template<bool Condition, typename T = void> struct enable_if {};
template<typename T> struct enable_if<true, T> { typedef T type; };
template<typename T> struct strip { typedef T type; };
template<typename T> struct strip<const T> { typedef T type; };
template<typename T> struct strip<volatile T> { typedef T type; };
template<typename T> struct strip<const volatile T> { typedef T type; };
template<typename T> struct strip<T&> { typedef T type; };
template<typename T> struct strip<const T&> { typedef T type; };
template<typename T> struct strip<volatile T&> { typedef T type; };
template<typename T> struct strip<const volatile T&> { typedef T type; };
template<typename T> struct strip<T(&)()> { typedef T(*type)(); };
#if __TBB_CPP11_RVALUE_REF_PRESENT
template<typename T> struct strip<T&&> { typedef T type; };
template<typename T> struct strip<const T&&> { typedef T type; };
template<typename T> struct strip<volatile T&&> { typedef T type; };
template<typename T> struct strip<const volatile T&&> { typedef T type; };
#endif
template<typename T, std::size_t N> struct strip<T(&)[N]> { typedef T* type; };
template<typename T, std::size_t N> struct strip<const T(&)[N]> { typedef const T* type; };
template<typename T, std::size_t N> struct strip<volatile T(&)[N]> { typedef volatile T* type; };
template<typename T, std::size_t N> struct strip<const volatile T(&)[N]> { typedef const volatile T* type; };
template<class U, class V> struct is_same_type { static const bool value = false; };
template<class W> struct is_same_type<W,W> { static const bool value = true; };
template<typename T> struct is_ref { static const bool value = false; };
template<typename U> struct is_ref<U&> { static const bool value = true; };
template<typename T> struct is_integral_impl { static const bool value = false; };
template<> struct is_integral_impl<bool> { static const bool value = true; };
template<> struct is_integral_impl<char> { static const bool value = true; };
#if __TBB_CPP11_PRESENT
template<> struct is_integral_impl<char16_t> { static const bool value = true; };
template<> struct is_integral_impl<char32_t> { static const bool value = true; };
#endif
template<> struct is_integral_impl<wchar_t> { static const bool value = true; };
template<> struct is_integral_impl<short> { static const bool value = true; };
template<> struct is_integral_impl<int> { static const bool value = true; };
template<> struct is_integral_impl<long> { static const bool value = true; };
template<> struct is_integral_impl<long long> { static const bool value = true; };
template<typename T>
struct is_integral : is_integral_impl<typename strip<T>::type> {};
#if __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT
template<typename...> struct void_t { typedef void type; };
#endif
#if __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT && __TBB_CPP11_TEMPLATE_ALIASES_PRESENT
// Generic SFINAE helper for expression checks, based on the idea demonstrated in ISO C++ paper n4502
template<typename T, typename, template<typename> class... Checks>
struct supports_impl { typedef std::false_type type; };
template<typename T, template<typename> class... Checks>
struct supports_impl<T, typename void_t<Checks<T>...>::type, Checks...> { typedef std::true_type type; };
template<typename T, template<typename> class... Checks>
using supports = typename supports_impl<T, void, Checks...>::type;
#endif /* __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT && __TBB_CPP11_TEMPLATE_ALIASES_PRESENT */
#if __TBB_CPP11_RVALUE_REF_PRESENT && __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT
template< typename... Types >
struct stored_pack;
template<>
struct stored_pack<>
{
typedef stored_pack<> pack_type;
stored_pack() {}
// Friend front-end functions
template< typename F, typename Pack > friend void call( F&& f, Pack&& p );
template< typename Ret, typename F, typename Pack > friend Ret call_and_return( F&& f, Pack&& p );
protected:
// Ideally, ref-qualified non-static methods would be used,
// but that would greatly reduce the set of compilers where it works.
template< typename Ret, typename F, typename... Preceding >
static Ret call( F&& f, const pack_type& /*pack*/, Preceding&&... params ) {
return std::forward<F>(f)( std::forward<Preceding>(params)... );
}
template< typename Ret, typename F, typename... Preceding >
static Ret call( F&& f, pack_type&& /*pack*/, Preceding&&... params ) {
return std::forward<F>(f)( std::forward<Preceding>(params)... );
}
};
template< typename T, typename... Types >
struct stored_pack<T, Types...> : stored_pack<Types...>
{
typedef stored_pack<T, Types...> pack_type;
typedef stored_pack<Types...> pack_remainder;
// Since lifetime of original values is out of control, copies should be made.
// Thus references should be stripped away from the deduced type.
typename strip<T>::type leftmost_value;
// Here rvalue references act in the same way as forwarding references,
// as long as class template parameters were deduced via forwarding references.
stored_pack( T&& t, Types&&... types )
: pack_remainder(std::forward<Types>(types)...), leftmost_value(std::forward<T>(t)) {}
// Friend front-end functions
template< typename F, typename Pack > friend void call( F&& f, Pack&& p );
template< typename Ret, typename F, typename Pack > friend Ret call_and_return( F&& f, Pack&& p );
protected:
template< typename Ret, typename F, typename... Preceding >
static Ret call( F&& f, pack_type& pack, Preceding&&... params ) {
return pack_remainder::template call<Ret>(
std::forward<F>(f), static_cast<pack_remainder&>(pack),
std::forward<Preceding>(params)... , pack.leftmost_value
);
}
template< typename Ret, typename F, typename... Preceding >
static Ret call( F&& f, const pack_type& pack, Preceding&&... params ) {
return pack_remainder::template call<Ret>(
std::forward<F>(f), static_cast<const pack_remainder&>(pack),
std::forward<Preceding>(params)... , pack.leftmost_value
);
}
template< typename Ret, typename F, typename... Preceding >
static Ret call( F&& f, pack_type&& pack, Preceding&&... params ) {
return pack_remainder::template call<Ret>(
std::forward<F>(f), static_cast<pack_remainder&&>(pack),
std::forward<Preceding>(params)... , std::move(pack.leftmost_value)
);
}
};
template< typename F, typename Pack >
void call( F&& f, Pack&& p ) {
strip<Pack>::type::template call<void>( std::forward<F>(f), std::forward<Pack>(p) );
}
template< typename Ret, typename F, typename Pack >
Ret call_and_return( F&& f, Pack&& p ) {
return strip<Pack>::type::template call<Ret>( std::forward<F>(f), std::forward<Pack>(p) );
}
template< typename... Types >
stored_pack<Types...> save_pack( Types&&... types ) {
return stored_pack<Types...>( std::forward<Types>(types)... );
}
#endif /* __TBB_CPP11_RVALUE_REF_PRESENT && __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT */
#if __TBB_CPP14_INTEGER_SEQUENCE_PRESENT
using std::index_sequence;
using std::make_index_sequence;
#elif __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT && __TBB_CPP11_TEMPLATE_ALIASES_PRESENT
template<std::size_t... S> class index_sequence {};
template<std::size_t N, std::size_t... S>
struct make_index_sequence_impl : make_index_sequence_impl < N - 1, N - 1, S... > {};
template<std::size_t... S>
struct make_index_sequence_impl <0, S...> {
using type = index_sequence<S...>;
};
template<std::size_t N>
using make_index_sequence = typename tbb::internal::make_index_sequence_impl<N>::type;
#endif /* __TBB_CPP14_INTEGER_SEQUENCE_PRESENT */
#if __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT
template<typename... Args>
struct conjunction;
template<typename First, typename... Args>
struct conjunction<First, Args...>
: std::conditional<bool(First::value), conjunction<Args...>, First>::type {};
template<typename T>
struct conjunction<T> : T {};
template<>
struct conjunction<> : std::true_type {};
#endif
#if __TBB_CPP11_PRESENT
template< typename Iter >
using iterator_value_t = typename std::iterator_traits<Iter>::value_type;
template< typename Iter >
using iterator_key_t = typename std::remove_const<typename iterator_value_t<Iter>::first_type>::type;
template< typename Iter >
using iterator_mapped_t = typename iterator_value_t<Iter>::second_type;
template< typename A > using value_type = typename A::value_type;
template< typename A > using alloc_ptr_t = typename std::allocator_traits<A>::pointer;
template< typename A > using has_allocate = decltype(std::declval<alloc_ptr_t<A>&>() = std::declval<A>().allocate(0));
template< typename A > using has_deallocate = decltype(std::declval<A>().deallocate(std::declval<alloc_ptr_t<A>>(), 0));
// value_type should be checked first because it can be used in other checks (via allocator_traits)
template< typename T >
using is_allocator = supports<T, value_type, has_allocate, has_deallocate>;
#if __TBB_CPP14_VARIABLE_TEMPLATES_PRESENT
template< typename T >
static constexpr bool is_allocator_v = is_allocator<T>::value;
#endif /*__TBB_CPP14_VARIABLE_TEMPLATES */
template< std::size_t N, typename... Args >
struct pack_element {
using type = void;
};
template< std::size_t N, typename T, typename... Args >
struct pack_element<N, T, Args...> {
using type = typename pack_element<N - 1, Args...>::type;
};
template< typename T, typename... Args >
struct pack_element<0, T, Args...> {
using type = T;
};
template< std::size_t N, typename... Args >
using pack_element_t = typename pack_element<N, Args...>::type;
// Helper alias for heterogeneous lookup functions in containers
// template parameter K and std::conditional are needed to provide immediate context
// and postpone getting is_trasparent from the compare functor until method instantiation.
template <typename Comp, typename K>
using is_transparent = typename std::conditional<true, Comp, K>::type::is_transparent;
#endif /* __TBB_CPP11_PRESENT */
} } // namespace internal, namespace tbb
#endif /* __TBB_template_helpers_H */
tbb::internal::stored_pack< T, Types... >
Definition: _template_helpers.h:132
tbb::internal::is_integral_impl::value
static const bool value
Definition: _template_helpers.h:68
tbb::internal::enable_if< true, T >::type
T type
Definition: _template_helpers.h:35
internal
Definition: _flow_graph_async_msg_impl.h:24
tbb::internal::is_ref::value
static const bool value
Definition: _template_helpers.h:64
void
void
Definition: ittnotify_static.h:91
tbb::internal::strip< const T & >::type
T type
Definition: _template_helpers.h:43
tbb::internal::supports
typename supports_impl< T, void, Checks... >::type supports
Definition: _template_helpers.h:98
tbb::internal::void_t
std::void_t internal implementation (to avoid GCC < 4.7 "template aliases" absence)
Definition: _template_helpers.h:86
tbb::internal::stored_pack<>
Definition: _template_helpers.h:109
tbb::internal::supports_impl::type
std::false_type type
Definition: _template_helpers.h:93
tbb::internal::strip
Strips its template type argument from cv- and ref-qualifiers.
Definition: _template_helpers.h:38
tbb::internal::stored_pack<>::call
static Ret call(F &&f, pack_type &&, Preceding &&... params)
Definition: _template_helpers.h:126
tbb
The graph class.
Definition: serial/tbb/parallel_for.h:46
tbb::internal::strip< volatile T && >::type
T type
Definition: _template_helpers.h:51
tbb::internal::is_integral_impl
Partial support for std::is_integral.
Definition: _template_helpers.h:68
tbb::internal::is_integral
Definition: _template_helpers.h:82
tbb::internal::strip< const volatile T & >::type
T type
Definition: _template_helpers.h:45
tbb::internal::index_sequence
Definition: _template_helpers.h:198
tbb::internal::supports_impl< T, typename void_t< Checks< T >... >::type, Checks... >::type
std::true_type type
Definition: _template_helpers.h:95
tbb::internal::is_same_type::value
static const bool value
Definition: _template_helpers.h:61
tbb::internal::strip< const T && >::type
T type
Definition: _template_helpers.h:50
tbb::internal::call_and_return
Ret call_and_return(F &&f, Pack &&p)
Definition: _template_helpers.h:180
tbb::internal::stored_pack<>::pack_type
stored_pack pack_type
Definition: _template_helpers.h:111
tbb::internal::strip< volatile T >::type
T type
Definition: _template_helpers.h:40
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 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
Definition: ittnotify_static.h:217
tbb::move
void move(tbb_thread &t1, tbb_thread &t2)
Definition: tbb_thread.h:319
tbb::internal::strip::type
T type
Definition: _template_helpers.h:38
tbb::internal::strip< T & >::type
T type
Definition: _template_helpers.h:42
tbb::internal::strip< const volatile T >::type
T type
Definition: _template_helpers.h:41
tbb::internal::conjunction
Definition: _template_helpers.h:215
tbb::internal::is_ref
Definition: _template_helpers.h:64
tbb::internal::strip< volatile T(&)[N]>::type
volatile T * type
Definition: _template_helpers.h:57
tbb::internal::true_type
bool_constant< true > true_type
Definition: tbb_stddef.h:489
tbb::internal::stored_pack< T, Types... >::stored_pack
stored_pack(T &&t, Types &&... types)
Definition: _template_helpers.h:142
tbb::internal::stored_pack
Allows to store a function parameter pack as a variable and later pass it to another function.
Definition: _template_helpers.h:106
tbb::internal::make_index_sequence_impl
Definition: _template_helpers.h:201
tbb::internal::is_same_type
Detects whether two given types are the same.
Definition: _template_helpers.h:61
tbb::internal::stored_pack<>::stored_pack
stored_pack()
Definition: _template_helpers.h:112
tbb::internal::stored_pack< T, Types... >::pack_remainder
stored_pack< Types... > pack_remainder
Definition: _template_helpers.h:135
tbb::internal::stored_pack< T, Types... >::call
static Ret call(F &&f, const pack_type &pack, Preceding &&... params)
Definition: _template_helpers.h:158
tbb::internal::stored_pack< T, Types... >::leftmost_value
strip< T >::type leftmost_value
Definition: _template_helpers.h:138
tbb::internal::strip< volatile T & >::type
T type
Definition: _template_helpers.h:44
tbb::internal::supports_impl
Definition: _template_helpers.h:93
value
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
Definition: ittnotify_static.h:192
tbb::internal::stored_pack< T, Types... >::call
static Ret call(F &&f, pack_type &&pack, Preceding &&... params)
Definition: _template_helpers.h:165
tbb::internal::strip< const T(&)[N]>::type
const typedef T * type
Definition: _template_helpers.h:56
tbb::internal::stored_pack< T, Types... >::call
static Ret call(F &&f, pack_type &pack, Preceding &&... params)
Definition: _template_helpers.h:151
tbb::internal::save_pack
stored_pack< Types... > save_pack(Types &&... types)
Definition: _template_helpers.h:185
tbb::internal::make_index_sequence
typename tbb::internal::make_index_sequence_impl< N >::type make_index_sequence
Definition: _template_helpers.h:209
tbb::internal::false_type
bool_constant< false > false_type
Definition: tbb_stddef.h:490
p
void const char const char int ITT_FORMAT __itt_group_sync p
Definition: ittnotify_static.h:91
tbb::internal::strip< T && >::type
T type
Definition: _template_helpers.h:49
tbb::internal::enable_if
Enables one or the other code branches.
Definition: _template_helpers.h:34
tbb::internal::strip< const T >::type
T type
Definition: _template_helpers.h:39
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_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
Definition: ittnotify_static.h:212
type
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
Definition: ittnotify_static.h:198
tbb::internal::stored_pack<>::call
static Ret call(F &&f, const pack_type &, Preceding &&... params)
Definition: _template_helpers.h:122
tbb::internal::call
void call(F &&f, Pack &&p)
Calls the given function with arguments taken from a stored_pack.
Definition: _template_helpers.h:175
tbb::internal::strip< const volatile T && >::type
T type
Definition: _template_helpers.h:52
tbb::internal::stored_pack< T, Types... >::pack_type
stored_pack< T, Types... > pack_type
Definition: _template_helpers.h:134
tbb::internal::strip< const volatile T(&)[N]>::type
const typedef volatile T * type
Definition: _template_helpers.h:58

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.