Skip to content

Commit

Permalink
feat: StdMultiset (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
PraneethJain authored May 31, 2024
1 parent 799b326 commit 72851eb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
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

0 comments on commit 72851eb

Please sign in to comment.