work on enumerate

v1
Brett 2024-10-01 13:27:39 -04:00
parent 97b6efb1ff
commit 68451b0433
5 changed files with 64 additions and 4 deletions

View File

@ -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.6) set(BLT_VERSION 1.1.7)
set(BLT_TARGET BLT) set(BLT_TARGET BLT)

View File

@ -115,7 +115,7 @@ namespace blt::iterator
} }
protected: protected:
mutable Iter iter; Iter iter;
}; };
template<typename Iter, typename Derived> template<typename Iter, typename Derived>

View File

@ -0,0 +1,59 @@
#pragma once
/*
* Copyright (C) 2024 Brett Terpstra
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef BLT_ITERATOR_ENUMERATE_H
#define BLT_ITERATOR_ENUMERATE_H
#include <blt/iterator/common.h>
#include <blt/meta/meta.h>
#include <tuple>
namespace blt
{
namespace iterator
{
/**
* struct which is returned by the enumerator.
* @tparam T type to store.
*/
template<typename T>
struct enumerate_item
{
blt::size_t index;
T value;
};
template<typename Iter>
class enumerate_wrapper : public passthrough_wrapper<Iter, enumerate_wrapper<Iter>>
{
public:
using passthrough_wrapper<Iter, enumerate_wrapper<Iter>>::passthrough_wrapper;
enumerate_item<meta::deref_return_t<Iter>> operator*() const
{
return *this->iter;
}
private:
blt::size_t index;
};
}
}
#endif //BLT_ITERATOR_ENUMERATE_H

View File

@ -145,8 +145,8 @@ namespace blt
template<typename... Iter> template<typename... Iter>
auto zip(iterator_pair<Iter>... iterator_pairs) auto zip(iterator_pair<Iter>... iterator_pairs)
{ {
zip_iterator_container(iterator::zip_wrapper<Iter...>{std::move(iterator_pairs.begin)...}, auto* d = static_cast<Derived*>(this);
iterator::zip_wrapper<Iter...>{std::move(iterator_pairs.end)...}); return zip_iterator_container(iterator_pair<decltype(d->begin())>{d->begin(), d->end()}, iterator_pairs...);
} }
}; };
} }

View File

@ -21,6 +21,7 @@
#include <blt/math/vectors.h> #include <blt/math/vectors.h>
#include <blt/math/log_util.h> #include <blt/math/log_util.h>
#include <blt/iterator/zip.h> #include <blt/iterator/zip.h>
#include <blt/iterator/enumerate.h>
#include <blt/iterator/iterator.h> #include <blt/iterator/iterator.h>
#include <blt/format/boxing.h> #include <blt/format/boxing.h>
#include <array> #include <array>