draconisplusplus/include/rfl/as.hpp

37 lines
984 B
C++
Raw Normal View History

2024-05-31 22:59:00 -04:00
#ifndef RFL_AS_HPP_
#define RFL_AS_HPP_
#include "from_named_tuple.hpp"
#include "make_named_tuple.hpp"
#include "to_named_tuple.hpp"
namespace rfl {
2024-06-08 14:10:59 -04:00
/// Generates a type T from the input values.
template <class T, class Head, class... Tail>
T as(Head&& _head, Tail&&... _tail) {
2024-05-31 22:59:00 -04:00
if constexpr (sizeof...(_tail) == 0) {
2024-06-08 14:10:59 -04:00
return from_named_tuple<T>(to_named_tuple(std::forward<Head>(_head)));
2024-05-31 22:59:00 -04:00
} else {
2024-06-08 14:10:59 -04:00
return from_named_tuple<T>(
to_named_tuple(std::forward<Head>(_head))
2024-06-08 15:53:06 -04:00
.add(to_named_tuple(std::forward<Tail>(_tail))...)
);
2024-05-31 22:59:00 -04:00
}
2024-06-08 14:10:59 -04:00
}
2024-05-31 22:59:00 -04:00
2024-06-08 14:10:59 -04:00
/// Generates a type T from the input values.
template <class T, class Head, class... Tail>
T as(const Head& _head, const Tail&... _tail) {
2024-05-31 22:59:00 -04:00
if constexpr (sizeof...(_tail) == 0) {
2024-06-08 14:10:59 -04:00
return from_named_tuple<T>(to_named_tuple(_head));
2024-05-31 22:59:00 -04:00
} else {
2024-06-08 15:53:06 -04:00
return from_named_tuple<T>(to_named_tuple(_head).add(to_named_tuple(_tail
)...));
2024-05-31 22:59:00 -04:00
}
2024-06-08 14:10:59 -04:00
}
2024-05-31 22:59:00 -04:00
2024-06-08 14:10:59 -04:00
} // namespace rfl
2024-05-31 22:59:00 -04:00
#endif