Async++ unknown
Async (co_await/co_return) code for C++
Loading...
Searching...
No Matches
parameter_pack.h
1#pragma once
2#include <cstddef>
3#include <utility>
4
5namespace asyncpp::detail {
6 class parameter_pack {
7 template<size_t Index, typename Arg0, typename... Args>
8 static constexpr decltype(auto) get_at_index_impl(Arg0&& first_arg, Args&&... args) noexcept {
9 if constexpr (Index == 0) {
10 return std::forward<Arg0>(first_arg);
11 } else {
12 return get_at_index_impl<Index - 1>(std::forward<Args>(args)...);
13 }
14 }
15
16 public:
17 parameter_pack() = delete;
18
19 template<size_t Index, typename... Args>
20 static constexpr decltype(auto) get_at_index(Args&&... args) noexcept {
21 static_assert(Index < sizeof...(Args), "index out of range");
22 return get_at_index_impl<Index>(std::forward<Args>(args)...);
23 }
24
25 template<typename... Args>
26 static constexpr decltype(auto) get_last(Args&&... args) noexcept {
27 static_assert(0 < sizeof...(Args), "parameter pack is empty");
28 return get_at_index_impl<sizeof...(Args) - 1>(std::forward<Args>(args)...);
29 }
30 };
31
32} // namespace asyncpp::detail