OSDN Git Service

CUDA
[eos/hostdependX86LINUX64.git] / util / X86LINUX64 / cuda-6.5 / include / thrust / detail / pointer.inl
1 /*
2  *  Copyright 2008-2013 NVIDIA 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 #include <thrust/detail/config.h>
18 #include <thrust/detail/pointer.h>
19
20
21 namespace thrust
22 {
23
24
25 template<typename Element, typename Tag, typename Reference, typename Derived>
26   pointer<Element,Tag,Reference,Derived>
27     ::pointer()
28       : super_t(static_cast<Element*>(0))
29 {} // end pointer::pointer
30
31
32 template<typename Element, typename Tag, typename Reference, typename Derived>
33   template<typename OtherElement>
34     pointer<Element,Tag,Reference,Derived>
35       ::pointer(OtherElement *other)
36         : super_t(other)
37 {} // end pointer::pointer
38
39
40 template<typename Element, typename Tag, typename Reference, typename Derived>
41   template<typename OtherPointer>
42     pointer<Element,Tag,Reference,Derived>
43       ::pointer(const OtherPointer &other,
44                 typename thrust::detail::enable_if_pointer_is_convertible<
45                   OtherPointer,
46                   pointer<Element,Tag,Reference,Derived>
47                  >::type *)
48         : super_t(thrust::detail::pointer_traits<OtherPointer>::get(other))
49 {} // end pointer::pointer
50
51
52 template<typename Element, typename Tag, typename Reference, typename Derived>
53   template<typename OtherPointer>
54     typename thrust::detail::enable_if_pointer_is_convertible<
55       OtherPointer,
56       pointer<Element,Tag,Reference,Derived>,
57       typename pointer<Element,Tag,Reference,Derived>::derived_type &
58     >::type
59       pointer<Element,Tag,Reference,Derived>
60         ::operator=(const OtherPointer &other)
61 {
62   super_t::base_reference() = thrust::detail::pointer_traits<OtherPointer>::get(other);
63   return static_cast<derived_type&>(*this);
64 } // end pointer::operator=
65
66
67 template<typename Element, typename Tag, typename Reference, typename Derived>
68   typename pointer<Element,Tag,Reference,Derived>::super_t::reference
69     pointer<Element,Tag,Reference,Derived>
70       ::dereference() const
71 {
72   return typename super_t::reference(static_cast<const derived_type&>(*this));
73 } // end pointer::dereference
74
75
76 template<typename Element, typename Tag, typename Reference, typename Derived>
77   Element *pointer<Element,Tag,Reference,Derived>
78     ::get() const
79 {
80   return super_t::base();
81 } // end pointer::get
82
83
84 namespace detail
85 {
86
87 #if (THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_MSVC) && (_MSC_VER <= 1400)
88 // XXX WAR MSVC 2005 problem with correctly implementing
89 //     pointer_raw_pointer for pointer by specializing it here
90 template<typename Element, typename Tag, typename Reference, typename Derived>
91   struct pointer_raw_pointer< thrust::pointer<Element,Tag,Reference,Derived> >
92 {
93   typedef typename pointer<Element,Tag,Reference,Derived>::raw_pointer type;
94 }; // end pointer_raw_pointer
95 #endif
96
97
98 #if (THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_GCC) && (THRUST_GCC_VERSION < 40200)
99 // XXX WAR g++-4.1 problem with correctly implementing
100 //     pointer_element for pointer by specializing it here
101 template<typename Element, typename Tag>
102   struct pointer_element< thrust::pointer<Element,Tag> >
103 {
104   typedef Element type;
105 }; // end pointer_element
106
107 template<typename Element, typename Tag, typename Reference>
108   struct pointer_element< thrust::pointer<Element,Tag,Reference> >
109     : pointer_element< thrust::pointer<Element,Tag> >
110 {}; // end pointer_element
111
112 template<typename Element, typename Tag, typename Reference, typename Derived>
113   struct pointer_element< thrust::pointer<Element,Tag,Reference,Derived> >
114     : pointer_element< thrust::pointer<Element,Tag,Reference> >
115 {}; // end pointer_element
116
117
118
119 // XXX WAR g++-4.1 problem with correctly implementing
120 //     rebind_pointer for pointer by specializing it here
121 template<typename Element, typename Tag, typename NewElement>
122   struct rebind_pointer<thrust::pointer<Element,Tag>, NewElement>
123 {
124   // XXX note we don't attempt to rebind the pointer's Reference type (or Derived)
125   typedef thrust::pointer<NewElement,Tag> type;
126 };
127
128 template<typename Element, typename Tag, typename Reference, typename NewElement>
129   struct rebind_pointer<thrust::pointer<Element,Tag,Reference>, NewElement>
130     : rebind_pointer<thrust::pointer<Element,Tag>, NewElement>
131 {};
132
133 template<typename Element, typename Tag, typename Reference, typename Derived, typename NewElement>
134   struct rebind_pointer<thrust::pointer<Element,Tag,Reference,Derived>, NewElement>
135     : rebind_pointer<thrust::pointer<Element,Tag,Reference>, NewElement>
136 {};
137 #endif
138
139 } // end namespace detail
140
141
142 } // end thrust
143