/// \file // Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_VIEW_MAP_HPP #define RANGES_V3_VIEW_MAP_HPP #include #include #include #include #include #include #include // TODO: Reuse subrange's pair_like concept here and have get_first and get_second // dispatch through get<>() namespace ranges { /// \cond namespace detail { template constexpr T & get_first_second_helper(T & t, std::true_type) noexcept { return t; } template constexpr auto get_first_second_helper(T & t, std::false_type) noexcept( std::is_nothrow_move_constructible::value) -> CPP_ret(T)( // requires move_constructible) { return std::move(t); } template using get_first_second_tag = meta::bool_::value || std::is_lvalue_reference::value>; struct get_first { // clang-format off template constexpr auto CPP_auto_fun(operator())(Pair &&p)(const) ( return get_first_second_helper( p.first, get_first_second_tag{}) ) // clang-format on }; struct get_second { // clang-format off template constexpr auto CPP_auto_fun(operator())(Pair &&p)(const) ( return get_first_second_helper( p.second, get_first_second_tag{}) ) // clang-format on }; // clang-format off CPP_def ( template(typename T) concept kv_pair_like_, invocable && invocable ); // clang-format on } // namespace detail /// \endcond /// \addtogroup group-views /// @{ namespace views { struct keys_fn { template auto operator()(Rng && rng) const -> CPP_ret(keys_range_view>)( // requires viewable_range && input_range && detail::kv_pair_like_>) { return {all(static_cast(rng)), detail::get_first{}}; } }; struct values_fn { template auto operator()(Rng && rng) const -> CPP_ret(values_view>)( // requires viewable_range && input_range && detail::kv_pair_like_>) { return {all(static_cast(rng)), detail::get_second{}}; } }; /// \relates keys_fn /// \ingroup group-views RANGES_INLINE_VARIABLE(view, keys) /// \relates values_fn /// \ingroup group-views RANGES_INLINE_VARIABLE(view, values) } // namespace views namespace cpp20 { namespace views { using ranges::views::keys; using ranges::views::values; } // namespace views // TODO(@cjdb): provide implementation for elements_view } // namespace cpp20 /// @} } // namespace ranges #endif