In the simple parser library I am writing, the results of multiple parsers is combined using std::tuple_cat
. But when applying a parser that returns the same result
Here's one way to do it:
#include
#include
#include
#include
template
auto to_vector_helper(const tuple_type &t, std::index_sequence)
{
return std::vector{
std::get(t)...
};
}
template
auto to_vector(const std::tuple &t)
{
typedef typename std::remove_reference::type tuple_type;
constexpr auto s =
std::tuple_size::value;
return to_vector_helper
(t, std::make_index_sequence{});
}
int main()
{
std::tuple t{2,3};
std::vector v=to_vector(t);
std::cout << v[0] << ' ' << v[1] << ' ' << v.size() << std::endl;
return 0;
}