bytedeco / javacpp

The missing bridge between Java and native C++
Other
4.46k stars 581 forks source link

Add Info.defaultInsertable #664

Closed HGuillemet closed 8 months ago

HGuillemet commented 1 year ago

Add a new Info to hint that a class cannot be default-constructed in containers.

WIthout this PR, some containers cannot be mapped to Java because the Parser will generate a resize method that is not supported.

Seen in pytorch for things like std::vector<torch::OrderedDict<std::string,std::shared_ptr<torch::nn::Module>>::Item> or std::vector<torch::nn::AnyValue>.

saudet commented 1 year ago

I'm pretty sure that's already covered by prefixing the cppNames with "const" like those here: https://github.com/bytedeco/javacpp-presets/blob/master/pytorch/src/main/java/org/bytedeco/pytorch/presets/torch.java#L2118

HGuillemet commented 1 year ago

Ah, I missed that. Adding const does more than just skipping resize: it also skips put and erase, and replaces get by at, but it should do the trick for the current need in Pytorch. You can put this PR on hold.