jeudi 7 février 2019

uninitialized_X functions that use the allocator constructor?

Is there a version of uninitialized_value_construct that uses the an allocator to construct the element in place instead of placement new?

This below is the prototypical implementation of uninitialized_value_construct; however I am looking for one where the allocator is passed so I can use the line alloc.construct(std::addressof(*current)) instead of ::new (std::addressof(*current)).

template<class ForwardIt>
void uninitialized_value_construct(ForwardIt first, ForwardIt last)
{
    using Value = typename std::iterator_traits<ForwardIt>::value_type;
    ForwardIt current = first;
    try {
        for (; current != last; ++current) {
            ::new (static_cast<void*>(std::addressof(*current))) Value();
        }
    } catch (...) {
        std::destroy(first, current);
        throw;
    }
}

In C++20, there is uninitialized_construct_using_allocator but it is not clear what it is for or how to use it.

Aucun commentaire:

Enregistrer un commentaire