Why is there no std :: make_raw_storage_iterator?

I'm wondering why it std::raw_storage_iterator

doesn't have companions std::make_raw_storage_iterator

like std::move_iterator

and std::make_move_iterator

. The class template std::raw_storage_iterator

has two template parameters. So I think it is actually more useful to provide a make function for std::raw_storage_iterator

than std::move_iterator

that only has to specify one template parameter.

+3


source to share


1 answer


With @ dyps suggestions, a sane implementation is indeed possible:

template <typename OutputIt>
auto make_raw_storage_iterator( OutputIt out ) {
    return std::raw_storage_iterator<OutputIt, std::remove_pointer_t<decltype(&*out)>>(out);
}

      

( Demo with example cppreference)
This is guaranteed to work with ยง20.7.10 / 1, which imposes requirements on template arguments raw_storage_iterator

, requires:



OutputIterator

is required to be operator*

returned by the object for which it is operator&

defined and returns a pointer to T

[..]

Where T

is the second argument, the type of the output range value. Thus, given the underlying output iterator, we have sufficient information to determine the intended specialization raw_storage_iterator

.

The reason this was not suggested is undoubtedly nothing more than an oversight - consider that make_reverse_iterator

or make_unique

not even were provided prior to C ++ 14. Feel free to take the first step.

+2


source







All Articles