Skip to content

Commit e0fc271

Browse files
authored
Merge pull request #151 from FabienPean/feature/array_indexing
Allow indexing by operator[] when dimension is 1
2 parents f2aeddc + 18442c5 commit e0fc271

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

Fastor/tensor/ScalarIndexing.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ template<typename... Args, typename std::enable_if<sizeof...(Args)==dimension_t:
99
FASTOR_INLINE T& operator()(Args ... args) {
1010
return _data[get_flat_index(args...)];
1111
}
12+
template<typename Arg, typename std::enable_if<1==dimension_t::value &&
13+
is_arithmetic_pack<Arg>::value,bool>::type =0>
14+
FASTOR_INLINE T& operator[](Arg arg) {
15+
return _data[get_flat_index(arg)];
16+
}
1217
//----------------------------------------------------------------------------------------------------------//
1318

1419
#endif // SCALAR_INDEXING_NONCONST_H
@@ -24,7 +29,11 @@ template<typename... Args, typename std::enable_if<sizeof...(Args)==dimension_t:
2429
constexpr FASTOR_INLINE const T& operator()(Args ... args) const {
2530
return _data[get_flat_index(args...)];
2631
}
27-
32+
template<typename Arg, typename std::enable_if<1==dimension_t::value &&
33+
is_arithmetic_pack<Arg>::value,bool>::type =0>
34+
constexpr FASTOR_INLINE const T& operator[](Arg arg) const {
35+
return _data[get_flat_index(arg)];
36+
}
2837
//----------------------------------------------------------------------------------------------------------//
2938

3039
#endif // SCALAR_INDEXING_CONST_H

0 commit comments

Comments
 (0)