Skip to content

Commit

Permalink
review updates
Browse files Browse the repository at this point in the history
* simplify handling of parameter pack expansion results
* add missing includes
* make consistency check more explicit

Co-authored-by: Thomas Grützmacher <thomas.gruetzmacher@kit.edu>
  • Loading branch information
upsj and Thomas Grützmacher committed Feb 14, 2022
1 parent a21535e commit 73e9433
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
27 changes: 12 additions & 15 deletions core/base/iterator_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <cassert>
#include <cstddef>
#include <initializer_list>
#include <iterator>
#include <tuple>
#include <utility>
Expand All @@ -45,12 +46,6 @@ namespace gko {
namespace detail {


/** Helper function to pass pack expansions to, whose values we don't need. */
template <typename... Args>
void tuple_unpack_sink(Args&&...)
{}


template <typename... Iterators>
class zip_iterator;

Expand Down Expand Up @@ -95,8 +90,8 @@ class zip_iterator_reference
template <std::size_t... idxs>
void assign_impl(std::index_sequence<idxs...>, const value_type& other)
{
tuple_unpack_sink(
(std::get<idxs>(*this) = std::get<idxs>(other), 0)...);
(void)std::initializer_list<int>{
(std::get<idxs>(*this) = std::get<idxs>(other), 0)...};
}

zip_iterator_reference(Iterators... it) : ref_tuple_type{*it...} {}
Expand Down Expand Up @@ -262,25 +257,27 @@ class zip_iterator {
template <typename Functor, std::size_t... idxs>
void forall_impl(Functor fn, std::index_sequence<idxs...>)
{
tuple_unpack_sink((fn(std::get<idxs>(iterators_)), 0)...);
(void)std::initializer_list<int>{
(fn(std::get<idxs>(iterators_)), 0)...};
}

template <typename Functor, std::size_t... idxs>
void forall_impl(const zip_iterator& other, Functor fn,
std::index_sequence<idxs...>) const
{
tuple_unpack_sink(
(void)std::initializer_list<int>{
(fn(std::get<idxs>(iterators_), std::get<idxs>(other.iterators_)),
0)...);
0)...};
}

template <typename Functor>
auto forall_check_consistent(const zip_iterator& other, Functor fn) const
{
auto result =
fn(std::get<0>(iterators_), std::get<0>(other.iterators_));
auto it = std::get<0>(iterators_);
auto other_it = std::get<0>(other.iterators_);
auto result = fn(it, other_it);
forall_impl(
other, [&](auto a, auto b) { assert(fn(a, b) == result); },
other, [&](auto a, auto b) { assert(it - other_it == a - b); },
index_sequence{});
return result;
}
Expand Down Expand Up @@ -308,7 +305,7 @@ zip_iterator<std::decay_t<Iterators>...> make_zip_iterator(Iterators&&... it)
* // now both a and b point to the same value that was originally at b
* ```
* It is modelled after the behavior of std::vector<bool> bit references.
* To swap in generic code, use the pattern `using std::swap; swap(a, b)`
* To swap in generic code, use the pattern `using std::swap; swap(a, b);`
*
* @tparam Iterators the iterator types inside the corresponding zip_iterator
*/
Expand Down
1 change: 1 addition & 0 deletions core/test/base/iterator_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


#include <algorithm>
#include <complex>
#include <numeric>
#include <vector>

Expand Down

0 comments on commit 73e9433

Please sign in to comment.