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: unordered set types #159

Merged
merged 2 commits into from
Jun 10, 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
7 changes: 7 additions & 0 deletions .github/workflows/test-linux-mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ jobs:
- macos-13
arch:
- x64
include:
- os: macos-14
arch: aarch64
version: "1.10"
- os: macos-14
arch: aarch64
version: "nightly"
steps:
- uses: actions/checkout@v3
with:
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ set(JLCXX_STL_SOURCES
${JLCXX_SOURCE_DIR}/stl_queue.cpp
${JLCXX_SOURCE_DIR}/stl_set.cpp
${JLCXX_SOURCE_DIR}/stl_multiset.cpp
${JLCXX_SOURCE_DIR}/stl_unordered_set.cpp
${JLCXX_SOURCE_DIR}/stl_unordered_multiset.cpp
${JLCXX_SOURCE_DIR}/stl_shared_ptr.cpp
${JLCXX_SOURCE_DIR}/stl_unique_ptr.cpp
${JLCXX_SOURCE_DIR}/stl_weak_ptr.cpp
Expand Down
24 changes: 20 additions & 4 deletions include/jlcxx/stl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <deque>
#include <queue>
#include <set>
#include <unordered_set>

#include "module.hpp"
#include "smart_pointers.hpp"
Expand Down Expand Up @@ -53,6 +54,8 @@ class JLCXX_API StlWrappers
TypeWrapper1 queue;
TypeWrapper1 set;
TypeWrapper1 multiset;
TypeWrapper1 unordered_set;
TypeWrapper1 unordered_multiset;

static void instantiate(Module& mod);
static StlWrappers& instance();
Expand All @@ -70,6 +73,8 @@ void apply_deque(TypeWrapper1& deque);
void apply_queue(TypeWrapper1& queue);
void apply_set(TypeWrapper1& set);
void apply_multiset(TypeWrapper1& multiset);
void apply_unordered_set(TypeWrapper1& unordered_set);
void apply_unordered_multiset(TypeWrapper1& unordered_multiset);
void apply_shared_ptr();
void apply_weak_ptr();
void apply_unique_ptr();
Expand Down Expand Up @@ -249,7 +254,7 @@ struct WrapQueue
}
};

struct WrapSet
struct WrapSetType
{
template<typename TypeWrapperT>
void operator()(TypeWrapperT&& wrapped)
Expand All @@ -269,7 +274,7 @@ struct WrapSet
}
};

struct WrapMultiset
struct WrapMultisetType
{
template<typename TypeWrapperT>
void operator()(TypeWrapperT&& wrapped)
Expand Down Expand Up @@ -321,6 +326,12 @@ template <typename T>
struct container_has_less_than_operator<T, std::enable_if_t<!is_container<T>::value>>
: has_less_than_operator<T> {};

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

template <typename T>
struct is_hashable<T, std::void_t<decltype(std::hash<T>{}(std::declval<T>()))>> : std::true_type {};

template<typename T>
inline void apply_stl(jlcxx::Module& mod)
{
Expand All @@ -330,8 +341,13 @@ inline void apply_stl(jlcxx::Module& mod)
TypeWrapper1(mod, StlWrappers::instance().queue).apply<std::queue<T>>(WrapQueue());
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());
TypeWrapper1(mod, StlWrappers::instance().set).apply<std::set<T>>(WrapSetType());
TypeWrapper1(mod, StlWrappers::instance().multiset).apply<std::multiset<T>>(WrapMultisetType());
}
if constexpr (is_hashable<T>::value)
{
TypeWrapper1(mod, StlWrappers::instance().unordered_set).apply<std::unordered_set<T>>(WrapSetType());
TypeWrapper1(mod, StlWrappers::instance().unordered_multiset).apply<std::unordered_multiset<T>>(WrapMultisetType());
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/stl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ JLCXX_API void StlWrappers::instantiate(Module& mod)
apply_queue(m_instance->queue);
apply_set(m_instance->set);
apply_multiset(m_instance->multiset);
apply_unordered_set(m_instance->unordered_set);
apply_unordered_multiset(m_instance->unordered_multiset);
apply_shared_ptr();
apply_weak_ptr();
apply_unique_ptr();
Expand All @@ -49,7 +51,9 @@ JLCXX_API StlWrappers::StlWrappers(Module& stl) :
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")),
multiset(stl.add_type<Parametric<TypeVar<1>>>("StdMultiset"))
multiset(stl.add_type<Parametric<TypeVar<1>>>("StdMultiset")),
unordered_set(stl.add_type<Parametric<TypeVar<1>>>("StdUnorderedSet")),
unordered_multiset(stl.add_type<Parametric<TypeVar<1>>>("StdUnorderedMultiset"))
{
}

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::WrapMultiset());
multiset.apply_combination<std::multiset, stltypes>(stl::WrapMultisetType());
}

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

void apply_set(TypeWrapper1& set)
{
set.apply_combination<std::set, stltypes>(stl::WrapSet());
set.apply_combination<std::set, stltypes>(stl::WrapSetType());
}

}
Expand Down
16 changes: 16 additions & 0 deletions src/stl_unordered_multiset.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "jlcxx/stl.hpp"

namespace jlcxx
{

namespace stl
{

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

}

}
16 changes: 16 additions & 0 deletions src/stl_unordered_set.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "jlcxx/stl.hpp"

namespace jlcxx
{

namespace stl
{

void apply_unordered_set(TypeWrapper1& unordered_set)
{
unordered_set.apply_combination<std::unordered_set, stltypes>(stl::WrapSetType());
}

}

}
Loading