Skip to content
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

Support std::map as AbstractDict? #88

Open
eschnett opened this issue Jul 8, 2021 · 5 comments
Open

Support std::map as AbstractDict? #88

eschnett opened this issue Jul 8, 2021 · 5 comments

Comments

@eschnett
Copy link

eschnett commented Jul 8, 2021

How difficult would it be to add support for std::map as an AbstractDict in Julia?

I've browsed the source code, and it seems that implementing this along the lines in which std::vector is handled seems straightforward. The only complication I'm seeing is that std::map takes two template arguments, not just one.

As far as I can tell, implementing this would touch three files: stl.hpp and stl.cpp in libcxxwrap-julia, as well as the file StdLib.jl in CxxWrap.

Would this be feasible? Am I missing something?

@eschnett
Copy link
Author

eschnett commented Jul 9, 2021

It looks as if this was a bit more complicated. You need also a new C++ class DictRef<K,T>, which wraps a Julia dictionary, so that they can be accessed for C++ with an API similar to std::map<K,T>. See the file array.hpp that implements ArrayRef<T> for Julia's Vector type.

@sloede
Copy link
Contributor

sloede commented Jan 29, 2024

Given that this has been dormant for such a long time, I guess I shouldn't be too hopeful that there has been any progress yet? @eschnett did you ever succeed in creating a wrapper (perhaps only locally)?

@barche I tried to come up with a PR to libcxxwrap-julia by following the suggestions in JuliaInterop/CxxWrap.jl#190 (comment). However, I got stuck very early since all existing STL types only support one template argument, which prevents me from using the smart-copy-and-extend-existing-code approach. It's probably too much to ask, but is there any chance you might be willing to step in here?

@eschnett
Copy link
Author

@sloede Unfortunately I did not.

@eschnett
Copy link
Author

@sloede How many different std::map key types do you need? In my experience the key is usually either int or std::string, and thus implementing two versions that have one template parameter might work.

@sloede
Copy link
Contributor

sloede commented Jan 29, 2024

In my experience the key is usually either int or std::string, and thus implementing two versions that have one template parameter might work.

That is very true. OTOH, I feel like it wouldn't do a very good service to most users if we only had a "half-solution" here, which works only for a very limited subset of cases.

I saw what you did with std::pair here, so I think I might mimic this in my code where I need std::map. Has this worked for you so far for pairs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants