Thanks to visit codestin.com
Credit goes to github.com

Skip to content

std::flat_set dispatches non-c++17 iterators to container's insert(const_iterator, InputIterator, InputIterator) #136656

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

Open
hewillk opened this issue Apr 22, 2025 · 3 comments · May be fixed by #137462
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Comments

@hewillk
Copy link
Contributor

hewillk commented Apr 22, 2025

#include <flat_set>
#include <iterator>
#include <sstream>
#include <ranges>
#include <boost/interprocess/containers/vector.hpp>
 
int main() {
  boost::container::vector<int> v;
  std::flat_set s(v);
  std::istringstream ints("0 1 1 0");
  auto r = std::ranges::subrange(std::istream_iterator<int>(ints),
                                 std::istream_iterator<int>())
         | std::views::transform([](int i) { return i * i; });
  s.insert_range(r);
}

https://godbolt.org/z/6P3rnod76

@frederick-vs-ja
Copy link
Contributor

frederick-vs-ja commented Apr 22, 2025

See the comments in this function:

template <class _Set, class _Range>
_LIBCPP_HIDE_FROM_ABI static void __append(_Set& __set, _Range&& __rng) {
if constexpr (requires { __set.__keys_.insert_range(__set.__keys_.end(), std::forward<_Range>(__rng)); }) {
// C++23 Sequence Container should have insert_range member function
// Note that not all Sequence Containers provide append_range.
__set.__keys_.insert_range(__set.__keys_.end(), std::forward<_Range>(__rng));
} else if constexpr (ranges::common_range<_Range>) {
__set.__keys_.insert(__set.__keys_.end(), ranges::begin(__rng), ranges::end(__rng));
} else {
for (auto&& __x : __rng) {
__set.__keys_.insert(__set.__keys_.end(), std::forward<decltype(__x)>(__x));
}
}
}
};

Can we just resolve this issue as invalid Resolved as invalid, i.e. not a bug because boost::container::vector<int> doesn't provide insert_range and hence doesn't meet the C++23 sequence container requirements ([sequence.reqmts])?

Or should we submit an LWG issue to make some new member functions optional for sequence containers?

CC @huixie90.

@frederick-vs-ja frederick-vs-ja added libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. and removed new issue labels Apr 22, 2025
@huixie90
Copy link
Contributor

I can simply add a cpp17 iterator check on the second branch. I am be conflicted about this. On the one hand, we can simply say that boost container is not standard compliant. On the other hand, even the boost one is not standard compliant, how can users’ ones be better?

@huixie90 huixie90 linked a pull request Apr 26, 2025 that will close this issue
@ldionne
Copy link
Member

ldionne commented May 6, 2025

I think it would be important to file a LWG issue about this. Sure, we can fix this as an extension, but at the end of the day the Standard has to be unambiguous about what containers should be supported in flat_foo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants