-
Notifications
You must be signed in to change notification settings - Fork 8
support template instantiation using integral values #137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
support template instantiation using integral values #137
Conversation
static inline | ||
bool is_integral(std::string& s) | ||
{ | ||
if (s == "false") { s = "0"; return true; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably need a clang::Lexer
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaking clang::Lexer
into clingwrapper? I believe that should be abstracted into CppInterOp...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize that is going to be an overkill and yes, @aaronj0 is right -- we can't really do it. The question is if we want to support that case? Especially the comma separated argument list in a form of string...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am really not seeing if In [6]: gbl.add["int, 7"](5)
is something useful and worth supporting. In cppyy upstream it was easy to implement but it is really worth implementing it. cc: @wlav.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a legitimate use, but an unlikely one b/c both "int" and "7" are valid Python objects, so no quotes needed. I.e., writing "int, 7"
is more work than writing int, 7
and thus unlikely. I would also assume that in practice the integer is programmatically established, in which case again it's be a number and not a string.
I don't have a test case that looks like this, which may mean no-one ever asked for it, but that may also be b/c it simply worked.
The only case I may see a use, is if the literal is typed. So e.g. if the templated function is overloaded with the second argument being either C++ double
or C++ float
and it is expected that the literal is either 3.14
or 3.14f
or some such. You can't do that in python: it'd have to be a string. (A workaround could be to use a numpy.float32
.)
All that said, see it as a challenge. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But in that case we will pass it as “3.14f” instead of “something, something, 3.14f”. The former is way simpler to support than the latter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move forward with the proposed approach. Can we add a fixme capturing the debate whether we want to support that feature.
Hi @vgvassilev, the string parsing is required here. Because cppyy allows instantiation using strings. For example:
Enables 5 tests: