Skip to content

Commit 4cd791e

Browse files
authored
Use non-resolving version of array_ref::array_ref where appropriate (#98)
* Use non-resolving version of array_ref::array_ref where appropriate * Use no_resolve tag type instead of std::false_type
1 parent 8fe608c commit 4cd791e

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

include/array/array.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,9 +1965,11 @@ NDARRAY_HOST_DEVICE array_ref<T, Shape> make_array_ref(T* base, const Shape& sha
19651965

19661966
namespace internal {
19671967

1968+
struct no_resolve {};
1969+
19681970
template <class T, class Shape>
19691971
NDARRAY_HOST_DEVICE array_ref<T, Shape> make_array_ref_no_resolve(T* base, const Shape& shape) {
1970-
return {base, shape, std::false_type()};
1972+
return {base, shape, no_resolve{}};
19711973
}
19721974

19731975
template <class T, class Shape, class... Args>
@@ -2032,7 +2034,7 @@ class array_ref {
20322034
shape_.resolve();
20332035
}
20342036

2035-
NDARRAY_HOST_DEVICE array_ref(pointer base, const Shape& shape, std::false_type /*resolve*/)
2037+
NDARRAY_HOST_DEVICE array_ref(pointer base, const Shape& shape, internal::no_resolve)
20362038
: base_(base), shape_(shape) {}
20372039

20382040
/** Shallow copy or assign an array_ref. */
@@ -2044,7 +2046,7 @@ class array_ref {
20442046
/** Shallow copy or assign an array_ref with a different shape type. */
20452047
template <class OtherShape, class = enable_if_shape_compatible<OtherShape>>
20462048
NDARRAY_HOST_DEVICE array_ref(const array_ref<T, OtherShape>& other)
2047-
: array_ref(other.base(), other.shape(), std::false_type()) {}
2049+
: array_ref(other.base(), other.shape(), internal::no_resolve{}) {}
20482050
template <class OtherShape, class = enable_if_shape_compatible<OtherShape>>
20492051
NDARRAY_HOST_DEVICE array_ref& operator=(const array_ref<T, OtherShape>& other) {
20502052
base_ = other.base();
@@ -2165,7 +2167,7 @@ class array_ref {
21652167

21662168
/** Allow conversion from array_ref<T> to const_array_ref<T>. */
21672169
NDARRAY_HOST_DEVICE const const_array_ref<T, Shape> cref() const {
2168-
return const_array_ref<T, Shape>(base_, shape_);
2170+
return const_array_ref<T, Shape>(base_, shape_, internal::no_resolve{});
21692171
}
21702172
NDARRAY_HOST_DEVICE operator const_array_ref<T, Shape>() const { return cref(); }
21712173

@@ -2662,8 +2664,10 @@ class array {
26622664
}
26632665

26642666
/** Make an array_ref referring to the data in this array. */
2665-
array_ref<T, Shape> ref() { return array_ref<T, Shape>(base_, shape_); }
2666-
const_array_ref<T, Shape> cref() const { return const_array_ref<T, Shape>(base_, shape_); }
2667+
array_ref<T, Shape> ref() { return array_ref<T, Shape>(base_, shape_, internal::no_resolve{}); }
2668+
const_array_ref<T, Shape> cref() const {
2669+
return const_array_ref<T, Shape>(base_, shape_, internal::no_resolve{});
2670+
}
26672671
const_array_ref<T, Shape> ref() const { return cref(); }
26682672
operator array_ref<T, Shape>() { return ref(); }
26692673
operator const_array_ref<T, Shape>() const { return cref(); }
@@ -2939,7 +2943,7 @@ bool equal(const array<TA, ShapeA, AllocA>& a, const array<TB, ShapeB, AllocB>&
29392943
* `NewShape`. The new shape is copy constructed from `a.shape()`. */
29402944
template <class NewShape, class T, class OldShape>
29412945
NDARRAY_HOST_DEVICE array_ref<T, NewShape> convert_shape(const array_ref<T, OldShape>& a) {
2942-
return array_ref<T, NewShape>(a.base(), convert_shape<NewShape>(a.shape()));
2946+
return array_ref<T, NewShape>(a.base(), convert_shape<NewShape>(a.shape()), internal::no_resolve{});
29432947
}
29442948
template <class NewShape, class T, class OldShape, class Allocator>
29452949
array_ref<T, NewShape> convert_shape(array<T, OldShape, Allocator>& a) {
@@ -2954,7 +2958,7 @@ const_array_ref<T, NewShape> convert_shape(const array<T, OldShape, Allocator>&
29542958
* `U`. `sizeof(T)` must be equal to `sizeof(U)`. */
29552959
template <class U, class T, class Shape, class = std::enable_if_t<sizeof(T) == sizeof(U)>>
29562960
NDARRAY_HOST_DEVICE array_ref<U, Shape> reinterpret(const array_ref<T, Shape>& a) {
2957-
return array_ref<U, Shape>(reinterpret_cast<U*>(a.base()), a.shape());
2961+
return array_ref<U, Shape>(reinterpret_cast<U*>(a.base()), a.shape(), internal::no_resolve{});
29582962
}
29592963
template <class U, class T, class Shape, class Alloc,
29602964
class = std::enable_if_t<sizeof(T) == sizeof(U)>>
@@ -2971,7 +2975,7 @@ const_array_ref<U, Shape> reinterpret(const array<T, Shape, Alloc>& a) {
29712975
* type `U` using `const_cast`. */
29722976
template <class U, class T, class Shape>
29732977
array_ref<U, Shape> reinterpret_const(const const_array_ref<T, Shape>& a) {
2974-
return array_ref<U, Shape>(const_cast<U*>(a.base()), a.shape());
2978+
return array_ref<U, Shape>(const_cast<U*>(a.base()), a.shape(), internal::no_resolve{});
29752979
}
29762980

29772981
/** Reinterpret the shape of the array or array_ref `a` to be a new shape

0 commit comments

Comments
 (0)