mirror of
https://github.com/catchorg/Catch2.git
synced 2025-10-09 04:05:39 +02:00
Remove recursion when stringifying std::tuple
This commit is contained in:

committed by
Martin Hořeňovský

parent
a58df2d7c5
commit
33e6fd217a
@@ -407,44 +407,38 @@ namespace Catch {
|
|||||||
|
|
||||||
// Separate std::tuple specialization
|
// Separate std::tuple specialization
|
||||||
#if defined(CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER)
|
#if defined(CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER)
|
||||||
#include <tuple>
|
# include <tuple>
|
||||||
|
# include <utility>
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
namespace Detail {
|
namespace Detail {
|
||||||
template<
|
template <typename Tuple, std::size_t... Is>
|
||||||
typename Tuple,
|
void PrintTuple( const Tuple& tuple,
|
||||||
std::size_t N = 0,
|
std::ostream& os,
|
||||||
bool = (N < std::tuple_size<Tuple>::value)
|
std::index_sequence<Is...> ) {
|
||||||
>
|
// 1 + Account for when the tuple is empty
|
||||||
struct TupleElementPrinter {
|
char a[1 + sizeof...( Is )] = {
|
||||||
static void print(const Tuple& tuple, std::ostream& os) {
|
( ( os << ( Is ? ", " : " " )
|
||||||
os << (N ? ", " : " ")
|
<< ::Catch::Detail::stringify( std::get<Is>( tuple ) ) ),
|
||||||
<< ::Catch::Detail::stringify(std::get<N>(tuple));
|
'\0' )... };
|
||||||
TupleElementPrinter<Tuple, N + 1>::print(tuple, os);
|
(void)a;
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<
|
|
||||||
typename Tuple,
|
|
||||||
std::size_t N
|
|
||||||
>
|
|
||||||
struct TupleElementPrinter<Tuple, N, false> {
|
|
||||||
static void print(const Tuple&, std::ostream&) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace Detail
|
||||||
|
|
||||||
template<typename ...Types>
|
template <typename... Types>
|
||||||
struct StringMaker<std::tuple<Types...>> {
|
struct StringMaker<std::tuple<Types...>> {
|
||||||
static std::string convert(const std::tuple<Types...>& tuple) {
|
static std::string convert( const std::tuple<Types...>& tuple ) {
|
||||||
ReusableStringStream rss;
|
ReusableStringStream rss;
|
||||||
rss << '{';
|
rss << '{';
|
||||||
Detail::TupleElementPrinter<std::tuple<Types...>>::print(tuple, rss.get());
|
Detail::PrintTuple(
|
||||||
|
tuple,
|
||||||
|
rss.get(),
|
||||||
|
std::make_index_sequence<sizeof...( Types )>{} );
|
||||||
rss << " }";
|
rss << " }";
|
||||||
return rss.str();
|
return rss.str();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
} // namespace Catch
|
||||||
#endif // CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER
|
#endif // CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER
|
||||||
|
|
||||||
#if defined(CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER) && defined(CATCH_CONFIG_CPP17_VARIANT)
|
#if defined(CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER) && defined(CATCH_CONFIG_CPP17_VARIANT)
|
||||||
|
Reference in New Issue
Block a user