diff --git a/include/jlcxx/stl.hpp b/include/jlcxx/stl.hpp index d2e3c8a..e6d6c46 100644 --- a/include/jlcxx/stl.hpp +++ b/include/jlcxx/stl.hpp @@ -131,40 +131,6 @@ void wrap_range_based_algorithms([[maybe_unused]] TypeWrapperT& wrapped) #endif } -template > typename ContainerT> -struct IteratorWrapper -{ - using value_type = valueT; - using iterator_type = typename ContainerT::iterator; - - iterator_type value; -}; - - -template -void validate_iterator(T it) -{ - using IteratorT = typename T::iterator_type; - if (it.value == IteratorT()) - { - throw std::runtime_error("Invalid iterator"); - } -} - -struct WrapIterator -{ - template - void operator()(TypeWrapperT&& wrapped) - { - using WrappedT = typename TypeWrapperT::type; - using ValueT = typename WrappedT::value_type; - - wrapped.method("iterator_next", [](WrappedT it) -> WrappedT { ++(it.value); return it; }); - wrapped.method("iterator_value", [](WrappedT it) -> ValueT { validate_iterator(it); return *it.value; }); - wrapped.method("iterator_is_equal", [](WrappedT it1, WrappedT it2) -> bool {return it1.value == it2.value; }); - }; -}; - template struct WrapVectorImpl { @@ -245,6 +211,40 @@ struct WrapValArray } }; + +template > typename ContainerT> +struct IteratorWrapper +{ + using value_type = valueT; + using iterator_type = typename ContainerT::iterator; + + iterator_type value; +}; + +template +void validate_iterator(T it) +{ + using IteratorT = typename T::iterator_type; + if (it.value == IteratorT()) + { + throw std::runtime_error("Invalid iterator"); + } +} + +struct WrapIterator +{ + template + void operator()(TypeWrapperT&& wrapped) + { + using WrappedT = typename TypeWrapperT::type; + using ValueT = typename WrappedT::value_type; + + wrapped.method("iterator_next", [](WrappedT it) -> WrappedT { ++(it.value); return it; }); + wrapped.method("iterator_value", [](WrappedT it) -> ValueT { validate_iterator(it); return *it.value; }); + wrapped.method("iterator_is_equal", [](WrappedT it1, WrappedT it2) -> bool {return it1.value == it2.value; }); + }; +}; + template struct DequeIteratorWrapper : IteratorWrapper {}; diff --git a/src/stl.cpp b/src/stl.cpp index 13471b8..f2b02d3 100644 --- a/src/stl.cpp +++ b/src/stl.cpp @@ -126,7 +126,7 @@ JLCXX_MODULE define_cxxwrap_stl_module(jlcxx::Module& stl) .method("swap", &std::thread::swap); stl.method("hardware_concurrency", [] () { return std::thread::hardware_concurrency(); }); - + jlcxx::add_smart_pointer(stl, "SharedPtr"); jlcxx::add_smart_pointer(stl, "WeakPtr"); jlcxx::add_smart_pointer(stl, "UniquePtr");