Skip to content

Commit

Permalink
Allow constructor of atlas::io::ArrayShape with different integer types
Browse files Browse the repository at this point in the history
  • Loading branch information
wdeconinck committed Oct 9, 2023
1 parent 24b8386 commit 0b1ed6b
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions atlas_io/src/atlas_io/types/array/ArrayMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <cstdint>
#include <string>
#include <type_traits>

#include "atlas_io/Metadata.h"
#include "atlas_io/detail/DataType.h"
Expand All @@ -36,6 +37,32 @@ class ArrayShape : public std::vector<size_t> {
ArrayShape(const std::array<idx_t, N>& list): Base(list.begin(), list.end()) {}
template <typename idx_t>
ArrayShape(const std::vector<idx_t>& list): Base(list.begin(), list.end()) {}
template <typename Int1, std::enable_if_t<std::is_integral_v<Int1>>>
ArrayShape(Int1 i) {
resize(1);
operator[](0) = i;
}
template <typename Int1, typename Int2, std::enable_if_t<std::is_integral_v<Int1> && std::is_integral_v<Int2>>>
ArrayShape(Int1 i, Int2 j) {
resize(2);
operator[](0) = i;
operator[](1) = j;
}
template <typename Int1, typename Int2, typename Int3, std::enable_if_t<std::is_integral_v<Int1> && std::is_integral_v<Int2> && std::is_integral_v<Int3>>>
ArrayShape(Int1 i, Int2 j, Int3 k) {
resize(3);
operator[](0) = i;
operator[](1) = j;
operator[](2) = k;
}
template <typename Int1, typename Int2, typename Int3, typename Int4, std::enable_if_t<std::is_integral_v<Int1> && std::is_integral_v<Int2> && std::is_integral_v<Int3> && std::is_integral_v<Int4>>>
ArrayShape(Int1 i, Int2 j, Int3 k, Int4 l) {
resize(4);
operator[](0) = i;
operator[](1) = j;
operator[](2) = k;
operator[](3) = l;
}
};

//---------------------------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit 0b1ed6b

Please sign in to comment.