OSDN Git Service

CUDA
[eos/hostdependX86LINUX64.git] / util / X86LINUX64 / cuda-6.5 / include / thrust / detail / allocator / tagged_allocator.h
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 #pragma once
18
19 #include <thrust/detail/config.h>
20 #include <thrust/detail/type_traits/pointer_traits.h>
21 #include <thrust/iterator/iterator_traits.h>
22
23 namespace thrust
24 {
25 namespace detail
26 {
27
28 template<typename T, typename Tag, typename Pointer> class tagged_allocator;
29
30 template<typename Tag, typename Pointer>
31   class tagged_allocator<void, Tag, Pointer>
32 {
33   public:
34     typedef void                                                                                 value_type;
35     typedef typename thrust::detail::pointer_traits<Pointer>::template rebind<void>::other       pointer;
36     typedef typename thrust::detail::pointer_traits<Pointer>::template rebind<const void>::other const_pointer;
37     typedef std::size_t                                                                          size_type;
38     typedef typename thrust::detail::pointer_traits<Pointer>::difference_type                    difference_type;
39     typedef Tag                                                                                  system_type;
40
41     template<typename U>
42       struct rebind
43     {
44       typedef tagged_allocator<U,Tag,Pointer> other;
45     }; // end rebind
46 };
47
48 template<typename T, typename Tag, typename Pointer>
49   class tagged_allocator
50 {
51   public:
52     typedef T                                                                                 value_type;
53     typedef typename thrust::detail::pointer_traits<Pointer>::template rebind<T>::other       pointer;
54     typedef typename thrust::detail::pointer_traits<Pointer>::template rebind<const T>::other const_pointer;
55     typedef typename thrust::iterator_reference<pointer>::type                                reference;
56     typedef typename thrust::iterator_reference<const_pointer>::type                          const_reference;
57     typedef std::size_t                                                                       size_type;
58     typedef typename thrust::detail::pointer_traits<pointer>::difference_type                 difference_type;
59     typedef Tag                                                                               system_type;
60
61     template<typename U>
62       struct rebind
63     {
64       typedef tagged_allocator<U,Tag,Pointer> other;
65     }; // end rebind
66
67     __host__ __device__
68     inline tagged_allocator();
69
70     __host__ __device__
71     inline tagged_allocator(const tagged_allocator &);
72
73     template<typename U, typename OtherPointer>
74     __host__ __device__
75     inline tagged_allocator(const tagged_allocator<U, Tag, OtherPointer> &);
76
77     __host__ __device__
78     inline ~tagged_allocator();
79
80     __host__ __device__
81     pointer address(reference x) const;
82
83     __host__ __device__
84     const_pointer address(const_reference x) const;
85
86     size_type max_size() const;
87 };
88
89 template<typename T1, typename Pointer1, typename T2, typename Pointer2, typename Tag>
90 __host__ __device__
91 bool operator==(const tagged_allocator<T1,Pointer1,Tag> &, const tagged_allocator<T2,Pointer2,Tag> &);
92
93 template<typename T1, typename Pointer1, typename T2, typename Pointer2, typename Tag>
94 __host__ __device__
95 bool operator!=(const tagged_allocator<T1,Pointer1,Tag> &, const tagged_allocator<T2,Pointer2,Tag> &);
96
97 } // end detail
98 } // end thrust
99
100 #include <thrust/detail/allocator/tagged_allocator.inl>
101