Skip to content

Commit a4a53f6

Browse files
committed
Refactor shape tuples.
1 parent f16d8b5 commit a4a53f6

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

array.h

+12-13
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,6 @@ template <class Fn, class Args, size_t... Is>
468468
NDARRAY_INLINE auto apply(Fn&& fn, const Args& args, index_sequence<Is...>) {
469469
return fn(std::get<Is>(args)...);
470470
}
471-
472471
template <class Fn, class... Args>
473472
NDARRAY_INLINE auto apply(Fn&& fn, const std::tuple<Args...>& args) {
474473
return apply(fn, args, make_index_sequence<sizeof...(Args)>());
@@ -774,31 +773,31 @@ shape<Dims...> make_shape_from_tuple(const std::tuple<Dims...>& dims) {
774773
* 'outermost' dimension. */
775774
template <class... Dims>
776775
class shape {
777-
std::tuple<Dims...> dims_;
778-
779776
public:
777+
/** The type of the dims tuple of this shape. */
778+
using dims_type = std::tuple<Dims...>;
779+
780780
/** Number of dims in this shape. */
781-
static constexpr size_t rank() { return std::tuple_size<std::tuple<Dims...>>::value; }
781+
static constexpr size_t rank() { return std::tuple_size<dims_type>::value; }
782782

783783
/** A shape is scalar if it is rank 0. */
784784
static constexpr bool is_scalar() { return rank() == 0; }
785785

786786
/** The type of an index for this shape. */
787787
using index_type = typename internal::tuple_of_n<index_t, rank()>::type;
788788

789-
/** The type of the dims tuple of this shape. */
790-
using dims_type = std::tuple<Dims...>;
791-
792789
using size_type = size_t;
793790

794791
private:
795-
// TODO: This should use std::is_constructible<std::tuple<Dims...>, std::tuple<OtherDims...>>
792+
dims_type dims_;
793+
794+
// TODO: This should use std::is_constructible<dims_type, std::tuple<OtherDims...>>
796795
// but it is broken on some compilers (https://github.com/dsharlet/array/issues/20).
797796
template <class... OtherDims>
798797
using enable_if_dims_compatible = typename std::enable_if<sizeof...(OtherDims) == rank()>::type;
799798

800799
template <class... Args>
801-
using enable_if_same_rank = typename std::enable_if<sizeof...(Args) == rank()>::type;
800+
using enable_if_same_rank = typename std::enable_if<(sizeof...(Args) == rank())>::type;
802801

803802
template <class... Args>
804803
using enable_if_indices =
@@ -810,7 +809,7 @@ class shape {
810809
!internal::all_of_type<index_t, Args...>::value>::type;
811810

812811
template <size_t Dim>
813-
using enable_if_dim = typename std::enable_if<Dim < rank()>::type;
812+
using enable_if_dim = typename std::enable_if<(Dim < rank())>::type;
814813

815814
public:
816815
shape() {}
@@ -822,7 +821,7 @@ class shape {
822821
shape(shape&&) = default;
823822

824823
/** Construct a shape from a tuple of `dims` of another type. */
825-
// We cannot have an std::tuple<Dims...> constructor because it will be
824+
// We cannot have an dims_type constructor because it will be
826825
// ambiguous with the Dims... constructor for 1D shapes.
827826
template <class... OtherDims, class = enable_if_dims_compatible<OtherDims...>>
828827
shape(const std::tuple<OtherDims...>& dims) : dims_(dims) {}
@@ -909,8 +908,8 @@ class shape {
909908
}
910909

911910
/** Get a tuple of all of the dims of this shape. */
912-
std::tuple<Dims...>& dims() { return dims_; }
913-
const std::tuple<Dims...>& dims() const { return dims_; }
911+
dims_type& dims() { return dims_; }
912+
const dims_type& dims() const { return dims_; }
914913

915914
/** Get an index pointing to the min or max index in each dimension of this
916915
* shape. */

0 commit comments

Comments
 (0)