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.
19 #include <thrust/detail/config.h>
20 #include <thrust/detail/type_traits.h>
21 #include <thrust/detail/use_default.h>
22 #include <thrust/detail/reference_forward_declaration.h>
30 template<typename> struct is_wrapped_reference;
34 // the base type for all of thrust's system-annotated references.
35 // for reasonable reference-like semantics, derived types must reimplement the following:
36 // 1. constructor from pointer
37 // 2. copy constructor
38 // 3. templated copy constructor from other reference
39 // 4. templated assignment from other reference
40 // 5. assignment from value_type
41 template<typename Element, typename Pointer, typename Derived>
45 typedef typename thrust::detail::eval_if<
46 thrust::detail::is_same<Derived,use_default>::value,
47 thrust::detail::identity_<reference>,
48 thrust::detail::identity_<Derived>
51 // hint for is_wrapped_reference lets it know that this type (or a derived type)
52 // is a wrapped reference
53 struct wrapped_reference_hint {};
54 template<typename> friend struct thrust::detail::is_wrapped_reference;
57 typedef Pointer pointer;
58 typedef typename thrust::detail::remove_const<Element>::type value_type;
61 explicit reference(const pointer &ptr);
63 template<typename OtherElement, typename OtherPointer, typename OtherDerived>
65 reference(const reference<OtherElement,OtherPointer,OtherDerived> &other,
66 typename thrust::detail::enable_if_convertible<
67 typename reference<OtherElement,OtherPointer,OtherDerived>::pointer,
72 derived_type &operator=(const reference &other);
74 // XXX this may need an enable_if
75 template<typename OtherElement, typename OtherPointer, typename OtherDerived>
77 derived_type &operator=(const reference<OtherElement,OtherPointer,OtherDerived> &other);
80 derived_type &operator=(const value_type &x);
83 pointer operator&() const;
86 operator value_type () const;
89 void swap(derived_type &other);
91 derived_type &operator++();
93 value_type operator++(int);
95 // XXX parameterize the type of rhs
96 derived_type &operator+=(const value_type &rhs);
98 derived_type &operator--();
100 value_type operator--(int);
102 // XXX parameterize the type of rhs
103 derived_type &operator-=(const value_type &rhs);
105 // XXX parameterize the type of rhs
106 derived_type &operator*=(const value_type &rhs);
108 // XXX parameterize the type of rhs
109 derived_type &operator/=(const value_type &rhs);
111 // XXX parameterize the type of rhs
112 derived_type &operator%=(const value_type &rhs);
114 // XXX parameterize the type of rhs
115 derived_type &operator<<=(const value_type &rhs);
117 // XXX parameterize the type of rhs
118 derived_type &operator>>=(const value_type &rhs);
120 // XXX parameterize the type of rhs
121 derived_type &operator&=(const value_type &rhs);
123 // XXX parameterize the type of rhs
124 derived_type &operator|=(const value_type &rhs);
126 // XXX parameterize the type of rhs
127 derived_type &operator^=(const value_type &rhs);
132 // allow access to m_ptr for other references
133 template <typename OtherElement, typename OtherPointer, typename OtherDerived> friend class reference;
135 template<typename System>
137 inline value_type strip_const_get_value(const System &system) const;
139 template<typename OtherPointer>
141 inline void assign_from(OtherPointer src);
143 // XXX this helper exists only to avoid warnings about null references from the other assign_from
144 template<typename System1, typename System2, typename OtherPointer>
145 inline __host__ __device__
146 void assign_from(System1 *system1, System2 *system2, OtherPointer src);
148 template<typename System, typename OtherPointer>
150 inline void strip_const_assign_value(const System &system, OtherPointer src);
152 // XXX this helper exists only to avoid warnings about null references from the other swap
153 template<typename System>
154 inline __host__ __device__
155 void swap(System *system, derived_type &other);
157 // XXX this helper exists only to avoid warnings about null references from operator value_type ()
158 template<typename System>
159 inline __host__ __device__
160 value_type convert_to_value_type(System *system) const;
166 #include <thrust/detail/reference.inl>