Open benshiffman opened 6 months ago
There are 2 unrelated bugs involved here:
These lines do not reconstruct the parameter list correctly when a parameter is a template instance with no info for the explicit instance but with a generic info like the ones you found in InfoMap
for std::vector
(but also for std::shared_ptr
). This is due to these lines that substitute the type with the template argument and set indirection
to 1. std::vector<U>
ends up being replaced by U*
in the parameter list. So you can work around by writing:
new Info("TemplatedClass<double>::TemplatedClass<int>(U*)
instead of:
new Info("TemplatedClass<double>::TemplatedClass<int>(std::vector<U>)
I'm not sure how to fix this, and if it is worth. @saudet any idea ?
Using an info key without parameters should be enough in this case, just like you did for the function;
infoMap.put(new Info("TemplatedClass<double>::TemplatedClass<int>").define());
but that doesn't work because your class is in the top level namespace and in this case for constructors (and probably operators), an extra qualification by TemplateClass::
prevents the info query to match. I guess this one could be fixed.
you can work around by writing:
new Info("TemplatedClass<double>::TemplatedClass<int>(U*)
instead of:
new Info("TemplatedClass<double>::TemplatedClass<int>(std::vector<U>)
Confirmed that this does work.
- Using an info key without parameters should be enough in this case, just like you did for the function;
infoMap.put(new Info("TemplatedClass<double>::TemplatedClass<int>").define());
but that doesn't work because your class is in the top level namespace and in this case for constructors (and probably operators), an extra qualification by
TemplateClass::
prevents the info query to match. I guess this one could be fixed.
Would the same change apply to operators? Currently, only normal templated functions can be mapped without specifying parameters.
Would the same change apply to operators? Currently, only normal templated functions can be mapped without specifying parameters.
Hmm. Are you sure ? I just tested with an operator without specifying the parameter list and it does work, even in the top level namespace. For constructors it works only if your class is not in the top level namespace.
Strangely I get this
public native @Name("operator =<int>") void operator =(@StdVector @ByVal IntVec vec);
from this mapping:
infoMap.put(new Info("TemplatedClass<double>::operator =<int>").define());
BTW, if you don't need @StdVector
at all, you should be able to override that with something like InfoMap.putFirst(new Info("std::vector"))
in your presets.
Strangely I get this
public native @Name("operator =<int>") void operator =(@StdVector @ByVal IntVec vec);
from this mapping:
infoMap.put(new Info("TemplatedClass<double>::operator =<int>").define());
Right. So if you replace the define
by a .javaNames("put")
, you should be alright.
I'll try to find a fix for bug 2.
Strangely I get this
public native @Name("operator =<int>") void operator =(@StdVector @ByVal IntVec vec);
from this mapping:
infoMap.put(new Info("TemplatedClass<double>::operator =<int>").define());
Right. So if you replace the
define
by a.javaNames("put")
, you should be alright.I'll try to find a fix for bug 2.
I don't think we need a fix for that, that's how it's intended to work.
I'm not sure what you mean by "that". But what I meant by "bug 2" (from post https://github.com/bytedeco/javacpp/issues/735#issuecomment-1897066235) should be fixed by PR #739 you are about to merge.
Remains the fact (bug 1) that std::vector<U>
or std::shared_ptr<U>
is replaced by U*
in the function fullnames if there is no user info with this cpp name. I guess that we could fix that by avoiding to substitute the type here and maybe instead create a dynamic info. If you think it's worth I can try.
Remains the fact (bug 1) that
std::vector<U>
orstd::shared_ptr<U>
is replaced byU*
in the function fullnames if there is no user info with this cpp name. I guess that we could fix that by avoiding to substitute the type here and maybe instead create a dynamic info. If you think it's worth I can try.
If the workaround is good enough for now, probably not worth it, no
I think so. This is only hit when we have a templated function with overloads and that we need to add a user info with function parameters to instantiate a specific overload.
Workarounds are either to use U*
in the info, or to add a dummy info:
infoMap.add(new Info("std::vector<U>"));
As described in #732. Title pretty much sums it up. Templated constructors and operators (but not plain functions) are ignored when they have
std::vector
as a parameter. The behavior is the same whether or not the class itself is templated.Example:
Header:
InfoMapping:
With line 110 in
InfoMap.java
(.put(new Info("std::vector").annotations("@StdVector"))
) commented out:Without commenting out the line: