Commit af7df254 authored by Pranjal Raihan's avatar Pranjal Raihan Committed by Facebook GitHub Bot

Make folly::detail::IteratorAdaptor default-constructible

Summary:
[Forward iterators are required to be default constructible](https://en.cppreference.com/w/cpp/named_req/ForwardIterator). So as of today, `IteratorAdaptor` is lying!

We should default construct the wrapped iterator into a [singular iterator](https://eel.is/c++draft/iterator.requirements#general-7):
> Iterators can also have singular values that are not associated with any sequence. Results of most expressions are undefined for singular values; the only exceptions are destroying an iterator that holds a singular value, the assignment of a non-singular value to an iterator that holds a singular value, and, for iterators that meet the `Cpp17DefaultConstructible` requirements, using a value-initialized iterator as the source of a copy or move operation.

Reviewed By: yfeldblum, mshneer

Differential Revision: D29578765

fbshipit-source-id: 7f2f0762b17f0b1a056532fc5db2abdd76cca3ea
parent 95f24e43
......@@ -155,7 +155,8 @@ class IteratorAdaptor : public IteratorFacade<D, V, Tag> {
using pointer = typename Super::pointer;
using difference_type = typename Super::difference_type;
explicit IteratorAdaptor(I base) : base_(base) {}
IteratorAdaptor() = default;
explicit IteratorAdaptor(I base) : base_(std::move(base)) {}
void increment() { ++base_; }
......
......@@ -235,6 +235,7 @@ struct dynamic::item_iterator : detail::IteratorAdaptor<
dynamic::ObjectImpl::iterator,
std::pair<dynamic const, dynamic>,
std::forward_iterator_tag>;
item_iterator() = default;
/* implicit */ item_iterator(dynamic::ObjectImpl::iterator b) : Super(b) {}
using object_type = dynamic::ObjectImpl;
......@@ -250,6 +251,7 @@ struct dynamic::value_iterator : detail::IteratorAdaptor<
dynamic::ObjectImpl::iterator,
dynamic,
std::forward_iterator_tag>;
value_iterator() = default;
/* implicit */ value_iterator(dynamic::ObjectImpl::iterator b) : Super(b) {}
using object_type = dynamic::ObjectImpl;
......@@ -268,6 +270,7 @@ struct dynamic::const_item_iterator
dynamic::ObjectImpl::const_iterator,
std::pair<dynamic const, dynamic> const,
std::forward_iterator_tag>;
const_item_iterator() = default;
/* implicit */ const_item_iterator(dynamic::ObjectImpl::const_iterator b)
: Super(b) {}
/* implicit */ const_item_iterator(const_item_iterator const& i)
......@@ -287,6 +290,7 @@ struct dynamic::const_key_iterator : detail::IteratorAdaptor<
dynamic::ObjectImpl::const_iterator,
dynamic const,
std::forward_iterator_tag>;
const_key_iterator() = default;
/* implicit */ const_key_iterator(dynamic::ObjectImpl::const_iterator b)
: Super(b) {}
......@@ -305,6 +309,7 @@ struct dynamic::const_value_iterator : detail::IteratorAdaptor<
dynamic::ObjectImpl::const_iterator,
dynamic const,
std::forward_iterator_tag>;
const_value_iterator() = default;
/* implicit */ const_value_iterator(dynamic::ObjectImpl::const_iterator b)
: Super(b) {}
/* implicit */ const_value_iterator(value_iterator i) : Super(i.base()) {}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment