introspection: return the template parameters of a type

This commit is contained in:
Danny Robson 2020-02-27 07:59:55 +11:00
parent 813148ca51
commit 7c92271296

View File

@ -10,6 +10,7 @@
#include "std.hpp" #include "std.hpp"
#include "variadic.hpp" #include "variadic.hpp"
#include "algo/search.hpp"
#include <cruft/util/preprocessor.hpp> #include <cruft/util/preprocessor.hpp>
@ -63,9 +64,18 @@ namespace cruft {
std::end (suffixes) std::end (suffixes)
); );
// Find the start of the first template parameter (or the end of the
// string otherwise), and the end of the template parameters for this
// type.
//
// This cursor will be used to limit the scope of the namespace removal
// we're about to do.
auto const first_template = std::find (ns_begin, type_end, '<');
auto const end_first_template = cruft::search::balanced (first_template, type_end, '<', '>');
// Find the end of any namespace symbols // Find the end of any namespace symbols
auto const ns_symbol = std::find ( auto const ns_symbol = std::find (
std::make_reverse_iterator (type_end), std::make_reverse_iterator (first_template),
std::make_reverse_iterator (ns_begin), std::make_reverse_iterator (ns_begin),
':' ':'
); );
@ -74,7 +84,7 @@ namespace cruft {
auto const data = ns_symbol != std::make_reverse_iterator (ns_begin) auto const data = ns_symbol != std::make_reverse_iterator (ns_begin)
? &*ns_symbol + 1 ? &*ns_symbol + 1
: ns_begin + prefix.size (); : ns_begin + prefix.size ();
auto const size = std::distance (data, type_end); auto const size = std::distance (data, end_first_template);
return std::string_view (data, size); return std::string_view (data, size);
} }