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

Why does ranges not support std::back_inserter? #867

yaoxinliu opened this issue Jul 20, 2018 · 2 comments


Copy link

commented Jul 20, 2018

        auto src = std::vector<int>{ 1, 2, 3 };
	std::vector<int> dst;

	// ok
	std::copy(src.begin(), src.end(),

	// ok
	ranges::copy(src, ranges::back_inserter(dst));

	// not ok
	ranges::copy(src, std::back_inserter(dst));

This comment has been minimized.

Copy link

commented Jul 20, 2018

Because it doesn't satisfy the Iterator concept as the range library defines it (it's not default constructible). That will be fixed in C++20. At least, that's the plan.


This comment has been minimized.

Copy link

commented Jun 13, 2019

I bumped into the same problem:

I think by following existing rules too strickly the library is consistently overconstraining the algorithms. I think there was no need to define Iterator as default constructible in the first place. If that is not possible to change, unfortunately we will have to define eventually NonNecessarelyDefaultConstructibleIterator relaxing that condition.

I once did a crude survey of which STL algorithms in effect need default-constructibility and it turns out that in libc++, at the time, it were std::minmax_element and std::rotate, and in both cases there was no actual need for that. I think partially-formed and/or default-constructibility are not bad per se, but requiring it is the problem.

(Another example is requiring Sentinels to be left and right comparable with iterators when one can adopt the convention that Sentinels to be right and left comparable.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
3 participants
You can’t perform that action at this time.