Skip to content

Commit eb497bc

Browse files
Cra3zericniebler
andauthored
implement allocator concept (#1750)
--------- Co-authored-by: Eric Niebler <[email protected]>
1 parent 0e99835 commit eb497bc

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

include/stdexec/__detail/__concepts.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,4 +271,23 @@ namespace STDEXEC {
271271
template <class _Ty, class... _Us>
272272
requires __none_of<_Ty, _Us...>
273273
using __unless_one_of_t = _Ty;
274+
275+
namespace __detail {
276+
template <class _Alloc>
277+
auto __test_alloc_pointer(int) -> typename _Alloc::pointer;
278+
template <class _Alloc>
279+
auto __test_alloc_pointer(long) -> typename _Alloc::value_type*;
280+
281+
template <class _Alloc>
282+
using __alloc_pointer_t = decltype(__detail::__test_alloc_pointer<__decay_t<_Alloc>>(0));
283+
} // namespace __detail
284+
285+
template <class _Alloc>
286+
concept __allocator_ = //
287+
requires(__decay_t<_Alloc>& __alloc, std::size_t __bytes) {
288+
{ __alloc.allocate(__bytes) } -> same_as<__detail::__alloc_pointer_t<_Alloc>>;
289+
__alloc.deallocate(__alloc.allocate(__bytes), __bytes);
290+
} //
291+
&& copy_constructible<__decay_t<_Alloc>> //
292+
&& equality_comparable<__decay_t<_Alloc>>;
274293
} // namespace STDEXEC

include/stdexec/__detail/__queries.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ namespace STDEXEC {
2727
//////////////////////////////////////////////////////////////////////////////////////////////////
2828
// [exec.queries]
2929
namespace __queries {
30-
// TODO: implement allocator concept
31-
template <class _T0>
32-
concept __allocator_c = true;
33-
3430
//////////////////////////////////////////////////////////////////////////////////
3531
// [exec.get.allocator]
3632
struct get_allocator_t : __query<get_allocator_t> {
@@ -44,7 +40,7 @@ namespace STDEXEC {
4440
STDEXEC_ATTRIBUTE(always_inline, host, device)
4541
static constexpr void __validate() noexcept {
4642
static_assert(__nothrow_callable<get_allocator_t, const _Env&>);
47-
static_assert(__allocator_c<__call_result_t<get_allocator_t, const _Env&>>);
43+
static_assert(__allocator_<__call_result_t<get_allocator_t, const _Env&>>);
4844
}
4945

5046
STDEXEC_ATTRIBUTE(nodiscard, always_inline, host, device)

0 commit comments

Comments
 (0)