#ifndef PYTHONIC_BUILTIN_MAP_HPP #define PYTHONIC_BUILTIN_MAP_HPP #include "pythonic/include/builtins/map.hpp" #include "pythonic/itertools/common.hpp" #include "pythonic/types/tuple.hpp" #include "pythonic/utils/fwd.hpp" #include "pythonic/utils/int_.hpp" #include "pythonic/utils/iterator.hpp" #include "pythonic/utils/functor.hpp" #include "pythonic/utils/seq.hpp" #include #include #include PYTHONIC_NS_BEGIN namespace builtins { namespace details { template template map_iterator::map_iterator(Operator const &op, std::tuple &_iters, utils::index_sequence) : it(std::get(_iters).begin()...), _op(op) { } template template map_iterator::map_iterator(itertools::npos, Operator const &op, std::tuple &_iters, utils::index_sequence) : it(std::get(_iters).end()...), _op(op) { } template template typename map_res::type map_iterator::get_value(utils::index_sequence, std::false_type) const { return _op(*std::get(it)...); } template template typename map_res::type map_iterator::get_value(utils::index_sequence, std::true_type) const { return types::make_tuple(*std::get(it)...); } template typename map_res::type map_iterator:: operator*() const { return get_value(utils::make_index_sequence{}, std::is_same()); } template template void map_iterator::next(utils::index_sequence) { utils::fwd(++std::get(it)...); } template map_iterator &map_iterator:: operator++() { next(utils::make_index_sequence{}); return *this; } template template void map_iterator::advance(long i, utils::int_) { std::get(it) += i; advance(i, utils::int_()); } template void map_iterator::advance(long i, utils::int_<0>) { std::get<0>(it) += i; } template map_iterator &map_iterator:: operator+=(long i) { advance(i, utils::int_()); return *this; } template map_iterator map_iterator:: operator+(long i) const { map_iterator other(*this); other += i; return other; } template template bool map_iterator::equal( map_iterator const &other, utils::int_) const { return std::get(other.it) == std::get(it) || equal(other, utils::int_()); } template bool map_iterator::equal( map_iterator const &other, utils::int_<0>) const { return std::get<0>(other.it) == std::get<0>(it); } template bool map_iterator:: operator==(map_iterator const &other) const { return equal(other, utils::int_()); } template bool map_iterator:: operator!=(map_iterator const &other) const { return !(*this == other); } template bool map_iterator:: operator<(map_iterator const &other) const { return !(*this == other); } template template long map_iterator::min_len( map_iterator const &other, utils::int_) const { return std::min((long)(std::get(it) - std::get(other.it)), min_len(other, utils::int_())); } template long map_iterator::min_len( map_iterator const &other, utils::int_<0>) const { return std::get<0>(it) - std::get<0>(other.it); } template long map_iterator:: operator-(map_iterator const &other) const { return min_len(other, utils::int_()); } template template map::map(Operator const &_op, Types &&... _iters) : utils::iterator_reminder( std::forward(_iters)...), map_iterator( _op, this->values, utils::make_index_sequence{}), end_iter(itertools::npos(), _op, this->values, utils::make_index_sequence{}) { } template typename map::iterator &map::begin() { return *this; } template typename map::iterator const & map::begin() const { return *this; } template typename map::iterator const & map::end() const { return end_iter; } } template auto map(Operator &&_op, Iter &&... iters) -> details::map< typename std::remove_cv< typename std::remove_reference::type>::type, typename types::iterator::type>::type>::type...> { return {std::forward(_op), std::forward(iters)...}; } } PYTHONIC_NS_END #endif