DPC++ Runtime
Runtime libraries for oneAPI DPC++
stl_type_traits.hpp
Go to the documentation of this file.
1 //==------- stl_type_traits.hpp - SYCL STL type traits analogs -------------==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #pragma once
10 
11 #include <iterator>
12 #include <memory>
13 #include <sycl/detail/defines.hpp>
14 #include <type_traits>
15 
16 namespace sycl {
18 namespace detail {
19 
20 // Type traits identical to those in std in newer versions. Can be removed when
21 // SYCL requires a newer version of the C++ standard.
22 // C++14
23 template <bool B, class T, class F>
24 using conditional_t = typename std::conditional<B, T, F>::type;
25 
26 template <typename T>
27 using remove_const_t = typename std::remove_const<T>::type;
28 
29 template <typename T> using remove_cv_t = typename std::remove_cv<T>::type;
30 
31 template <typename T>
32 using remove_reference_t = typename std::remove_reference<T>::type;
33 
34 template <typename T> using add_pointer_t = typename std::add_pointer<T>::type;
35 
36 // C++17
37 template <bool V> using bool_constant = std::integral_constant<bool, V>;
38 
39 template <class...> using void_t = void;
40 
41 // Custom type traits
42 template <typename T>
43 using allocator_value_type_t = typename std::allocator_traits<T>::value_type;
44 
45 template <typename T>
46 using allocator_pointer_t = typename std::allocator_traits<T>::pointer;
47 
48 template <typename T>
49 using iterator_category_t = typename std::iterator_traits<T>::iterator_category;
50 
51 template <typename T>
52 using iterator_value_type_t = typename std::iterator_traits<T>::value_type;
53 
54 template <typename T>
55 using iterator_pointer_t = typename std::iterator_traits<T>::pointer;
56 
57 template <typename T>
59  std::is_const<typename std::remove_pointer<iterator_pointer_t<T>>::type>;
60 
61 // TODO Align with C++ named requirements: LegacyOutputIterator
62 // https://en.cppreference.com/w/cpp/named_req/OutputIterator
63 template <typename T>
66  decltype(*std::declval<T>() =
67  std::declval<iterator_value_type_t<T>>())>;
68 
69 template <typename, typename = void> struct is_output_iterator {
70  static constexpr bool value = false;
71 };
72 
73 template <typename T>
75  static constexpr bool value = true;
76 };
77 
78 } // namespace detail
79 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
80 } // namespace sycl
#define __SYCL_INLINE_VER_NAMESPACE(X)
typename std::remove_cv< T >::type remove_cv_t
typename std::iterator_traits< T >::value_type iterator_value_type_t
typename std::conditional< B, T, F >::type conditional_t
std::is_const< typename std::remove_pointer< iterator_pointer_t< T > >::type > iterator_to_const_type_t
typename std::iterator_traits< T >::iterator_category iterator_category_t
std::integral_constant< bool, V > bool_constant
void_t< iterator_category_t< T >, decltype(*std::declval< T >()=std::declval< iterator_value_type_t< T > >())> output_iterator_requirements
typename std::allocator_traits< T >::value_type allocator_value_type_t
typename std::remove_const< T >::type remove_const_t
typename std::add_pointer< T >::type add_pointer_t
typename std::iterator_traits< T >::pointer iterator_pointer_t
typename std::allocator_traits< T >::pointer allocator_pointer_t
typename std::remove_reference< T >::type remove_reference_t
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14