2 * Copyright 2008-2013 NVIDIA Corporation
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <thrust/detail/config.h>
18 #include <thrust/detail/pointer.h>
25 template<typename Element, typename Tag, typename Reference, typename Derived>
26 pointer<Element,Tag,Reference,Derived>
28 : super_t(static_cast<Element*>(0))
29 {} // end pointer::pointer
32 template<typename Element, typename Tag, typename Reference, typename Derived>
33 template<typename OtherElement>
34 pointer<Element,Tag,Reference,Derived>
35 ::pointer(OtherElement *other)
37 {} // end pointer::pointer
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<
46 pointer<Element,Tag,Reference,Derived>
48 : super_t(thrust::detail::pointer_traits<OtherPointer>::get(other))
49 {} // end pointer::pointer
52 template<typename Element, typename Tag, typename Reference, typename Derived>
53 template<typename OtherPointer>
54 typename thrust::detail::enable_if_pointer_is_convertible<
56 pointer<Element,Tag,Reference,Derived>,
57 typename pointer<Element,Tag,Reference,Derived>::derived_type &
59 pointer<Element,Tag,Reference,Derived>
60 ::operator=(const OtherPointer &other)
62 super_t::base_reference() = thrust::detail::pointer_traits<OtherPointer>::get(other);
63 return static_cast<derived_type&>(*this);
64 } // end pointer::operator=
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>
72 return typename super_t::reference(static_cast<const derived_type&>(*this));
73 } // end pointer::dereference
76 template<typename Element, typename Tag, typename Reference, typename Derived>
77 Element *pointer<Element,Tag,Reference,Derived>
80 return super_t::base();
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> >
93 typedef typename pointer<Element,Tag,Reference,Derived>::raw_pointer type;
94 }; // end pointer_raw_pointer
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> >
104 typedef Element type;
105 }; // end pointer_element
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
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
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>
124 // XXX note we don't attempt to rebind the pointer's Reference type (or Derived)
125 typedef thrust::pointer<NewElement,Tag> type;
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>
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>
139 } // end namespace detail