#ifndef RFL_INTERNAL_NTH_ELEMENT_HPP_ #define RFL_INTERNAL_NTH_ELEMENT_HPP_ #include namespace rfl::internal { template struct ElementWrapper { T t_; }; template constexpr auto operator|(const ElementWrapper& _e1, const ElementWrapper& _e2) { if constexpr (_i1 == N) { return _e1; } else { return _e2; } } template constexpr auto find_matching_element(const Head& _head, const Tail&... _tail) { return (_head | ... | _tail); }; template constexpr auto wrap_elements(Ts... _ts, std::integer_sequence) { return find_matching_element(ElementWrapper{_ts}...).t_; } template constexpr auto nth_element(Ts... _ts) { static_assert(N >= 0, "N out of bounds."); static_assert(N < sizeof...(Ts), "N out of bounds."); return wrap_elements( _ts..., std::make_integer_sequence()); } } // namespace rfl::internal #endif