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/system/omp/detail/copy.h>
21 #include <thrust/system/detail/generic/copy.h>
22 #include <thrust/detail/type_traits/minimum_type.h>
23 #include <thrust/system/cpp/detail/copy.h>
24 #include <thrust/iterator/detail/retag.h>
37 template<typename DerivedPolicy,
38 typename InputIterator,
39 typename OutputIterator>
40 OutputIterator copy(execution_policy<DerivedPolicy> &exec,
43 OutputIterator result,
44 thrust::incrementable_traversal_tag)
46 return thrust::system::cpp::detail::copy(exec, first, last, result);
50 template<typename DerivedPolicy,
51 typename InputIterator,
52 typename OutputIterator>
53 OutputIterator copy(execution_policy<DerivedPolicy> &exec,
56 OutputIterator result,
57 thrust::random_access_traversal_tag)
59 // XXX WAR problems reconciling unrelated types such as omp & tbb
60 // reinterpret iterators as the policy we were passed
61 // this ensures that generic::copy's implementation, which eventually results in
62 // zip_iterator works correctly
63 thrust::detail::tagged_iterator<OutputIterator,DerivedPolicy> retagged_result(result);
65 return thrust::system::detail::generic::copy(exec, thrust::reinterpret_tag<DerivedPolicy>(first), thrust::reinterpret_tag<DerivedPolicy>(last), retagged_result).base();
69 template<typename DerivedPolicy,
70 typename InputIterator,
72 typename OutputIterator>
73 OutputIterator copy_n(execution_policy<DerivedPolicy> &exec,
76 OutputIterator result,
77 thrust::incrementable_traversal_tag)
79 return thrust::system::cpp::detail::copy_n(exec, first, n, result);
83 template<typename DerivedPolicy,
84 typename InputIterator,
86 typename OutputIterator>
87 OutputIterator copy_n(execution_policy<DerivedPolicy> &exec,
90 OutputIterator result,
91 thrust::random_access_traversal_tag)
93 // XXX WAR problems reconciling unrelated types such as omp & tbb
94 // reinterpret iterators as the policy we were passed
95 // this ensures that generic::copy's implementation, which eventually results in
96 // zip_iterator works correctly
97 thrust::detail::tagged_iterator<OutputIterator,DerivedPolicy> retagged_result(result);
99 return thrust::system::detail::generic::copy_n(exec, thrust::reinterpret_tag<DerivedPolicy>(first), n, retagged_result).base();
105 template<typename DerivedPolicy,
106 typename InputIterator,
107 typename OutputIterator>
108 OutputIterator copy(execution_policy<DerivedPolicy> &exec,
111 OutputIterator result)
113 typedef typename thrust::iterator_traversal<InputIterator>::type traversal1;
114 typedef typename thrust::iterator_traversal<OutputIterator>::type traversal2;
116 typedef typename thrust::detail::minimum_type<traversal1,traversal2>::type traversal;
118 // dispatch on minimum traversal
119 return thrust::system::omp::detail::dispatch::copy(exec, first,last,result,traversal());
124 template<typename DerivedPolicy,
125 typename InputIterator,
127 typename OutputIterator>
128 OutputIterator copy_n(execution_policy<DerivedPolicy> &exec,
131 OutputIterator result)
133 typedef typename thrust::iterator_traversal<InputIterator>::type traversal1;
134 typedef typename thrust::iterator_traversal<OutputIterator>::type traversal2;
136 typedef typename thrust::detail::minimum_type<traversal1,traversal2>::type traversal;
138 // dispatch on minimum traversal
139 return thrust::system::omp::detail::dispatch::copy_n(exec,first,n,result,traversal());
143 } // end namespace detail
144 } // end namespace omp
145 } // end namespace system
146 } // end namespace thrust