zip
parent
22c44ca551
commit
97b6efb1ff
|
@ -1,6 +1,6 @@
|
||||||
cmake_minimum_required(VERSION 3.20)
|
cmake_minimum_required(VERSION 3.20)
|
||||||
include(cmake/color.cmake)
|
include(cmake/color.cmake)
|
||||||
set(BLT_VERSION 1.1.5)
|
set(BLT_VERSION 1.1.6)
|
||||||
|
|
||||||
set(BLT_TARGET BLT)
|
set(BLT_TARGET BLT)
|
||||||
|
|
||||||
|
|
|
@ -129,7 +129,7 @@ namespace blt::iterator
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace impls
|
namespace impl
|
||||||
{
|
{
|
||||||
template<typename Derived>
|
template<typename Derived>
|
||||||
class skip_t
|
class skip_t
|
||||||
|
@ -227,13 +227,13 @@ namespace blt::iterator
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename IterBase, typename... Base>
|
template<typename IterBase>
|
||||||
class iterator_container : public impls::take_t<iterator_container<IterBase, Base...>>,
|
class iterator_container : public impl::take_t<iterator_container<IterBase>>,
|
||||||
public impls::skip_t<iterator_container<IterBase, Base...>>,
|
public impl::skip_t<iterator_container<IterBase>>
|
||||||
public Base ...
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using iterator_category = typename IterBase::iterator_category;
|
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))
|
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<typename IterBase::iterator_category, std::bidirectional_iterator_tag> ||
|
static_assert((std::is_same_v<typename IterBase::iterator_category, std::bidirectional_iterator_tag> ||
|
||||||
std::is_same_v<typename IterBase::iterator_category, std::random_access_iterator_tag>),
|
std::is_same_v<typename IterBase::iterator_category, std::random_access_iterator_tag>),
|
||||||
".rev() must be used with bidirectional (or better) iterators!");
|
".rev() must be used with bidirectional (or better) iterators!");
|
||||||
return iterator_container < std::reverse_iterator<IterBase>, Base...>{std::reverse_iterator<IterBase>{end()}, std::reverse_iterator<IterBase>{begin()}};
|
return iterator_container<std::reverse_iterator<IterBase>>{std::reverse_iterator<IterBase>{end()},
|
||||||
|
std::reverse_iterator<IterBase>{begin()}};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto begin() const
|
auto begin() const
|
||||||
|
|
|
@ -97,6 +97,18 @@ namespace blt
|
||||||
return min;
|
return min;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// template<typename Iter>
|
||||||
|
// struct zip_wrapper<Iter> : public Iter
|
||||||
|
// {
|
||||||
|
// using iterator_category = typename std::iterator_traits<Iter>::iterator_category;
|
||||||
|
// using value_type = typename std::iterator_traits<Iter>::value_type;
|
||||||
|
// using difference_type = typename std::iterator_traits<Iter>::difference_type;
|
||||||
|
// using pointer = typename std::iterator_traits<Iter>::pointer;
|
||||||
|
// using reference = typename std::iterator_traits<Iter>::reference;
|
||||||
|
//
|
||||||
|
// using Iter::Iter;
|
||||||
|
// };
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Iter>
|
template<typename Iter>
|
||||||
|
@ -112,38 +124,42 @@ namespace blt
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename... Iter>
|
template<typename... Iter>
|
||||||
class zip_iterator_storage : public iterator::iterator_container<iterator::zip_wrapper<Iter...>>
|
class zip_iterator_container : public iterator::iterator_container<iterator::zip_wrapper<Iter...>>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using iterator::iterator_container<iterator::zip_wrapper<Iter...>>::iterator_container;
|
using iterator::iterator_container<iterator::zip_wrapper<Iter...>>::iterator_container;
|
||||||
|
|
||||||
explicit zip_iterator_storage(iterator_pair<Iter>... iterator_pairs):
|
explicit zip_iterator_container(iterator_pair<Iter>... iterator_pairs):
|
||||||
iterator::iterator_container<iterator::zip_wrapper<Iter...>>(iterator::zip_wrapper<Iter...>{std::move(iterator_pairs.begin)...},
|
iterator::iterator_container<iterator::zip_wrapper<Iter...>>(iterator::zip_wrapper<Iter...>{std::move(iterator_pairs.begin)...},
|
||||||
iterator::zip_wrapper<Iter...>{std::move(iterator_pairs.end)...})
|
iterator::zip_wrapper<Iter...>{std::move(iterator_pairs.end)...})
|
||||||
{}
|
{}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Derived>
|
namespace impl
|
||||||
class zip_t
|
|
||||||
{
|
{
|
||||||
public:
|
template<typename Derived>
|
||||||
template<typename... Iter>
|
class zip_t
|
||||||
auto zip(iterator_pair<Iter>... iterator_pairs)
|
{
|
||||||
{
|
public:
|
||||||
iterator::iterator_container<iterator::zip_wrapper<Iter...>>(iterator::zip_wrapper<Iter...>{std::move(iterator_pairs.begin)...},
|
template<typename... Iter>
|
||||||
iterator::zip_wrapper<Iter...>{std::move(iterator_pairs.end)...});
|
auto zip(iterator_pair<Iter>... iterator_pairs)
|
||||||
}
|
{
|
||||||
};
|
zip_iterator_container(iterator::zip_wrapper<Iter...>{std::move(iterator_pairs.begin)...},
|
||||||
|
iterator::zip_wrapper<Iter...>{std::move(iterator_pairs.end)...});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* CTAD for the zip containers
|
* CTAD for the zip containers
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template<typename... Iter>
|
template<typename... Iter>
|
||||||
zip_iterator_storage(iterator_pair<Iter>...) -> zip_iterator_storage<Iter...>;
|
zip_iterator_container(iterator_pair<Iter>...) -> zip_iterator_container<Iter...>;
|
||||||
|
|
||||||
template<typename... Iter>
|
template<typename... Iter>
|
||||||
zip_iterator_storage(std::initializer_list<Iter>...) -> zip_iterator_storage<Iter...>;
|
zip_iterator_container(std::initializer_list<Iter>...) -> zip_iterator_container<Iter...>;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -153,7 +169,7 @@ namespace blt
|
||||||
template<typename... Container>
|
template<typename... Container>
|
||||||
auto zip(Container& ... container)
|
auto zip(Container& ... container)
|
||||||
{
|
{
|
||||||
return zip_iterator_storage{iterator_pair{container.begin(), container.end()}...};
|
return zip_iterator_container{iterator_pair{container.begin(), container.end()}...};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue