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

feat: StdMultiset #155

Merged
merged 1 commit into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions include/jlcxx/stl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class JLCXX_API StlWrappers
TypeWrapper1 deque;
TypeWrapper1 queue;
TypeWrapper1 set;
TypeWrapper1 multiset;

static void instantiate(Module& mod);
static StlWrappers& instance();
Expand Down Expand Up @@ -257,6 +258,27 @@ struct WrapSet
}
};

struct WrapMultiset
{
template<typename TypeWrapperT>
void operator()(TypeWrapperT&& wrapped)
{
using WrappedT = typename TypeWrapperT::type;
using T = typename WrappedT::value_type;

wrapped.template constructor<>();
wrapped.module().set_override_module(StlWrappers::instance().module());
wrapped.method("cppsize", &WrappedT::size);
wrapped.method("multiset_insert!", [] (WrappedT& v, const T& val) { v.insert(val); });
wrapped.method("multiset_empty!", [] (WrappedT& v) { v.clear(); });
wrapped.method("multiset_isempty", [] (WrappedT& v) { return v.empty(); });
wrapped.method("multiset_delete!", [] (WrappedT&v, const T& val) { v.erase(val); });
wrapped.method("multiset_in", [] (WrappedT& v, const T& val) { return v.count(val) != 0; });
wrapped.method("multiset_count", [] (WrappedT& v, const T& val) { return v.count(val); });
wrapped.module().unset_override_module();
}
};

template <typename T, typename = void>
struct has_less_than_operator : std::false_type {};

Expand Down Expand Up @@ -298,6 +320,7 @@ inline void apply_stl(jlcxx::Module& mod)
if constexpr (container_has_less_than_operator<T>::value)
{
TypeWrapper1(mod, StlWrappers::instance().set).apply<std::set<T>>(WrapSet());
TypeWrapper1(mod, StlWrappers::instance().multiset).apply<std::multiset<T>>(WrapMultiset());
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/stl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ JLCXX_API void StlWrappers::instantiate(Module& mod)
m_instance->deque.apply_combination<std::deque, stltypes>(stl::WrapDeque());
m_instance->queue.apply_combination<std::queue, stltypes>(stl::WrapQueue());
m_instance->set.apply_combination<std::set, stltypes>(stl::WrapSet());
m_instance->multiset.apply_combination<std::multiset, stltypes>(stl::WrapMultiset());
smartptr::apply_smart_combination<std::shared_ptr, stltypes>();
smartptr::apply_smart_combination<std::weak_ptr, stltypes>();
smartptr::apply_smart_combination<std::unique_ptr, stltypes>();
Expand All @@ -47,7 +48,8 @@ JLCXX_API StlWrappers::StlWrappers(Module& stl) :
valarray(stl.add_type<Parametric<TypeVar<1>>>("StdValArray", julia_type("AbstractVector"))),
deque(stl.add_type<Parametric<TypeVar<1>>>("StdDeque", julia_type("AbstractVector"))),
queue(stl.add_type<Parametric<TypeVar<1>>>("StdQueue", julia_type("AbstractVector"))),
set(stl.add_type<Parametric<TypeVar<1>>>("StdSet"))
set(stl.add_type<Parametric<TypeVar<1>>>("StdSet")),
multiset(stl.add_type<Parametric<TypeVar<1>>>("StdMultiset"))
{
}

Expand Down
Loading