aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.generator/coroutine_traits.ccm
blob: 2a9d51dff097aeedb2ee07115c659eaa41f44846 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
///////////////////////////////////////////////////////////////////////////////
// Reference implementation of std::generator proposal P2168.
//
// See https://wg21.link/P2168 for details.
//
///////////////////////////////////////////////////////////////////////////////
// Copyright Lewis Baker, Corentin Jabot
//
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0.
// (See accompanying file LICENSE or http://www.boost.org/LICENSE_1_0.txt)
///////////////////////////////////////////////////////////////////////////////

module;

#include <coroutine>
#include <memory>

export module nihil.generator:coroutine_traits;

import :byte_allocator;
import :forward;
import :generator_promise;

namespace std {

// Type-erased allocator with default allocator behaviour.
export template <typename Ref, typename Value, typename... Args>
struct coroutine_traits<nihil::generator<Ref, Value>, Args...>
{
	using promise_type =
		nihil::generator_promise<nihil::generator<Ref, Value>, std::allocator<std::byte>>;
};

// Type-erased allocator with std::allocator_arg parameter
export template <typename Ref, typename Value, typename Alloc, typename... Args>
struct coroutine_traits<nihil::generator<Ref, Value>, allocator_arg_t, Alloc, Args...>
{
private:
	using byte_allocator = nihil::byte_allocator_t<Alloc>;

public:
	using promise_type = nihil::generator_promise<nihil::generator<Ref, Value>, byte_allocator,
	                                              true /*explicit Allocator*/>;
};

// Type-erased allocator with std::allocator_arg parameter (non-static member functions)
export template <typename Ref, typename Value, typename This, typename Alloc, typename... Args>
struct coroutine_traits<nihil::generator<Ref, Value>, This, allocator_arg_t, Alloc, Args...>
{
private:
	using byte_allocator = nihil::byte_allocator_t<Alloc>;

public:
	using promise_type = nihil::generator_promise<nihil::generator<Ref, Value>, byte_allocator,
	                                              true /*explicit Allocator*/>;
};

// Generator with specified allocator type
export template <typename Ref, typename Value, typename Alloc, typename... Args>
struct coroutine_traits<nihil::generator<Ref, Value, Alloc>, Args...>
{
	using byte_allocator = nihil::byte_allocator_t<Alloc>;

public:
	using promise_type =
		nihil::generator_promise<nihil::generator<Ref, Value, Alloc>, byte_allocator>;
};

} // namespace std