libcxxwrap-julia
libcxxwrap-julia copied to clipboard
Support std::map as AbstractDict?
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?
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.
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 https://github.com/JuliaInterop/CxxWrap.jl/issues/190#issuecomment-579455100. 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?
@sloede Unfortunately I did not.
@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.
In my experience the key is usually either
intorstd::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?