@@ -30,7 +30,18 @@ class buffer {
30
30
using allocator_type = AllocatorT;
31
31
template <int dims>
32
32
using EnableIfOneDimension = typename std::enable_if<1 == dims>::type;
33
-
33
+ // using same requirement for contiguous container as std::span
34
+ template <class Container >
35
+ using EnableIfContiguous =
36
+ detail::void_t <detail::enable_if_t <std::is_convertible<
37
+ detail::remove_pointer_t <decltype (
38
+ std::declval<Container>().data())> (*)[],
39
+ const T (*)[]>::value>,
40
+ decltype(std::declval<Container>().size())>;
41
+ template <class It >
42
+ using EnableIfItInputIterator = detail::enable_if_t <
43
+ std::is_convertible<typename std::iterator_traits<It>::iterator_category,
44
+ std::input_iterator_tag>::value>;
34
45
template <typename ItA, typename ItB>
35
46
using EnableIfSameNonConstIterators =
36
47
typename std::enable_if<std::is_same<ItA, ItB>::value &&
@@ -107,7 +118,8 @@ class buffer {
107
118
}
108
119
109
120
template <class InputIterator , int N = dimensions,
110
- typename = EnableIfOneDimension<N>>
121
+ typename = EnableIfOneDimension<N>,
122
+ typename = EnableIfItInputIterator<InputIterator>>
111
123
buffer (InputIterator first, InputIterator last, AllocatorT allocator,
112
124
const property_list &propList = {})
113
125
: Range(range<1 >(std::distance(first, last))) {
@@ -117,7 +129,8 @@ class buffer {
117
129
}
118
130
119
131
template <class InputIterator , int N = dimensions,
120
- typename = EnableIfOneDimension<N>>
132
+ typename = EnableIfOneDimension<N>,
133
+ typename = EnableIfItInputIterator<InputIterator>>
121
134
buffer (InputIterator first, InputIterator last,
122
135
const property_list &propList = {})
123
136
: Range(range<1 >(std::distance(first, last))) {
@@ -126,6 +139,26 @@ class buffer {
126
139
detail::getNextPowerOfTwo (sizeof (T)), propList);
127
140
}
128
141
142
+ // This constructor is a prototype for a future SYCL specification
143
+ template <class Container , int N = dimensions,
144
+ typename = EnableIfOneDimension<N>,
145
+ typename = EnableIfContiguous<Container>>
146
+ buffer (Container &container, AllocatorT allocator,
147
+ const property_list &propList = {})
148
+ : Range(range<1 >(container.size())) {
149
+ impl = std::make_shared<detail::buffer_impl<AllocatorT>>(
150
+ container.data (), container.data () + container.size (),
151
+ get_count () * sizeof (T), detail::getNextPowerOfTwo (sizeof (T)), propList,
152
+ allocator);
153
+ }
154
+
155
+ // This constructor is a prototype for a future SYCL specification
156
+ template <class Container , int N = dimensions,
157
+ typename = EnableIfOneDimension<N>,
158
+ typename = EnableIfContiguous<Container>>
159
+ buffer (Container &container, const property_list &propList = {})
160
+ : buffer(container, {}, propList) {}
161
+
129
162
buffer (buffer<T, dimensions, AllocatorT> &b, const id<dimensions> &baseIndex,
130
163
const range<dimensions> &subRange)
131
164
: impl(b.impl), Range(subRange),
@@ -317,6 +350,30 @@ class buffer {
317
350
return newRange[1 ] == parentRange[1 ] && newRange[2 ] == parentRange[2 ];
318
351
}
319
352
};
353
+
354
+ #ifdef __cpp_deduction_guides
355
+ template <class InputIterator , class AllocatorT >
356
+ buffer (InputIterator, InputIterator, AllocatorT, const property_list & = {})
357
+ ->buffer<typename std::iterator_traits<InputIterator>::value_type, 1,
358
+ AllocatorT>;
359
+ template <class InputIterator >
360
+ buffer (InputIterator, InputIterator, const property_list & = {})
361
+ ->buffer<typename std::iterator_traits<InputIterator>::value_type, 1>;
362
+ template <class Container , class AllocatorT >
363
+ buffer (Container &, AllocatorT, const property_list & = {})
364
+ ->buffer<typename Container::value_type, 1, AllocatorT>;
365
+ template <class Container >
366
+ buffer (Container &, const property_list & = {})
367
+ ->buffer<typename Container::value_type, 1>;
368
+ template <class T , int dimensions, class AllocatorT >
369
+ buffer (const T *, const range<dimensions> &, AllocatorT,
370
+ const property_list & = {})
371
+ ->buffer<T, dimensions, AllocatorT>;
372
+ template <class T , int dimensions>
373
+ buffer (const T *, const range<dimensions> &, const property_list & = {})
374
+ ->buffer<T, dimensions>;
375
+ #endif // __cpp_deduction_guides
376
+
320
377
} // namespace sycl
321
378
} // namespace cl
322
379
0 commit comments