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/allocator/allocator_traits.h>
19 #include <thrust/detail/type_traits.h>
20 #include <thrust/detail/type_traits/pointer_traits.h>
21 #include <thrust/for_each.h>
22 #include <thrust/uninitialized_fill.h>
28 namespace allocator_traits_detail
32 template<typename Allocator>
33 struct construct1_via_allocator
37 construct1_via_allocator(Allocator &a)
42 inline __host__ __device__
45 allocator_traits<Allocator>::construct(a, &x);
50 template<typename Allocator, typename T>
51 struct needs_default_construct_via_allocator
52 : has_member_construct1<
59 // we know that std::allocator::construct's only effect is to call T's
60 // default constructor, so we needn't use it for default construction
61 template<typename U, typename T>
62 struct needs_default_construct_via_allocator<std::allocator<U>, T>
63 : thrust::detail::false_type
67 template<typename Allocator, typename Pointer, typename Size>
69 needs_default_construct_via_allocator<
71 typename pointer_element<Pointer>::type
74 default_construct_range(Allocator &a, Pointer p, Size n)
76 thrust::for_each_n(allocator_system<Allocator>::get(a), p, n, construct1_via_allocator<Allocator>(a));
80 template<typename Allocator, typename Pointer, typename Size>
82 needs_default_construct_via_allocator<
84 typename pointer_element<Pointer>::type
87 default_construct_range(Allocator &a, Pointer p, Size n)
89 thrust::uninitialized_fill_n(allocator_system<Allocator>::get(a), p, n, typename pointer_element<Pointer>::type());
93 } // end allocator_traits_detail
96 template<typename Allocator, typename Pointer, typename Size>
97 void default_construct_range(Allocator &a, Pointer p, Size n)
99 return allocator_traits_detail::default_construct_range(a,p,n);