cppast
cppast copied to clipboard
Walking a template specialization
Consider std::vector<std::string>
used as return type somewhere. Is there a way to somehow use that return type and walk instantiation of class std::vector<std::string>
so that methods of std::vector
have std::string
type inserted where appropriate? Or do i have to resolve these template types manually somehow?
P.S. I hope i am not getting annoying with spamming issue tracker with random questions. If there is a better place to ask these things please let me know. P.P.S. Thank you for the help with other issues, i greatly appreciate swift response. Just never posted "thanks" messages to save you some spam in the mailbox :)
No, there is no way to do that.
Why do you need it?
I hope i am not getting annoying with spamming issue tracker with random questions. If there is a better place to ask these things please let me know.
No, it's okay.
I am using cppast to generate .net bindings for one project. Unfortunately some template containers are a big part of API and i am looking for ways to wrap these containers. I was considering to wrap every instantiation of template class as separate type with separate name so for example std::vector<std::string>
on c# side would end up being non-generic StringVector
type.
And you are looking for an automated way of generating such a StringVector
?
Yes indeed i am. I already have wrapper generation automated for good chunk of API. these template classes are like a last piece of puzzle.
Then I'm afraid there isn't an easy way to do it with the current API.
But is there a "non-easy" way to do it ?
trying to walk through a template instantiation, it seems that inner template arguments are unexposed and available as a string (for instance for std::vector<std::shared_ptr<std::string>>
unexposed_args contains std::shared_ptr<std::string>
but arguments are empty), but not as an entity tree, am I wrong ?
I thought I could be able to retrieve arguments then get back to their types through the arguments array, but the template instantiation parsing code (in cppast::type_parser.cpp) seems to only provide unexposed_arguments ?
I made a pull request (https://github.com/foonathan/cppast/pull/99) that parses every template instantiation argument. There may be limitations, but up till now it worked for instantiations such as std::vector<std::shared_ptr
The template instantiation full argument parsing is built when the option-DCPPAST_TEMPLATE_FULLARGUMENTSPARSING=ON is used upon invoking cmake.