Skip to content

Commit ca16652

Browse files
committed
Add lifetime, ownership, and semantic documentation
- circular_dynamic_buffer: note that copies alias external storage - slice_of: add @tparam, example, thread safety, lifetime note - string_dynamic_buffer: add example and invalidation/lifetime note - strand: document moved-from state on move ctor/assign - thread_pool::executor_type: document unassociated default state - io_result<T1,T2> and <T1,T2,T3>: add @tparam and payload semantics - match_delim::delim: document string_view lifetime requirement
1 parent ad06e26 commit ca16652

File tree

7 files changed

+111
-15
lines changed

7 files changed

+111
-15
lines changed

include/boost/capy/buffers/circular_dynamic_buffer.hpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,14 @@ class circular_dynamic_buffer
7070
/// Construct an empty circular buffer with zero capacity.
7171
circular_dynamic_buffer() = default;
7272

73-
/// Construct a copy.
73+
/** Construct a copy.
74+
75+
Copies the adapter state (position and length) but does
76+
not deep-copy the backing storage. Both objects alias the
77+
same external buffer.
78+
79+
@note The underlying storage must outlive all copies.
80+
*/
7481
circular_dynamic_buffer(
7582
circular_dynamic_buffer const&) = default;
7683

@@ -110,7 +117,14 @@ class circular_dynamic_buffer
110117
detail::throw_invalid_argument();
111118
}
112119

113-
/// Assign by copying.
120+
/** Assign by copying.
121+
122+
Copies the adapter state but does not deep-copy the
123+
backing storage. Both objects alias the same external
124+
buffer afterward.
125+
126+
@note The underlying storage must outlive all copies.
127+
*/
114128
circular_dynamic_buffer& operator=(
115129
circular_dynamic_buffer const&) = default;
116130

include/boost/capy/buffers/slice.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,24 @@ using slice_type = std::conditional_t<
5252
kept using the free functions @ref keep_prefix,
5353
@ref remove_prefix, etc.
5454
55+
The wrapped sequence is stored by value. The underlying
56+
buffer memory must remain valid for the lifetime of the
57+
slice.
58+
59+
@par Thread Safety
60+
Distinct objects: Safe.
61+
Shared objects: Unsafe.
62+
63+
@par Example
64+
@code
65+
mutable_buffer buf(data, 100);
66+
auto s = prefix(buf, 50); // first 50 bytes
67+
remove_prefix(s, 10); // now bytes 10..49
68+
@endcode
69+
70+
@tparam BufferSequence The buffer sequence type, stored
71+
by value. Must satisfy @ref ConstBufferSequence.
72+
5573
@see keep_prefix, remove_prefix, prefix, sans_prefix
5674
*/
5775
template<ConstBufferSequence BufferSequence>

include/boost/capy/buffers/string_dynamic_buffer.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,25 @@ namespace capy {
2626
bytes are appended by `prepare` and made readable by
2727
`commit`.
2828
29+
@note The wrapped string must outlive this adapter.
30+
Calls to `prepare`, `commit`, and `consume`
31+
invalidate previously returned buffer views.
32+
2933
@par Thread Safety
3034
Distinct objects: Safe.
3135
Shared objects: Unsafe.
3236
37+
@par Example
38+
@code
39+
std::string s;
40+
auto buf = dynamic_buffer( s, 4096 );
41+
auto mb = buf.prepare( 100 );
42+
// fill mb with data...
43+
buf.commit( 100 );
44+
// buf.data() now has 100 readable bytes
45+
buf.consume( 50 );
46+
@endcode
47+
3348
@tparam CharT The character type.
3449
@tparam Traits The character traits type.
3550
@tparam Allocator The allocator type.

include/boost/capy/ex/strand.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ class strand
113113
strand(strand const&) = default;
114114

115115
/** Construct by moving.
116+
117+
@note A moved-from strand is only safe to destroy
118+
or reassign.
116119
*/
117120
strand(strand&&) = default;
118121

@@ -121,6 +124,9 @@ class strand
121124
strand& operator=(strand const&) = default;
122125

123126
/** Assign by moving.
127+
128+
@note A moved-from strand is only safe to destroy
129+
or reassign.
124130
*/
125131
strand& operator=(strand&&) = default;
126132

include/boost/capy/ex/thread_pool.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,12 @@ class thread_pool::executor_type
117117
}
118118

119119
public:
120-
/// Construct a default null executor.
120+
/** Construct a default null executor.
121+
122+
The resulting executor is not associated with any pool.
123+
`context()`, `dispatch()`, and `post()` require the
124+
executor to be associated with a pool before use.
125+
*/
121126
executor_type() = default;
122127

123128
/// Return the underlying thread pool.

include/boost/capy/io_result.hpp

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ namespace capy {
3232
if (ec) { ... }
3333
@endcode
3434
35-
@tparam Args Additional value types beyond the error code.
35+
@note Only 0, 1, 2, and 3 payload specializations are
36+
provided. Payload members are only meaningful when
37+
`ec` does not indicate an error.
38+
39+
@tparam Args Ordered payload types following the leading
40+
`std::error_code`.
3641
*/
3742
template<class... Args>
3843
struct io_result
@@ -100,7 +105,7 @@ struct [[nodiscard]] io_result<T1>
100105
/// The error code from the operation.
101106
std::error_code ec;
102107

103-
/// The first result value.
108+
/// The first payload value. Unspecified when `ec` is set.
104109
T1 t1{};
105110

106111
#ifdef _MSC_VER
@@ -132,6 +137,19 @@ struct [[nodiscard]] io_result<T1>
132137

133138
/** Result type for operations returning two values.
134139
140+
Stores a leading `std::error_code` followed by two
141+
operation-specific payload values. Inspect `t1` and `t2`
142+
only when `ec` does not indicate an error.
143+
144+
@par Example
145+
@code
146+
auto [ec, t1, t2] = co_await some_op();
147+
if (ec) { ... }
148+
@endcode
149+
150+
@tparam T1 First payload type following the error code.
151+
@tparam T2 Second payload type following T1.
152+
135153
@see io_result
136154
*/
137155
template<typename T1, typename T2>
@@ -140,10 +158,10 @@ struct [[nodiscard]] io_result<T1, T2>
140158
/// The error code from the operation.
141159
std::error_code ec;
142160

143-
/// The first result value.
161+
/// The first payload value. Unspecified when `ec` is set.
144162
T1 t1{};
145163

146-
/// The second result value.
164+
/// The second payload value. Unspecified when `ec` is set.
147165
T2 t2{};
148166

149167
#ifdef _MSC_VER
@@ -178,6 +196,20 @@ struct [[nodiscard]] io_result<T1, T2>
178196

179197
/** Result type for operations returning three values.
180198
199+
Stores a leading `std::error_code` followed by three
200+
operation-specific payload values. Inspect `t1`, `t2`,
201+
and `t3` only when `ec` does not indicate an error.
202+
203+
@par Example
204+
@code
205+
auto [ec, t1, t2, t3] = co_await some_op();
206+
if (ec) { ... }
207+
@endcode
208+
209+
@tparam T1 First payload type following the error code.
210+
@tparam T2 Second payload type following T1.
211+
@tparam T3 Third payload type following T2.
212+
181213
@see io_result
182214
*/
183215
template<typename T1, typename T2, typename T3>
@@ -186,13 +218,13 @@ struct [[nodiscard]] io_result<T1, T2, T3>
186218
/// The error code from the operation.
187219
std::error_code ec;
188220

189-
/// The first result value.
221+
/// The first payload value. Unspecified when `ec` is set.
190222
T1 t1{};
191223

192-
/// The second result value.
224+
/// The second payload value. Unspecified when `ec` is set.
193225
T2 t2{};
194226

195-
/// The third result value.
227+
/// The third payload value. Unspecified when `ec` is set.
196228
T3 t3{};
197229

198230
#ifdef _MSC_VER
@@ -230,8 +262,8 @@ struct [[nodiscard]] io_result<T1, T2, T3>
230262

231263
#ifdef _MSC_VER
232264

233-
/// @name Free-standing get() overloads for ADL (MSVC aggregate workaround).
234-
/// @{
265+
// Free-standing get() overloads for ADL (MSVC aggregate workaround).
266+
/// @cond
235267

236268
template<std::size_t I>
237269
auto& get(io_result<>& r) noexcept
@@ -305,7 +337,7 @@ auto&& get(io_result<T1, T2, T3>&& r) noexcept
305337
return std::move(r).template get<I>();
306338
}
307339

308-
/// @}
340+
/// @endcond
309341

310342
#endif // _MSC_VER
311343

include/boost/capy/read_until.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,21 @@ struct read_until_awaitable
205205
*/
206206
struct match_delim
207207
{
208-
/// The delimiter string to search for.
208+
/** The delimiter string to search for.
209+
210+
@note The referenced characters must remain valid
211+
for the lifetime of this object and any pending
212+
read operation.
213+
*/
209214
std::string_view delim;
210215

211216
/** Search for the delimiter in `data`.
212217
213218
@param data The data to search.
214219
@param hint If non-null, receives the overlap hint
215220
on miss.
216-
@return Position past the delimiter, or `npos`.
221+
@return `0` if `delim` is empty; otherwise the position
222+
just past the delimiter, or `npos` if not found.
217223
*/
218224
std::size_t
219225
operator()(

0 commit comments

Comments
 (0)