-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollection_type.hpp
More file actions
54 lines (48 loc) · 1.37 KB
/
collection_type.hpp
File metadata and controls
54 lines (48 loc) · 1.37 KB
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
#pragma once
#include <vector>
#include <string_view>
#include <type_traits>
#include <memory_resource>
namespace atom
{
class collection {};
template <const char* key_value, typename type>
class collection_type : public collection
{
public:
template <typename Value, typename = std::enable_if_t<
std::is_constructible_v<std::pmr::vector<type>, std::remove_const_t<std::decay_t<Value>>>
>>
constexpr collection_type(Value&& values)
: values_ { std::forward<Value>(values) }
{ }
template <typename... Value, typename = std::enable_if_t<
std::conjunction_v<std::is_constructible<type, std::remove_cv_t<std::decay_t<Value>>>...>
>>
constexpr collection_type(Value&&... values)
: allocator { stack_buffer, sizeof stack_buffer },
values_ { { std::forward<Value>(values)... }, &allocator }
{ }
constexpr collection_type()
: allocator { stack_buffer, sizeof stack_buffer },
values_ { &allocator }
{ }
[[nodiscard]]std::string_view key() const noexcept
{
return key_;
}
[[nodiscard]] const std::pmr::vector<type>& values() const noexcept
{
return values_;
}
[[nodiscard]] std::pmr::vector<type>& values() noexcept
{
return values_;
}
private:
const char* key_ { key_value };
std::byte stack_buffer[1024];
std::pmr::monotonic_buffer_resource allocator;
std::pmr::vector<type> values_;
};
}