boostorg / boostorg/core

Consider updating Allocator Access to add rvalue reference overloads

Open
#156 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
156
Forks
116
PR merge metrics
No merged PRs in 30d

Description

Right now most of allocator access takes the allocator by lvalue reference.

I presume this is to support stateful allocators.

Instead, I purport that allocator access should also work with temporarily materialized allocators.

This is useful in the case where we're rebinding a stored allocator and wishing to do a quick one-off allocation in a single place.

The goal is to remove the need to declare a stack-local, for example.

See the relevant CE example here: https://godbolt.org/z/hqKTGb3ab

Obligatory inline copy:
```cpp
#include
#include
#include

namespace boost
{

template
allocator_pointer_t>
allocator_allocate(A&& a, allocator_size_type_t> n)
{
return allocator_allocate(a,n);
}

}

auto tester(std::allocator a) {
// feed the rebound allocator directly using the converting constructor
//
return boost::allocator_allocate(std::allocator(a),16);

// want to avoid the need to declare `oa` to use the rebound allocator type
//
// std::allocator oa(a);
// return boost::allocator_allocate(oa,16);
}

```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.