Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

elements: view to extracts elements of tuple-like objects #195

Closed
wants to merge 1 commit into from

Conversation

cor3ntin
Copy link

@cor3ntin cor3ntin commented Oct 7, 2018

sequence_of_tuple | ranges::ext::view::elements<42>
static_array | ranges::ext::view::elements<0>

map | ranges::ext::view::keys;
map | ranges::ext::view::values;

sequence_of_tuple | ranges::ext::view::elements<42>
static_array | ranges::ext::view::elements<0>

map | ranges::ext::view::keys;
map | ranges::ext::view::values;
@cor3ntin
Copy link
Author

cor3ntin commented Oct 7, 2018

Hi @CaseyCarter, could tell me what you think about this?
The goal was to take a bit of work out of @cjdb for his range paper.

I currently have a weird issue if I try a static_assert(View<Rng>), any idea what I could have done wrong?
I suspect the issue is that I need to instantiate the view with an explicit type (given i have to pass 2 template parameter), and I'm probably screwing it up

/usr/include/c++/8/type_traits: In substitution of ‘template<class _Tp> decltype (__declval<_Tp>(0)) std::declval() [with _Tp = std::experimental::ranges::v1::ext::ref_view<std::experimental::ranges::v1::ext::elements_view<std::experimental::ranges::v1::ext::ref_view<std::vector<std::tuple<int, int, int> > >, 0> >]’:
/home/cor3ntin/dev/cpp_proposals/move_only_io_iterator/cmcstl2/include/stl2/view/all.hpp:54:38:   recursively required by substitution of ‘template<class Rng>  requires  ViewableRange<Rng> using all_view = decltype (std::experimental::ranges::v1::view::all(declval<Rng>())) [with Rng = std::experimental::ranges::v1::ext::ref_view<std::experimental::ranges::v1::ext::elements_view<std::experimental::ranges::v1::ext::ref_view<std::vector<std::tuple<int, int, int> > >, 0> >]’
/home/cor3ntin/dev/cpp_proposals/move_only_io_iterator/cmcstl2/include/stl2/view/all.hpp:54:38:   required from ‘struct std::is_constructible<std::experimental::ranges::v1::ext::ref_view<std::experimental::ranges::v1::ext::elements_view<std::experimental::ranges::v1::ext::ref_view<std::vector<std::tuple<int, int, int> > >, 0> >, std::experimental::ranges::v1::ext::ref_view<std::experimental::ranges::v1::ext::elements_view<std::experimental::ranges::v1::ext::ref_view<std::vector<std::tuple<int, int, int>, std::allocator<std::tuple<int, int, int> > > >, 0> > >’
/home/cor3ntin/dev/cpp_proposals/move_only_io_iterator/cmcstl2/include/stl2/detail/concepts/core.hpp:31:43:   required from ‘constexpr auto std::experimental::ranges::v1::view::__all_fn::operator()(Rng&&) const [with Rng = std::experimental::ranges::v1::ext::elements_view<std::experimental::ranges::v1::ext::ref_view<std::vector<std::tuple<int, int, int> > >, 0>&]’
/home/cor3ntin/dev/cpp_proposals/move_only_io_iterator/cmcstl2/include/stl2/view/all.hpp:49:37:   required by substitution of ‘template<class Rng>  requires  ViewableRange<Rng> using all_view = decltype (std::experimental::ranges::v1::view::all(declval<Rng>())) [with Rng = std::experimental::ranges::v1::ext::elements_view<std::experimental::ranges::v1::ext::ref_view<std::vector<std::tuple<int, int, int> > >, 0>&]’
/home/cor3ntin/dev/cpp_proposals/move_only_io_iterator/cmcstl2/include/stl2/view/all.hpp:54:38:   required from ‘struct std::is_constructible<std::experimental::ranges::v1::ext::elements_view<std::experimental::ranges::v1::ext::ref_view<std::vector<std::tuple<int, int, int> > >, 0>, std::experimental::ranges::v1::ext::elements_view<std::experimental::ranges::v1::ext::ref_view<std::vector<std::tuple<int, int, int>, std::allocator<std::tuple<int, int, int> > > >, 0>&>’
/home/cor3ntin/dev/cpp_proposals/move_only_io_iterator/cmcstl2/include/stl2/detail/concepts/core.hpp:31:43:   required from here
/usr/include/c++/8/type_traits:756:55: fatal error: template instantiation depth exceeds maximum of 900 (use -ftemplate-depth= to increase the maximum)
     auto declval() noexcept -> decltype(__declval<_Tp>(0));

@cjdb
Copy link
Collaborator

cjdb commented Nov 1, 2018

This is what I've been using in my zip_with branch. Is there any reason we can't go with this instead? (I don't think it breaks any equality preservation).

namespace view {
	template<int X>
	requires (X == 0) || (X == 1)
	struct __get_fn {
		template<class P>
		requires _PairLike<remove_reference_t<P>> // from subrange.hpp
		constexpr decltype(auto) operator()(P&& p) const
		{
			using T = decltype(std::get<X>(std::forward<P>(p)));
			return std::forward<T>(std::get<X>(std::forward<P>(p)));
		}
	};

	inline constexpr auto keys = view::transform(__get_fn<0>{});
	inline constexpr auto values = view::transform(__get_fn<1>{});
} // namespace view

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants