Skip to content

Commit 1de0f1d

Browse files
committed
added simple-allocator exposition-only concept (#19)
1 parent dbbb810 commit 1de0f1d

File tree

5 files changed

+153
-1
lines changed

5 files changed

+153
-1
lines changed

docs/TODO.json

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
{
2+
"allocator.requirements.general": { "code":true, "test":true, "doc":false },
23
"execution": { "code":true, "test":true, "doc":true, "comment":"empty" },
34
"execution.queries": { "code":true, "test":true, "doc":true, "comment":"empty" },
5+
"execution.queryable": { "code":true, "test":true, "doc":true, "comment":"empty" },
6+
"execution.queryable.general]": { "code":true, "test":true, "doc":false, "comment":"nothing testable" },
7+
"execution.queryable.concepts": { "code":true, "test":true, "doc":false },
48
"execution.receivers": { "code":true, "test":true, "doc":true, "comment":"empty" },
59
"execution.senders": { "code":true, "test":true, "doc":true, "comment":"empty" },
610
"execution.senders.factories": { "code":true, "test":true, "doc":true, "comment":"empty" },
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// include/Beman/Execution26/detail/simple-allocator.hpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#ifndef INCLUDED_BEMAN_EXECUTION26_DETAIL_SIMPLE_ALLOCATOR
5+
#define INCLUDED_BEMAN_EXECUTION26_DETAIL_SIMPLE_ALLOCATOR
6+
7+
#include <cstddef>
8+
#include <concepts>
9+
10+
// ----------------------------------------------------------------------------
11+
12+
namespace Beman::Execution26::Detail
13+
{
14+
template <typename Alloc>
15+
concept simple_allocator
16+
= requires(Alloc alloc, ::std::size_t n)
17+
{
18+
{ *alloc.allocate(n) } -> ::std::same_as<typename Alloc::value_type&>;
19+
alloc.deallocate(alloc.allocate(n), n);
20+
}
21+
&& ::std::copy_constructible<Alloc>
22+
&& ::std::equality_comparable<Alloc>
23+
;
24+
}
25+
26+
// ----------------------------------------------------------------------------
27+
28+
#endif

src/Beman/Execution26/tests/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
33

44
list(APPEND execution_tests
5+
allocator-requirements-general.pass
56
exec-general.pass
67
exec-utils-cmplsigs.pass
78
functional-syn.pass
89
exec-recv.pass
9-
queryable.pass
10+
execution-queryable-concept.pass
1011
exec-get-env.pass
1112
exec-set-stopped.pass
1213
exec-set-error.pass
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// src/Beman/Execution26/tests/allocator-requirements-general.pass.cpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#include <Beman/Execution26/detail/simple-allocator.hpp>
5+
#include <test/execution.hpp>
6+
7+
// ----------------------------------------------------------------------------
8+
9+
namespace
10+
{
11+
enum class size_type {};
12+
13+
struct non_allocator {};
14+
struct no_allocate
15+
{
16+
using value_type = int;
17+
auto deallocate(int*, ::std::size_t) -> void {}
18+
19+
auto operator== (no_allocate const&) const -> bool = default;
20+
};
21+
struct no_deallocate
22+
{
23+
using value_type = int;
24+
auto allocate(::std::size_t n) -> int* { return new int[n]; }
25+
26+
auto operator== (no_deallocate const&) const -> bool = default;
27+
};
28+
29+
struct no_value_type
30+
{
31+
auto allocate(::std::size_t n) -> int* { return new int[n]; }
32+
auto deallocate(int*, ::std::size_t) -> void {}
33+
34+
auto operator== (no_value_type const&) const -> bool = default;
35+
};
36+
37+
struct allocate_return_type_mismatch
38+
{
39+
using value_type = long;
40+
auto allocate(::std::size_t n) -> int* { return new int[n]; }
41+
auto deallocate(int*, ::std::size_t) -> void {}
42+
43+
auto operator== (allocate_return_type_mismatch const&) const -> bool = default;
44+
};
45+
46+
struct allocate_size_type_mismatch
47+
{
48+
using value_type = int; //-dk:TODO long;
49+
auto allocate(size_type n) -> int* { return new int[::std::size_t(n)]; }
50+
auto deallocate(int*, ::std::size_t) -> void {}
51+
52+
auto operator== (allocate_size_type_mismatch const&) const -> bool = default;
53+
};
54+
55+
struct deallocate_object_type_mismatch
56+
{
57+
using value_type = int;
58+
auto allocate(::std::size_t n) -> int* { return new int[n]; }
59+
auto deallocate(long*, ::std::size_t) -> void {}
60+
61+
auto operator== (deallocate_object_type_mismatch const&) const -> bool = default;
62+
};
63+
64+
struct deallocate_size_type_mismatch
65+
{
66+
using value_type = int;
67+
auto allocate(::std::size_t n) -> int* { return new int[n]; }
68+
auto deallocate(int*, size_type) -> void {}
69+
70+
auto operator== (deallocate_size_type_mismatch const&) const -> bool = default;
71+
};
72+
73+
struct not_copy_constructible
74+
{
75+
using value_type = int;
76+
77+
not_copy_constructible(not_copy_constructible const&) = delete;
78+
auto allocate(::std::size_t n) -> int* { return new int[n]; }
79+
auto deallocate(/*long*/int*, ::std::size_t) -> void {}
80+
81+
auto operator== (not_copy_constructible const&) const -> bool = default;
82+
};
83+
84+
struct not_equality_comparable
85+
{
86+
using value_type = int;
87+
88+
auto allocate(::std::size_t n) -> int* { return new int[n]; }
89+
auto deallocate(int*, ::std::size_t) -> void {}
90+
91+
auto operator== (not_equality_comparable const&) const -> bool = delete;
92+
};
93+
94+
struct allocator
95+
{
96+
using value_type = int;
97+
98+
auto allocate(::std::size_t n) -> int* { return new int[n]; }
99+
auto deallocate(int* object, ::std::size_t) -> void { delete[] object; }
100+
101+
auto operator== (allocator const&) const -> bool = default;
102+
};
103+
}
104+
105+
auto main() -> int
106+
{
107+
static_assert(not test_detail::simple_allocator<non_allocator>);
108+
static_assert(not test_detail::simple_allocator<no_allocate>);
109+
static_assert(not test_detail::simple_allocator<no_deallocate>);
110+
static_assert(not test_detail::simple_allocator<no_value_type>);
111+
static_assert(not test_detail::simple_allocator<allocate_return_type_mismatch>);
112+
static_assert(not test_detail::simple_allocator<allocate_size_type_mismatch>);
113+
static_assert(not test_detail::simple_allocator<deallocate_object_type_mismatch>);
114+
static_assert(not test_detail::simple_allocator<deallocate_size_type_mismatch>);
115+
static_assert(not test_detail::simple_allocator<not_copy_constructible>);
116+
static_assert(not test_detail::simple_allocator<not_equality_comparable>);
117+
118+
static_assert(test_detail::simple_allocator<allocator>);
119+
}

0 commit comments

Comments
 (0)