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/type_traits.h>
19 #include <thrust/detail/allocator/allocator_traits.h>
20 #include <thrust/detail/type_traits/pointer_traits.h>
21 #include <thrust/for_each.h>
22 #include <thrust/uninitialized_fill.h>
29 namespace allocator_traits_detail
32 // fill_construct_range has 2 cases:
33 // if Allocator has an effectful member function construct:
34 // 1. construct via the allocator
36 // 2. construct via uninitialized_fill
38 template<typename Allocator, typename T, typename Arg1>
39 struct has_effectful_member_construct2
40 : has_member_construct2<Allocator,T,Arg1>
43 // std::allocator::construct's only effect is to invoke placement new
44 template<typename U, typename T, typename Arg1>
45 struct has_effectful_member_construct2<std::allocator<U>,T,Arg1>
46 : thrust::detail::false_type
50 template<typename Allocator, typename Arg1>
51 struct construct2_via_allocator
56 construct2_via_allocator(Allocator &a, const Arg1 &arg)
61 inline __host__ __device__
64 allocator_traits<Allocator>::construct(a, &x, arg);
69 template<typename Allocator, typename Pointer, typename Size, typename T>
71 has_effectful_member_construct2<
73 typename pointer_element<Pointer>::type,
77 fill_construct_range(Allocator &a, Pointer p, Size n, const T &value)
79 thrust::for_each_n(allocator_system<Allocator>::get(a), p, n, construct2_via_allocator<Allocator,T>(a, value));
83 template<typename Allocator, typename Pointer, typename Size, typename T>
85 has_effectful_member_construct2<
87 typename pointer_element<Pointer>::type,
91 fill_construct_range(Allocator &a, Pointer p, Size n, const T &value)
93 thrust::uninitialized_fill_n(allocator_system<Allocator>::get(a), p, n, value);
97 } // end allocator_traits_detail
100 template<typename Alloc, typename Pointer, typename Size, typename T>
101 void fill_construct_range(Alloc &a, Pointer p, Size n, const T &value)
103 return allocator_traits_detail::fill_construct_range(a,p,n,value);