Fermat
iterator.h
1 /*
2  * CUGAR : Cuda Graphics Accelerator
3  *
4  * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the NVIDIA CORPORATION nor the
14  * names of its contributors may be used to endorse or promote products
15  * derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
34 #pragma once
35 
36 #include <iterator>
37 #include <cugar/basic/types.h>
38 #include <thrust/iterator/iterator_categories.h>
39 
40 #if defined(__CUDACC__)
41 
42 namespace std
43 {
44 
45 // extend the std::iterator_traits with support for CUDA's __restrict__ pointers
46 template<class _Ty>
47 struct iterator_traits<const _Ty * __restrict__>
48 { // get traits from const pointer
49  typedef random_access_iterator_tag iterator_category;
50  typedef _Ty value_type;
51  typedef ptrdiff_t difference_type;
52  //typedef ptrdiff_t distance_type; // retained
53  typedef const _Ty* __restrict__ pointer;
54  typedef const _Ty& reference;
55 };
56 
57 } // namespace std
58 
59 #endif // __CUDACC__
60 
61 namespace cugar {
62 
65 
66 typedef std::input_iterator_tag input_host_iterator_tag;
67 typedef std::output_iterator_tag output_host_iterator_tag;
68 typedef std::forward_iterator_tag forward_host_iterator_tag;
69 typedef std::bidirectional_iterator_tag bidirectional_host_iterator_tag;
70 typedef std::random_access_iterator_tag random_access_host_iterator_tag;
71 
72 typedef thrust::input_device_iterator_tag input_device_iterator_tag;
73 typedef thrust::output_device_iterator_tag output_device_iterator_tag;
74 typedef thrust::forward_device_iterator_tag forward_device_iterator_tag;
75 typedef thrust::bidirectional_device_iterator_tag bidirectional_device_iterator_tag;
76 typedef thrust::random_access_device_iterator_tag random_access_device_iterator_tag;
77 
78 typedef thrust::input_universal_iterator_tag input_universal_iterator_tag;
79 typedef thrust::output_universal_iterator_tag output_universal_iterator_tag;
80 typedef thrust::forward_universal_iterator_tag forward_universal_iterator_tag;
81 typedef thrust::bidirectional_universal_iterator_tag bidirectional_universal_iterator_tag;
82 typedef thrust::random_access_universal_iterator_tag random_access_universal_iterator_tag;
83 
84 template <typename iterator_category> struct iterator_category_system {};
85 template <> struct iterator_category_system<input_host_iterator_tag> { typedef host_tag type; };
86 template <> struct iterator_category_system<output_host_iterator_tag> { typedef host_tag type; };
87 template <> struct iterator_category_system<forward_host_iterator_tag> { typedef host_tag type; };
88 template <> struct iterator_category_system<bidirectional_host_iterator_tag> { typedef host_tag type; };
89 template <> struct iterator_category_system<random_access_host_iterator_tag> { typedef host_tag type; };
90 template <> struct iterator_category_system<input_device_iterator_tag> { typedef device_tag type; };
91 template <> struct iterator_category_system<output_device_iterator_tag> { typedef device_tag type; };
92 template <> struct iterator_category_system<forward_device_iterator_tag> { typedef device_tag type; };
93 template <> struct iterator_category_system<bidirectional_device_iterator_tag> { typedef device_tag type; };
94 template <> struct iterator_category_system<random_access_device_iterator_tag> { typedef device_tag type; };
95 template <> struct iterator_category_system<input_universal_iterator_tag> { typedef device_tag type; };
96 template <> struct iterator_category_system<output_universal_iterator_tag> { typedef device_tag type; };
97 template <> struct iterator_category_system<forward_universal_iterator_tag> { typedef device_tag type; };
98 template <> struct iterator_category_system<bidirectional_universal_iterator_tag> { typedef device_tag type; };
99 template <> struct iterator_category_system<random_access_universal_iterator_tag> { typedef device_tag type; };
100 
101 template <typename iterator>
103 {
104  typedef typename std::iterator_traits<iterator>::iterator_category iterator_category;
106 };
107 
110 template <typename T>
111 struct iterator_traits : public std::iterator_traits<T>
112 {
113  typedef typename std::iterator_traits<T>::iterator_category iterator_category;
114  typedef typename std::iterator_traits<T>::value_type value_type;
115  typedef typename std::iterator_traits<T>::difference_type difference_type;
116  typedef typename std::iterator_traits<T>::pointer pointer;
117  typedef typename std::iterator_traits<T>::reference reference;
118  typedef T forward_iterator;
119 };
120 
122 
123 } // namespace cugar
Definition: shared_pointer.h:646
Definition: types.h:181
T forward_iterator
add forward iterator conversion
Definition: iterator.h:118
Definition: types.h:185
Define a vector_view POD type and plain_view() for std::vector.
Definition: diff.h:38
Definition: iterator.h:84
Definition: iterator.h:111
Definition: iterator.h:102