Skip to content

Commit

Permalink
Use move instead of tuple for the early release
Browse files Browse the repository at this point in the history
  • Loading branch information
aurianer committed Aug 24, 2023
1 parent 35bdb51 commit 9dba07b
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions include/dlaf/common/consume_rvalues.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,26 @@
#include <utility>

namespace dlaf::common::internal {

template <typename T>
T consume_rvalue(T&& x) {
return std::move(x);
}

template <typename T>
T& consume_rvalue(T& x) {
return x;
}

/// ConsumeRvalues is a callable object wrapper that consumes rvalues passed as arguments
/// after calling the wrapped callable.
template <typename F>
struct ConsumeRvalues {
std::decay_t<F> f;

template <typename... Ts>
auto operator()(Ts&&... ts) -> decltype(std::move(f)(std::forward<Ts>(ts)...)) {
using result_type = decltype(std::move(f)(std::forward<Ts>(ts)...));
if constexpr (std::is_void_v<result_type>) {
std::move(f)(std::forward<Ts>(ts)...);
std::tuple<Ts...>(std::forward<Ts>(ts)...);
}
else {
auto r = std::move(f)(std::forward<Ts>(ts)...);
std::tuple<Ts...>(std::forward<Ts>(ts)...);
return r;
}
auto operator()(Ts&&... ts) -> decltype(std::move(f)(consume_rvalue(std::forward<Ts>(ts))...)) {
return std::move(f)(consume_rvalue(std::forward<Ts>(ts))...);
}
};

Expand Down

0 comments on commit 9dba07b

Please sign in to comment.