[libcxx-commits] [PATCH] D149826: [libc++][ranges] Implement the changes to vector from P1206 (`ranges::to`):
Nikolas Klauser via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Fri May 12 10:52:40 PDT 2023
philnik added a comment.
In D149826#4338420 <https://reviews.llvm.org/D149826#4338420>, @var-const wrote:
> @rupprecht Just a heads-up: this patch refactors the internals of `vector` and thus carries some amount of risk of a possible breakage. The tests in this patch are quite extensive, but I'd still like to give you a warning just in case you notice any new failures that this patch could be the culprit.
>
> Adding libc++-vendors to subscribers as well.
>
> In D149826#4338357 <https://reviews.llvm.org/D149826#4338357>, @asmok-g wrote:
>
>> Before this patch, if a non-copy-constructible Iterator was passed to the vector constructor `vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last)` it compiled, but now it gives the error: `call to deleted constructor of 'Iterator'`. Is that expected ?
>>
>> smth like
>>
>> #include <iterator>
>> #include <vector>
>>
>> const char* data = "abc";
>>
>> class Iterator : public std::iterator<std::input_iterator_tag, const char> {
>> public:
>> explicit Iterator(const char c) {}
>> Iterator(const Iterator& other) = delete;
>> Iterator& operator=(const Iterator& other) = delete;
>> reference operator*() const { return data[0]; }
>> void operator++() {}
>> bool operator==(const Iterator& other) const { return true; }
>> bool operator!=(const Iterator& other) const { return false; }
>> };
>>
>> class Elem {
>> public:
>> Elem() = default;
>> explicit Elem(const char ref) {}
>> };
>>
>> int main(int argc, char** argv) {
>> std::vector<Elem>(Iterator(data[0]), Iterator(data[1]));
>> }
>
> Thank you for the report! Is this blocking you?
>
> I will look into this today. Hopefully it's an easy fix.
An InputIterator has to be copy-constructible: http://eel.is/c++draft/iterator.iterators#2.1, and IMO we should enforce that even if we don't make use of the functionality (e.g. `static_assert(is_copy_constructible<_InputIterator>::value, "InputIterator has to be copy constructible")`).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D149826/new/
https://reviews.llvm.org/D149826
More information about the libcxx-commits
mailing list