I am writing a lightweight parser combinator library (akin to Boost::Spirit) as hobby project.
One thing I'd like to do, is to automatically be able to convert a Result<std::tuple<char>>, Result<std::tuple<char, char>>, etc. into a std::string.
And similarly, if having e.g. a Result<std::tuple<int, int>> I'd like to be able to convert it to a Result<std::vector<int>> or more generally for any tuple containing zero or more elements of the same type T I'd like to be able to convert it automatically to a Result<Container<T>>.
How does one tackle something like this? I attempted for instance:
template<typename Container>
Result<decltype(std::make_from_tuple<Container>(std::declval<T>()))> () const {
Result{Container{std::make_from_tuple<std::initializer_list<typename std::tuple_element<0, T>::type>> (std::get<T>(*this))}};
}
but this does not work, as it turns out that it's not possible to create an initializer list programmatically like this.
live example on godbolt.org
More generic solution:
Usage: