/* * Copyright 2008-2012 NVIDIA Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include #include #include #include namespace thrust { namespace detail { // we can retag an iterator if FromTag converts to ToTag // or vice versa template struct is_retaggable : integral_constant< bool, (is_convertible::value || is_convertible::value) > {}; template struct enable_if_retaggable : enable_if< is_retaggable::value, Result > {}; // end enable_if_retaggable } // end detail template thrust::detail::tagged_iterator reinterpret_tag(Iterator iter) { return thrust::detail::tagged_iterator(iter); } // end reinterpret_tag() // specialization for raw pointer template thrust::pointer reinterpret_tag(T *ptr) { return thrust::pointer(ptr); } // end reinterpret_tag() // specialization for thrust::pointer template thrust::pointer reinterpret_tag(thrust::pointer ptr) { return reinterpret_tag(ptr.get()); } // end reinterpret_tag() // avoid deeply-nested tagged_iterator template thrust::detail::tagged_iterator reinterpret_tag(thrust::detail::tagged_iterator iter) { return reinterpret_tag(iter.base()); } // end reinterpret_tag() template typename thrust::detail::enable_if_retaggable< typename thrust::iterator_system::type, Tag, thrust::detail::tagged_iterator >::type retag(Iterator iter) { return reinterpret_tag(iter); } // end retag() // specialization for raw pointer template typename thrust::detail::enable_if_retaggable< typename thrust::iterator_system::type, Tag, thrust::pointer >::type retag(T *ptr) { return reinterpret_tag(ptr); } // end retag() // specialization for thrust::pointer template typename thrust::detail::enable_if_retaggable< OtherTag, Tag, thrust::pointer >::type retag(thrust::pointer ptr) { return reinterpret_tag(ptr); } // end retag() // avoid deeply-nested tagged_iterator template typename thrust::detail::enable_if_retaggable< OtherTag, Tag, thrust::detail::tagged_iterator >::type retag(thrust::detail::tagged_iterator iter) { return reinterpret_tag(iter); } // end retag() } // end thrust