Skip to content

Commit b027ecf

Browse files
authored
Merge pull request #40 from uonrobotics/refactor-use-autoref
perfect forwarding with auto&&
2 parents 40fd8e1 + 53c72a8 commit b027ecf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+324
-380
lines changed

benchmarks/isclose/none/source.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ template <typename T> inline void test(benchmark::State &state) noexcept {
1818
auto out = md::mdarray<T, md::dims<1>>{md::dims<1>{set_num}};
1919

2020
for (auto _ : state) {
21-
md::isclose(in1, in2, out);
21+
md::isclose_to(in1, in2, out);
2222
}
2323

2424
state.SetComplexityN(state.range(0));

ctmd/absolute.hpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,26 @@ inline constexpr void absolute_impl(const in_t &in, const out_t &out) noexcept {
2020

2121
} // namespace detail
2222

23-
template <typename InType, typename OutType>
24-
inline constexpr void absolute(InType &&In, OutType &&Out,
23+
inline constexpr void absolute(auto &&In, auto &&Out,
2524
const MPMode mpmode = MPMode::NONE) noexcept {
2625
core::batch(
2726
[](auto &&...elems) {
2827
detail::absolute_impl(std::forward<decltype(elems)>(elems)...);
2928
},
3029
std::index_sequence<0, 0>{}, mpmode,
31-
core::to_const_mdspan(std::forward<InType>(In)),
32-
core::to_const_mdspan(std::forward<OutType>(Out)));
30+
core::to_const_mdspan(std::forward<decltype(In)>(In)),
31+
core::to_const_mdspan(std::forward<decltype(Out)>(Out)));
3332
}
3433

35-
template <typename dtype = void, typename InType>
34+
template <typename dtype = void>
3635
[[nodiscard]] inline constexpr auto
37-
absolute(InType &&In, const MPMode mpmode = MPMode::NONE) noexcept {
36+
absolute(auto &&In, const MPMode mpmode = MPMode::NONE) noexcept {
3837
return core::batch_out<dtype>(
3938
[](auto &&...elems) {
4039
detail::absolute_impl(std::forward<decltype(elems)>(elems)...);
4140
},
4241
std::index_sequence<0>{}, ctmd::extents<uint8_t>{}, mpmode,
43-
core::to_const_mdspan(std::forward<InType>(In)));
42+
core::to_const_mdspan(std::forward<decltype(In)>(In)));
4443
}
4544

4645
} // namespace ctmd

ctmd/add.hpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,19 @@ inline constexpr void add_impl(const in1_t &in1, const in2_t &in2,
3737
*
3838
* @note Equivalent to In1 + In2 = Out in terms of array broadcasting.
3939
*
40-
* @see ctmd::add(In1Type&&, In2Type&&, MPMode) for the in-place version that
41-
* returns the result.
40+
* @see ctmd::add(auto&&, auto&&, MPMode) for the in-place version that returns
41+
* the result.
4242
*/
43-
template <typename In1Type, typename In2Type, typename OutType>
44-
inline constexpr void add(In1Type &&In1, In2Type &&In2, OutType &&Out,
43+
inline constexpr void add(auto &&In1, auto &&In2, auto &&Out,
4544
const MPMode mpmode = MPMode::NONE) noexcept {
4645
core::batch(
4746
[](auto &&...elems) {
4847
detail::add_impl(std::forward<decltype(elems)>(elems)...);
4948
},
5049
std::index_sequence<0, 0, 0>{}, mpmode,
51-
core::to_const_mdspan(std::forward<In1Type>(In1)),
52-
core::to_const_mdspan(std::forward<In2Type>(In2)),
53-
core::to_mdspan(std::forward<OutType>(Out)));
50+
core::to_const_mdspan(std::forward<decltype(In1)>(In1)),
51+
core::to_const_mdspan(std::forward<decltype(In2)>(In2)),
52+
core::to_mdspan(std::forward<decltype(Out)>(Out)));
5453
}
5554

5655
/**
@@ -67,19 +66,19 @@ inline constexpr void add(In1Type &&In1, In2Type &&In2, OutType &&Out,
6766
*
6867
* @note Equivalent to In1 + In2 = Out in terms of array broadcasting.
6968
*
70-
* @see ctmd::add(In1Type&&, In2Type&&, OutType&&, MPMode) for the in-place
71-
* version that modifies the output.
69+
* @see ctmd::add(auto&&, auto&&, auto&&, MPMode) for the in-place version that
70+
* modifies the output.
7271
*/
73-
template <typename dtype = void, typename In1Type, typename In2Type>
72+
template <typename dtype = void>
7473
[[nodiscard]] inline constexpr auto
75-
add(In1Type &&In1, In2Type &&In2, const MPMode mpmode = MPMode::NONE) noexcept {
74+
add(auto &&In1, auto &&In2, const MPMode mpmode = MPMode::NONE) noexcept {
7675
return core::batch_out<dtype>(
7776
[](auto &&...elems) {
7877
detail::add_impl(std::forward<decltype(elems)>(elems)...);
7978
},
8079
std::index_sequence<0, 0>{}, ctmd::extents<uint8_t>{}, mpmode,
81-
core::to_const_mdspan(std::forward<In1Type>(In1)),
82-
core::to_const_mdspan(std::forward<In2Type>(In2)));
80+
core::to_const_mdspan(std::forward<decltype(In1)>(In1)),
81+
core::to_const_mdspan(std::forward<decltype(In2)>(In2)));
8382
}
8483

8584
} // namespace ctmd

ctmd/all.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55
namespace ctmd {
66

7-
template <typename InType>
8-
[[nodiscard]] inline constexpr bool all(InType &&In) noexcept {
9-
const auto in = core::to_const_mdspan(std::forward<InType>(In));
7+
[[nodiscard]] inline constexpr bool all(auto &&In) noexcept {
8+
const auto in = core::to_const_mdspan(std::forward<decltype(In)>(In));
109
using in_t = decltype(in);
1110

1211
if constexpr (in_t::rank() == 0) {

ctmd/allclose.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55

66
namespace ctmd {
77

8-
template <typename In1Type, typename In2Type>
98
[[nodiscard]] inline constexpr bool
10-
allclose(In1Type &&In1, In2Type &&In2, const double &rtol = 1e-05,
9+
allclose(auto &&In1, auto &&In2, const double &rtol = 1e-05,
1110
const double &atol = 1e-08,
1211
const MPMode mpmode = MPMode::NONE) noexcept {
13-
return ctmd::all(ctmd::isclose(std::forward<In1Type>(In1),
14-
std::forward<In2Type>(In2), rtol, atol,
12+
return ctmd::all(ctmd::isclose(std::forward<decltype(In1)>(In1),
13+
std::forward<decltype(In2)>(In2), rtol, atol,
1514
mpmode));
1615
}
1716

ctmd/array_equal.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44

55
namespace ctmd {
66

7-
template <typename In1Type, typename In2Type>
8-
[[nodiscard]] inline constexpr bool array_equal(In1Type &&In1,
9-
In2Type &&In2) noexcept {
10-
const auto in1 = core::to_const_mdspan(std::forward<In1Type>(In1));
11-
const auto in2 = core::to_const_mdspan(std::forward<In2Type>(In2));
7+
[[nodiscard]] inline constexpr bool array_equal(auto &&In1,
8+
auto &&In2) noexcept {
9+
const auto in1 = core::to_const_mdspan(std::forward<decltype(In1)>(In1));
10+
const auto in2 = core::to_const_mdspan(std::forward<decltype(In2)>(In2));
1211
using in1_t = decltype(in1);
1312
using in2_t = decltype(in2);
1413

ctmd/array_equiv.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55

66
namespace ctmd {
77

8-
template <typename In1Type, typename In2Type>
98
[[nodiscard]] inline constexpr bool
10-
array_equiv(In1Type &&In1, In2Type &&In2,
9+
array_equiv(auto &&In1, auto &&In2,
1110
const MPMode mpmode = MPMode::NONE) noexcept {
12-
return ctmd::all(ctmd::equal(std::forward<In1Type>(In1),
13-
std::forward<In2Type>(In2), mpmode));
11+
return ctmd::all(ctmd::equal(std::forward<decltype(In1)>(In1),
12+
std::forward<decltype(In2)>(In2), mpmode));
1413
}
1514

1615
} // namespace ctmd

ctmd/atan2.hpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,28 @@ inline constexpr void atan2_impl(const in1_t &in1, const in2_t &in2,
1818

1919
} // namespace detail
2020

21-
template <typename In1Type, typename In2Type, typename OutType>
22-
inline constexpr void atan2(In1Type &&In1, In2Type &&In2, OutType &&Out,
21+
inline constexpr void atan2(auto &&In1, auto &&In2, auto &&Out,
2322
const MPMode mpmode = MPMode::NONE) noexcept {
2423
core::batch(
2524
[](auto &&...elems) {
2625
detail::atan2_impl(std::forward<decltype(elems)>(elems)...);
2726
},
2827
std::index_sequence<0, 0, 0>{}, mpmode,
29-
core::to_const_mdspan(std::forward<In1Type>(In1)),
30-
core::to_const_mdspan(std::forward<In2Type>(In2)),
31-
core::to_mdspan(std::forward<OutType>(Out)));
28+
core::to_const_mdspan(std::forward<decltype(In1)>(In1)),
29+
core::to_const_mdspan(std::forward<decltype(In2)>(In2)),
30+
core::to_mdspan(std::forward<decltype(Out)>(Out)));
3231
}
3332

34-
template <typename dtype = void, typename In1Type, typename In2Type>
33+
template <typename dtype = void>
3534
[[nodiscard]] inline constexpr auto
36-
atan2(In1Type &&In1, In2Type &&In2,
37-
const MPMode mpmode = MPMode::NONE) noexcept {
35+
atan2(auto &&In1, auto &&In2, const MPMode mpmode = MPMode::NONE) noexcept {
3836
return core::batch_out<dtype>(
3937
[](auto &&...elems) {
4038
detail::atan2_impl(std::forward<decltype(elems)>(elems)...);
4139
},
4240
std::index_sequence<0, 0>{}, ctmd::extents<uint8_t>{}, mpmode,
43-
core::to_const_mdspan(std::forward<In1Type>(In1)),
44-
core::to_const_mdspan(std::forward<In2Type>(In2)));
41+
core::to_const_mdspan(std::forward<decltype(In1)>(In1)),
42+
core::to_const_mdspan(std::forward<decltype(In2)>(In2)));
4543
}
4644

4745
} // namespace ctmd

ctmd/clip.hpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,31 @@ inline constexpr void clip_impl(const in_t &in, const min_t &min,
2424

2525
} // namespace detail
2626

27-
template <typename InType, typename MinType, typename MaxType, typename OutType>
28-
inline constexpr void clip(InType &&In, MinType &&Min, MaxType &&Max,
29-
OutType &&Out,
27+
inline constexpr void clip(auto &&In, auto &&Min, auto &&Max, auto &&Out,
3028
const MPMode mpmode = MPMode::NONE) noexcept {
3129
core::batch(
3230
[](auto &&...elems) {
3331
detail::clip_impl(std::forward<decltype(elems)>(elems)...);
3432
},
3533
std::index_sequence<0, 0, 0, 0>{}, mpmode,
36-
core::to_const_mdspan(std::forward<InType>(In)),
37-
core::to_const_mdspan(std::forward<MinType>(Min)),
38-
core::to_const_mdspan(std::forward<MaxType>(Max)),
39-
core::to_mdspan(std::forward<OutType>(Out)));
34+
core::to_const_mdspan(std::forward<decltype(In)>(In)),
35+
core::to_const_mdspan(std::forward<decltype(Min)>(Min)),
36+
core::to_const_mdspan(std::forward<decltype(Max)>(Max)),
37+
core::to_mdspan(std::forward<decltype(Out)>(Out)));
4038
}
4139

42-
template <typename dtype = void, typename InType, typename MinType,
43-
typename MaxType>
40+
template <typename dtype = void>
4441
[[nodiscard]] inline constexpr auto
45-
clip(InType &&In, MinType &&Min, MaxType &&Max,
42+
clip(auto &&In, auto &&Min, auto &&Max,
4643
const MPMode mpmode = MPMode::NONE) noexcept {
4744
return core::batch_out<dtype>(
4845
[](auto &&...elems) {
4946
detail::clip_impl(std::forward<decltype(elems)>(elems)...);
5047
},
5148
std::index_sequence<0, 0, 0>{}, ctmd::extents<uint8_t>{}, mpmode,
52-
core::to_const_mdspan(std::forward<InType>(In)),
53-
core::to_const_mdspan(std::forward<MinType>(Min)),
54-
core::to_const_mdspan(std::forward<MaxType>(Max)));
49+
core::to_const_mdspan(std::forward<decltype(In)>(In)),
50+
core::to_const_mdspan(std::forward<decltype(Min)>(Min)),
51+
core::to_const_mdspan(std::forward<decltype(Max)>(Max)));
5552
}
5653

5754
} // namespace ctmd

ctmd/copy.hpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,26 @@ inline constexpr void copy_impl(const in_t &in, const out_t &out) noexcept {
1313

1414
} // namespace detail
1515

16-
template <typename InType, typename OutType>
17-
inline constexpr void copy(InType &&In, OutType &&Out,
16+
inline constexpr void copy(auto &&In, auto &&Out,
1817
const MPMode mpmode = MPMode::NONE) noexcept {
1918
core::batch(
2019
[](auto &&...elems) {
2120
detail::copy_impl(std::forward<decltype(elems)>(elems)...);
2221
},
2322
std::index_sequence<0, 0>{}, mpmode,
24-
core::to_const_mdspan(std::forward<InType>(In)),
25-
core::to_mdspan(std::forward<OutType>(Out)));
23+
core::to_const_mdspan(std::forward<decltype(In)>(In)),
24+
core::to_mdspan(std::forward<decltype(Out)>(Out)));
2625
}
2726

28-
template <typename dtype = void, typename InType>
27+
template <typename dtype = void>
2928
[[nodiscard]] inline constexpr auto
30-
copy(InType &&In, const MPMode mpmode = MPMode::NONE) noexcept {
29+
copy(auto &&In, const MPMode mpmode = MPMode::NONE) noexcept {
3130
return core::batch_out<dtype>(
3231
[](auto &&...elems) {
3332
detail::copy_impl(std::forward<decltype(elems)>(elems)...);
3433
},
3534
std::index_sequence<0>{}, ctmd::extents<uint8_t>{}, mpmode,
36-
core::to_const_mdspan(std::forward<InType>(In)));
35+
core::to_const_mdspan(std::forward<decltype(In)>(In)));
3736
}
3837

3938
} // namespace ctmd

0 commit comments

Comments
 (0)