From 97b6efb1ff68419f235608cce15df013261049c7 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Mon, 30 Sep 2024 19:43:02 -0400 Subject: [PATCH] zip --- CMakeLists.txt | 2 +- include/blt/iterator/common.h | 13 +++++----- include/blt/iterator/zip.h | 46 +++++++++++++++++++++++------------ 3 files changed, 39 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0bf31e4..58db704 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.20) include(cmake/color.cmake) -set(BLT_VERSION 1.1.5) +set(BLT_VERSION 1.1.6) set(BLT_TARGET BLT) diff --git a/include/blt/iterator/common.h b/include/blt/iterator/common.h index 1474017..3918d09 100644 --- a/include/blt/iterator/common.h +++ b/include/blt/iterator/common.h @@ -129,7 +129,7 @@ namespace blt::iterator } }; - namespace impls + namespace impl { template class skip_t @@ -227,13 +227,13 @@ namespace blt::iterator }; } - template - class iterator_container : public impls::take_t>, - public impls::skip_t>, - public Base ... + template + class iterator_container : public impl::take_t>, + public impl::skip_t> { public: using iterator_category = typename IterBase::iterator_category; + using iterator = IterBase; iterator_container(IterBase begin, IterBase end): m_begin(std::move(begin)), m_end(std::move(end)) {} @@ -247,7 +247,8 @@ namespace blt::iterator static_assert((std::is_same_v || std::is_same_v), ".rev() must be used with bidirectional (or better) iterators!"); - return iterator_container < std::reverse_iterator, Base...>{std::reverse_iterator{end()}, std::reverse_iterator{begin()}}; + return iterator_container>{std::reverse_iterator{end()}, + std::reverse_iterator{begin()}}; } auto begin() const diff --git a/include/blt/iterator/zip.h b/include/blt/iterator/zip.h index bb05bda..e763f0c 100644 --- a/include/blt/iterator/zip.h +++ b/include/blt/iterator/zip.h @@ -97,6 +97,18 @@ namespace blt return min; } }; + +// template +// struct zip_wrapper : public Iter +// { +// using iterator_category = typename std::iterator_traits::iterator_category; +// using value_type = typename std::iterator_traits::value_type; +// using difference_type = typename std::iterator_traits::difference_type; +// using pointer = typename std::iterator_traits::pointer; +// using reference = typename std::iterator_traits::reference; +// +// using Iter::Iter; +// }; } template @@ -112,38 +124,42 @@ namespace blt }; template - class zip_iterator_storage : public iterator::iterator_container> + class zip_iterator_container : public iterator::iterator_container> { public: using iterator::iterator_container>::iterator_container; - explicit zip_iterator_storage(iterator_pair... iterator_pairs): + explicit zip_iterator_container(iterator_pair... iterator_pairs): iterator::iterator_container>(iterator::zip_wrapper{std::move(iterator_pairs.begin)...}, iterator::zip_wrapper{std::move(iterator_pairs.end)...}) {} + }; - template - class zip_t + namespace impl { - public: - template - auto zip(iterator_pair... iterator_pairs) - { - iterator::iterator_container>(iterator::zip_wrapper{std::move(iterator_pairs.begin)...}, - iterator::zip_wrapper{std::move(iterator_pairs.end)...}); - } - }; + template + class zip_t + { + public: + template + auto zip(iterator_pair... iterator_pairs) + { + zip_iterator_container(iterator::zip_wrapper{std::move(iterator_pairs.begin)...}, + iterator::zip_wrapper{std::move(iterator_pairs.end)...}); + } + }; + } /* * CTAD for the zip containers */ template - zip_iterator_storage(iterator_pair...) -> zip_iterator_storage; + zip_iterator_container(iterator_pair...) -> zip_iterator_container; template - zip_iterator_storage(std::initializer_list...) -> zip_iterator_storage; + zip_iterator_container(std::initializer_list...) -> zip_iterator_container; /* @@ -153,7 +169,7 @@ namespace blt template auto zip(Container& ... container) { - return zip_iterator_storage{iterator_pair{container.begin(), container.end()}...}; + return zip_iterator_container{iterator_pair{container.begin(), container.end()}...}; } }