BCNP 3.2.1
Batched Command Network Protocol
Loading...
Searching...
No Matches
packet_storage.h
Go to the documentation of this file.
1#pragma once
2
4#include <cstddef>
5#include <type_traits>
6#include <vector>
7
8namespace bcnp {
9
23namespace detail {
24
25// Detection idiom helpers
26template<typename, typename = void>
27struct has_push_back : std::false_type {};
28
29template<typename T>
30struct has_push_back<T, std::void_t<decltype(std::declval<T>().push_back(std::declval<typename T::value_type>()))>>
31 : std::true_type {};
32
33template<typename, typename = void>
34struct has_size : std::false_type {};
35
36template<typename T>
37struct has_size<T, std::void_t<decltype(std::declval<T>().size())>>
38 : std::true_type {};
39
40template<typename, typename = void>
41struct has_clear : std::false_type {};
42
43template<typename T>
44struct has_clear<T, std::void_t<decltype(std::declval<T>().clear())>>
45 : std::true_type {};
46
47template<typename, typename = void>
48struct has_reserve : std::false_type {};
49
50template<typename T>
51struct has_reserve<T, std::void_t<decltype(std::declval<T>().reserve(std::size_t{}))>>
52 : std::true_type {};
53
54template<typename, typename = void>
55struct has_begin_end : std::false_type {};
56
57template<typename T>
58struct has_begin_end<T, std::void_t<decltype(std::declval<T>().begin()), decltype(std::declval<T>().end())>>
59 : std::true_type {};
60
61template<typename, typename = void>
62struct has_subscript : std::false_type {};
63
64template<typename T>
65struct has_subscript<T, std::void_t<decltype(std::declval<T>()[std::size_t{}])>>
66 : std::true_type {};
67
68} // namespace detail
69
75template<typename Container>
85
86template<typename Container>
88
95template<typename T>
96using DynamicPacketStorage = std::vector<T>;
97
107template<typename T, std::size_t Capacity = 64>
109
113template<typename T>
115
121template<typename Container>
122void ReserveIfPossible(Container& container, std::size_t capacity) {
124 container.reserve(capacity);
125 }
126}
127
128} // namespace bcnp
Fixed-capacity vector with no heap allocation.
std::vector< T > DynamicPacketStorage
Default packet storage using heap allocation.
constexpr bool IsValidPacketStorage_v
void ReserveIfPossible(Container &container, std::size_t capacity)
Helper to reserve capacity (no-op for static storage).
Fixed-capacity vector with stack allocation (no heap).
Concept-like check for valid packet storage containers.
static constexpr bool value