Skip to content

Commit

Permalink
refactor: split up multiset and unordered multiset
Browse files Browse the repository at this point in the history
  • Loading branch information
PraneethJain committed Jul 20, 2024
1 parent e08c497 commit 1521e05
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
27 changes: 24 additions & 3 deletions include/jlcxx/stl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,28 @@ struct WrapUnorderedSet
}
};

struct WrapMultisetType
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();
}
};

struct WrapUnorderedMultiset
{
template<typename TypeWrapperT>
void operator()(TypeWrapperT&& wrapped)
Expand Down Expand Up @@ -562,14 +583,14 @@ inline void apply_stl(jlcxx::Module& mod)
{
TypeWrapper1(mod, StlWrappers::instance().set_iterator).apply<stl::SetIteratorWrapper<T>>(WrapIterator());
TypeWrapper1(mod, StlWrappers::instance().set).apply<std::set<T>>(WrapSet());
TypeWrapper1(mod, StlWrappers::instance().multiset).apply<std::multiset<T>>(WrapMultisetType());
TypeWrapper1(mod, StlWrappers::instance().multiset).apply<std::multiset<T>>(WrapMultiset());
TypeWrapper1(mod, StlWrappers::instance().priority_queue).apply<std::priority_queue<T>>(WrapPriorityQueue());
}
if constexpr (is_hashable<T>::value)
{
TypeWrapper1(mod, StlWrappers::instance().unordered_set_iterator).apply<stl::UnorderedSetIteratorWrapper<T>>(WrapIterator());
TypeWrapper1(mod, StlWrappers::instance().unordered_set).apply<std::unordered_set<T>>(WrapUnorderedSet());
TypeWrapper1(mod, StlWrappers::instance().unordered_multiset).apply<std::unordered_multiset<T>>(WrapMultisetType());
TypeWrapper1(mod, StlWrappers::instance().unordered_multiset).apply<std::unordered_multiset<T>>(WrapUnorderedMultiset());
}
TypeWrapper1(mod, StlWrappers::instance().list_iterator).apply<stl::ListIteratorWrapper<T>>(WrapIterator());
TypeWrapper1(mod, StlWrappers::instance().list).apply<std::list<T>>(WrapList());
Expand Down
2 changes: 1 addition & 1 deletion src/stl_multiset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace stl

void apply_multiset(TypeWrapper1& multiset)
{
multiset.apply_combination<std::multiset, stltypes>(stl::WrapMultisetType());
multiset.apply_combination<std::multiset, stltypes>(stl::WrapMultiset());
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/stl_unordered_multiset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace stl

void apply_unordered_multiset(TypeWrapper1& unordered_multiset)
{
unordered_multiset.apply_combination<std::unordered_multiset, stltypes>(stl::WrapMultisetType());
unordered_multiset.apply_combination<std::unordered_multiset, stltypes>(stl::WrapUnorderedMultiset());
}

}
Expand Down

0 comments on commit 1521e05

Please sign in to comment.