#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 . */ #ifndef BLT_ITERATOR_FLATTEN_H #define BLT_ITERATOR_FLATTEN_H #include #include namespace blt::iterator { namespace detail { template struct make_tuple { using type = std::tuple; static auto convert(T& f) { return std::forward_as_tuple(f); } static auto convert(T&& f) { return std::forward_as_tuple(f); } }; template struct make_tuple> { using type = std::tuple; static std::tuple& convert(std::tuple& lvalue) { return lvalue; } static std::tuple&& convert(std::tuple&& rvalue) { return rvalue; } }; } template class flatten_wrapper : public deref_only_wrapper> { public: using iterator_category = typename std::iterator_traits::iterator_category; // using value_type = std::invoke_result_t>; using difference_type = ptrdiff_t; // using pointer = value_type; // using reference = value_type; explicit flatten_wrapper(Iter iter): deref_only_wrapper>(std::move(iter)) { } reference operator*() const { return func(*this->iter); } }; } #endif //BLT_ITERATOR_FLATTEN_H