Compare commits

..

No commits in common. "main" and "v1" have entirely different histories.
main ... v1

9 changed files with 158 additions and 171 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.20)
include(cmake/color.cmake)
set(BLT_VERSION 2.0.4)
set(BLT_VERSION 1.1.8)
set(BLT_TARGET BLT)

View File

@ -199,8 +199,6 @@ def make_release(env: EnvData, name):
'X-GitHub-Api-Version': '2022-11-28'
}
for url in urls:
if not "github" in url:
continue
response = requests.post(url, headers=headers, data=json.dumps(data))
if response.status_code == 201:
print('Release created successfully!')

View File

@ -25,8 +25,6 @@
#include <blt/iterator/fwddecl.h>
#include <blt/meta/meta.h>
#include <blt/meta/iterator.h>
#include <functional>
#include <optional>
namespace blt::iterator
{
@ -112,7 +110,7 @@ namespace blt::iterator
}
protected:
mutable Iter iter;
Iter iter;
};
template<typename Iter, typename Derived>
@ -124,92 +122,28 @@ namespace blt::iterator
{
return *this->iter;
}
};
template<typename Iter, typename Derived>
class deref_only_wrapper : public passthrough_wrapper<Iter, Derived, false>
{
public:
using passthrough_wrapper<Iter, Derived, false>::passthrough_wrapper;
deref_only_wrapper& operator++()
{
++this->iter;
return *this;
}
deref_only_wrapper& operator--()
{
--this->iter;
return *this;
}
deref_only_wrapper& operator+(blt::ptrdiff_t n)
{
static_assert(meta::is_random_access_iterator_v<Iter>, "Iterator must allow random access");
this->iter = this->iter + n;
return *this;
}
deref_only_wrapper& operator-(blt::ptrdiff_t n)
{
static_assert(meta::is_random_access_iterator_v<Iter>, "Iterator must allow random access");
this->iter = this->iter - n;
return *this;
}
};
template<typename Iter, typename Func>
class map_wrapper : public deref_only_wrapper<Iter, map_wrapper<Iter, Func>>
{
public:
using iterator_category = typename std::iterator_traits<Iter>::iterator_category;
using value_type = std::invoke_result_t<Func, meta::deref_return_t<Iter>>;
using difference_type = blt::ptrdiff_t;
using pointer = value_type;
using reference = value_type;
map_wrapper(Iter iter, Func func):
deref_only_wrapper<Iter, map_wrapper<Iter, Func>>(std::move(iter)), func(std::move(func))
{}
reference operator*() const
{
return func(*this->iter);
}
private:
Func func;
};
template<typename Iter, typename Pred>
class filter_wrapper : public deref_only_wrapper<Iter, filter_wrapper<Iter, Pred>>
{
public:
using iterator_category = typename std::iterator_traits<Iter>::iterator_category;
using value_type = std::conditional_t<
std::is_reference_v<meta::deref_return_t<Iter>>,
std::optional<std::reference_wrapper<std::remove_reference_t<meta::deref_return_t<Iter>>>>,
std::optional<meta::deref_return_t<Iter>>>;
using difference_type = blt::ptrdiff_t;
using pointer = value_type;
using reference = value_type;
filter_wrapper(Iter iter, Pred func):
deref_only_wrapper<Iter, filter_wrapper<Iter, Pred>>(std::move(iter)), func(std::move(func))
{}
reference operator*() const
{
if (!func(*this->iter))
{
return {};
}
return *this->iter;
}
private:
Pred func;
// zip_wrapper& operator++()
// {
// return *this;
// }
//
// zip_wrapper& operator--()
// {
// return *this;
// }
//
// friend zip_wrapper operator+(const zip_wrapper& a, blt::ptrdiff_t n)
// {
// static_assert(std::is_same_v<iterator_category, std::random_access_iterator_tag>,
// "Iterator must allow random access");
// }
//
// friend zip_wrapper operator-(const zip_wrapper& a, blt::ptrdiff_t n)
// {
// static_assert(std::is_same_v<iterator_category, std::random_access_iterator_tag>,
// "Iterator must allow random access");
// }
};
namespace impl
@ -357,22 +291,6 @@ namespace blt::iterator
return enumerate_iterator_container{begin(), end(), static_cast<blt::size_t>(std::distance(begin(), end()))};
}
template<typename Func>
auto map(Func func) const
{
return iterator_container<blt::iterator::map_wrapper<IterBase, Func>>{
blt::iterator::map_wrapper<IterBase, Func>{m_begin, func},
blt::iterator::map_wrapper<IterBase, Func>{m_end, func}};
}
template<typename Pred>
auto filter(Pred pred) const
{
return iterator_container<blt::iterator::filter_wrapper<IterBase, Pred>>{
blt::iterator::filter_wrapper<IterBase, Pred>{m_begin, pred},
blt::iterator::filter_wrapper<IterBase, Pred>{m_end, pred}};
}
auto begin() const
{
return m_begin;

View File

@ -108,6 +108,20 @@ namespace blt
template<typename Iter>
enumerate_iterator_container(Iter, Iter, blt::size_t) -> enumerate_iterator_container<Iter>;
namespace iterator::impl
{
template<typename Derived>
class enumerate_t
{
public:
auto enumerate()
{
auto* d = static_cast<Derived*>(this);
return enumerate_iterator_container{d->begin(), d->end(), static_cast<blt::size_t>(std::distance(d->begin(), d->end()))};
}
};
}
template<typename T>
static inline auto enumerate(T& container)
{

View File

@ -41,12 +41,6 @@ namespace blt
template<typename... Iter>
struct zip_wrapper;
template<typename Iter, typename Func>
class map_wrapper;
template<typename Iter, typename Pred>
class filter_wrapper;
namespace impl
{
template<typename Derived>
@ -54,6 +48,12 @@ namespace blt
template<typename Derived>
class take_t;
template<typename Derived>
class zip_t;
template<typename Derived>
class enumerate_t;
}
}
}

View File

@ -121,6 +121,21 @@ namespace blt
};
namespace iterator::impl
{
template<typename Derived>
class zip_t
{
public:
template<typename... Iter>
auto zip(iterator::iterator_pair<Iter>... iterator_pairs)
{
auto* d = static_cast<Derived*>(this);
return zip_iterator_container(iterator::iterator_pair<decltype(d->begin())>{d->begin(), d->end()}, iterator_pairs...);
}
};
}
/*
* CTAD for the zip containers
*/

View File

@ -95,10 +95,104 @@ namespace blt::meta
template<class T>
inline constexpr bool is_streamable_v = is_streamable<T>::value;
namespace detail
{
template<typename Or>
struct value_type_helper
{
template<typename Subs>
inline static constexpr auto get(int) -> typename Subs::value_type
{
return std::declval<Subs::value_type>();
}
template<typename>
inline static constexpr Or get(...)
{
return std::declval<Or>();
}
};
template<typename Or>
struct reference_type_helper
{
template<typename Subs>
inline static constexpr auto get(int) -> typename Subs::reference
{
return std::declval<typename Subs::reference>();
}
template<typename>
inline static constexpr Or get(...)
{
return std::declval<Or>();
}
};
template<typename Or>
struct const_reference_type_helper
{
template<typename Subs>
inline static constexpr auto get(int) -> typename Subs::const_reference
{
return std::declval<typename Subs::const_reference>();
}
template<typename>
inline static constexpr Or get(...)
{
return std::declval<Or>();
}
};
template<typename Or>
struct pointer_type_helper
{
template<typename Subs>
inline static constexpr auto get(int) -> typename Subs::pointer
{
return std::declval<typename Subs::pointer>();
}
template<typename>
inline static constexpr Or get(...)
{
return std::declval<Or>();
}
};
template<typename Or>
struct difference_type_helper
{
template<typename Subs>
inline static constexpr auto get(int) -> typename Subs::difference_type
{
return std::declval<typename Subs::difference_type>();
}
template<typename>
inline static constexpr Or get(...)
{
return std::declval<Or>();
}
};
}
template<typename T, typename Or>
using value_type_t = decltype(detail::value_type_helper<Or>::template get<T>(0));
template<typename T, typename Or>
using difference_t = decltype(detail::difference_type_helper<Or>::template get<T>(0));
template<typename T, typename Or>
using pointer_t = decltype(detail::pointer_type_helper<Or>::template get<T>(0));
template<typename T, typename Or>
using reference_t = decltype(detail::reference_type_helper<Or>::template get<T>(0));
template<typename T, typename Or>
using const_reference_t = decltype(detail::const_reference_type_helper<Or>::template get<T>(0));
template<typename T>
struct arrow_return
{
using type = typename std::invoke_result_t<decltype(&T::operator->), T*>;
using type = typename std::result_of<decltype(&T::operator->)(T*)>::type;
};
template<typename T>
@ -114,7 +208,7 @@ namespace blt::meta
template<typename T>
struct deref_return
{
using type = typename std::invoke_result_t<decltype(&T::operator*), T&>;
using type = typename std::result_of<decltype(&T::operator*)(T*)>::type;
};
template<typename T>

@ -1 +1 @@
Subproject commit 93201da2ba5a6aba0a6e57ada64973555629b3e3
Subproject commit 7ef2e733416953b222851f9a360d7fc72d068ee5

View File

@ -191,63 +191,11 @@ void test_iterate()
BLT_TRACE_STREAM << "Zip: " << a << " " << b << "\n";
}
BLT_TRACE("================================");
for (auto [i, data] : blt::iterate(array_1).map([](const blt::vec2& in) { return in.normalize(); }).zip(list_1).skip(3).take(4).enumerate())
for (auto [i, data] : blt::iterate(array_1).zip(list_1).skip(3).take(4).enumerate())
{
auto [a, b] = data;
BLT_TRACE_STREAM << "Map + Zip + Skip + Take + Enumerate (Index: " << i << ")> " << a << " " << b << "\n";
BLT_TRACE_STREAM << "Zip (" << i << "): " << a << " " << b << "\n";
}
BLT_TRACE("================================");
for (auto [i, data] : blt::iterate(array_1).map(
[](const blt::vec2& in) {
return in.normalize();
}).zip(list_1).skip(3).take(4).enumerate())
{
auto [a, b] = data;
BLT_TRACE_STREAM << "Map + Zip + Skip + Take + Enumerate (Index: " << i << ")> " << a << " " << b << "\n";
}
BLT_TRACE("================================");
for (auto a : blt::iterate(array_1).map([](const blt::vec2& in) { return in.normalize(); })
.filter([](const blt::vec2& f) { return f.x() > 0.5; }))
{
if (!a)
continue;
auto v = *a;
BLT_TRACE_STREAM << " So this one works? " << v << "\n";
}
BLT_TRACE("================================");
for (auto a : blt::iterate(array_1).map([](const blt::vec2& in) { return in.normalize(); })
.enumerate().filter([](const auto& f) { return f.value.x() > 0.5; }))
{
if (!a)
continue;
auto [index, v] = *a;
BLT_TRACE_STREAM << " So this one works? (" << index << ")" << v << "\n";
}
BLT_TRACE("================================");
// for (auto a : blt::iterate(array_1).filter([](const auto& f) { return f.x() > 3 && f.y() < 6; }).take(2))
// {
// if (!a)
// continue;
// auto v = *a;
// BLT_TRACE_STREAM << " How about this one?? " << v.get() << "\n";
// }
for (auto a : blt::iterate(array_1).map([](const auto& f) { return f.x() > 3 && f.y() < 6; }))
{
BLT_TRACE_STREAM << " How about this one?? " << a << "\n";
}
// for (auto [value, a] : blt::iterate(array_1).map(
// [](const blt::vec2& in) {
// return in.normalize();
// }).enumerate().filter([](const auto& v) {
// return v.index % 2 == 0;
// }).zip(array_2).skip(3))
// {
// if (!value)
// continue;
// auto [i, v] = *value;
// BLT_TRACE_STREAM << "Enumerate Filter (Index: " << i << ")> " << v << "\n";
// }
}
int main()