how would you (efficiently if possible) transform a string like
"class sfw::Smthing<class sfw::type<double>,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >"
to
"class sfw::Smthing<class sfw::type<...>,class std::basic_string<...> >"
in C++ using at most the stl?
I won’t do all the work for you, but I’ll give you the basic idea.
Scan through the string with a for loop. Keep track of what level of template argument you are at. You can do that by counting up when you find a
'<', and counting down when you find'>'.When you’re inside the 2nd level (that is, the template arguments of the template arguments of the outer type) or deeper, replace the character. Either replace it with a period, or, if you’ve placed 3 or more consecutive periods (another variable needed), replace it with a character which you know will not be anywhere else in the character set, like
'@'.Once you’ve done that, your string will look like this:
Then all you need to do is remove every ‘@’: