Open n3f4s opened 8 years ago
Yep, given template specialization is not available for rust (at least for stable), we can't do better than that.
Leaving this open so when it gets stabilized we aim to do something smarter. Until then there's not too much we can do that doing the generic one if found or the first instantiation if not :/
Oh, btw, thanks for filling this bugs, they're really useful :)
Would it be possible to do the same as with function (appending something at the end of the class name) ?
(Off-Topic but I don't know where to ask : once there is template specialization for rust, is it possible to use it for handling c++ overload... instead of generating multiple functions ?)
Yes, it would but then in rust you have MyTemplate<i32>
and MyTemplate_int
, and only the second is valid, which is clunky. Also, partial template specialization would be funny to handle.
Regarding the C++ function overloads... yes, I guess so (though it has to be written :P).
I was going to say that bindgen add a postfix to C++ template function, I checked to be sure and I saw that not specialized template function are not handled (same reason as template class I guess).
For C++ function overload, it would make more sense to use template specialization (IMHO). Having one (rust) function by (C++) overload would weird (having X functions with some obviously computer-generated postfix is not the best), and would cause function bloat in some case.
I'm not sure If bindgen
can properly support this. One thing that comes to mind would be monomorphizing everything under different names so that
template <typename T>
class test{};
template<>
class test<int> {
int foo;
};
template<>
class test<float> {
float foo;
};
becomes
struct Test<T> {}
struct TestInt { foo: c_int }
struct TestFloat { foo: c_float }
but I don't think this is a proper solution.
Unless rust add generic specialisation, I also don't think there's a good solution.
I think adding a warning when template specialisation is encountered in C++ code is required tho. Having code be silently ignored isn't good :).
Hi, bindgen ignore template specialization for class (and struct) and select the first "working answer". For example :
give
The float specialization is ignored. And with a valid
test<T>
:gives :
Both the float and int specialization are ignored.