nbind icon indicating copy to clipboard operation
nbind copied to clipboard

Support std::map, std::set and their unordered versions

Open jjrv opened this issue 9 years ago • 2 comments

Node and all recent browsers seem to support Map and Set so std::map and std::set should be converted automatically. Probably std::map<Key, Value> should become a plain JavaScript object for any integer or string Key and otherwise a Map object.

Probably std::set<Key> should always become a JavaScript Set for performance (see anvaka/set-vs-object) but accept plain objects as input if Key is integer or string. Any truthy value in the JavaScript object would mean its key is a set member.

jjrv avatar Nov 12 '16 14:11 jjrv

Supporting these data structures would be awesome, especially when porting already-existing libraries, where changing data types might not be easy.

Somewhat related: when I tried returning std::unordered_set and std::unordered_map instances, everything compiled fine, but segfault'd later. Is it to be expected? Shouldn't it be a compile-time issue?

arcanis avatar Dec 04 '16 13:12 arcanis

Not sure if invalid types can be a compile-time error (they would have to bomb during linking), but on Emscripten target they throw immediately when the code is loaded. Node.js target should be changed to do the same, instead of crashing hard.

I'll try to get the map and set done soon, it's not much work but there's a couple other urgent projects.

jjrv avatar Dec 04 '16 13:12 jjrv