-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshared_buffer.hpp
More file actions
701 lines (631 loc) · 23.5 KB
/
shared_buffer.hpp
File metadata and controls
701 lines (631 loc) · 23.5 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
/** @mainpage Reference Counted Byte Buffer Classes, Const and Mutable Versions
*
* ## Overview
*
* The @c shared_buffer classes provide byte buffers with internal reference counting.
* These classes can be used within asynchronous IO / networking applications where the
* lifetime of the buffer must be kept alive until a requested IO operation completes.
*
* For example, a network write is started asynchronously, which means a write request
* is started, and the write completion will happen at a later time. The byte buffer
* must be kept alive until the completion notification. Meanwhile multiple other
* write requests can happen simultaneously (even on the same thread). For reads, a
* read request can be started, and the byte buffer used for incoming data will be
* kept alive until a read request completes - i.e. data arrives.
*
* In networking applications, this allows multiple sockets to be performing reads
* and writes under one thread (or multiple threads, such as in a thread pool).
* In particular, it eliminates the (sometimes inefficient) design of "one thread
* per socket".
*
* The Connective C++ Chops Net IP library is an asynchronous networking library (using
* Asio underneath) and it uses @c shared_buffer classes for buffer lifetime management.
*
* There are two concrete classes, @c mutable_shared_buffer and @c const_shared_buffer.
* @c mutable_shared_buffer is a reference counted modifiable buffer class with
* convenience methods for appending data. @c const_shared_buffer is a reference counted
* non-modifiable buffer class. Once the object is constructed, it cannot be modified.
*
* A @c const_shared_buffer can be efficiently constructed (no buffer copies, only
* pointer assignments through move construction) from a @c mutable shared_buffer. This
* allows the use case of serializing data into a @c mutable_shared_buffer then
* constructing a @c const_shared_buffer for writing to the network.
*
* Besides the data buffer lifetime management, these utility classes eliminate data
* copies and (obviously) can be utilized in use cases other than networking.
*
* ### Additional Details
*
* Internally all data is stored in a @c std::vector of @c std::byte. There are
* convenience templated constructors so that the @c shared_buffer objects can
* be constructed from traditional byte buffers, such as @c char @c *.
*
* There are ordering methods so that shared buffer objects can be stored in
* sequential or associative containers.
*
* Efficient moving of data (versus copying) is enabled in multiple ways, including
* allowing a @c const_shared_buffer to be move constructed from a
* @c mutable_shared_buffer, and allowing a @c std::vector of @c std::byte to be moved
* into either @c shared_buffer type.
*
* The implementation is adapted from Chris Kohlhoff's reference counted buffer
* examples in the Asio library. It has been significantly modified by adding a
* @c mutable_shared_buffer class as well as adding convenience methods to the
* @c const_shared_buffer class.
*
* It is likely that this shared buffer design and code will change as the C++
* Networking TS buffer features are expanded, changed, or better understood. Currently
* there are no direct ties to Networking TS buffer features.
*
* @note Everything is declared @c noexcept except for the methods that allocate
* memory and might throw a memory exception. This is tighter than the @c noexcept
* declarations on the underlying @c std::vector methods, since @c std::byte
* operations will never throw.
*
* @authors Cliff Green, Chris Kohlhoff
*
* @copyright (c) 2017-2025 by Cliff Green
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*
*/
#ifndef SHARED_BUFFER_HPP_INCLUDED
#define SHARED_BUFFER_HPP_INCLUDED
#include <cstddef> // std::byte
#include <vector>
#include <memory> // std::shared_ptr
#include <compare> // spaceship operator
#include <span>
#include <utility> // std::move, std::swap
#include <algorithm> // std::copy
// TODO - add concepts and / or requires
//
// modify the templated constructor that takes a buffer of any valid
// byte type, add constraints which makes the casting safer
namespace chops {
class const_shared_buffer;
/**
* @brief A mutable (modifiable) byte buffer class with convenience methods, internally
* reference-counted for efficient copying and lifetime management.
*
* This class provides ownership, copying, and lifetime management for byte oriented
* buffers. In particular, it is designed to be used in conjunction with the
* @c const_shared_buffer class for efficient transfer and correct lifetime management
* of buffers in asynchronous libraries (such as the C++ Networking TS). In particular,
* a reference counted buffer can be passed among multiple layers of software without
* any one layer "owning" the buffer.
*
* A @c std::byte pointer returned by the @c data method may be invalidated if the
* @c mutable_shared_buffer is modified in any way (this follows the usual constraints
* on @c std::vector iterator invalidation).
*
* This class is similar to @c const_shared_buffer, but with mutable characteristics.
*
* @invariant There will always be an internal buffer of data, even if the size is zero.
*
* @note Modifying the underlying buffer of data (for example by writing bytes using the
* @c data method, or appending data) will show up in any other @c mutable_shared_buffer
* objects that have been copied to or from the original object.
*
*/
class mutable_shared_buffer {
public:
using byte_vec = std::vector<std::byte>;
using size_type = typename byte_vec::size_type;
private:
std::shared_ptr<byte_vec> m_data;
private:
friend class const_shared_buffer;
friend bool operator==(const mutable_shared_buffer&, const const_shared_buffer&) noexcept;
friend bool operator==(const const_shared_buffer&, const mutable_shared_buffer&) noexcept;
public:
// default copy and move construction, copy and move assignment
mutable_shared_buffer(const mutable_shared_buffer&) = default;
mutable_shared_buffer(mutable_shared_buffer&&) = default;
mutable_shared_buffer& operator=(const mutable_shared_buffer&) = default;
mutable_shared_buffer& operator=(mutable_shared_buffer&&) = default;
/**
* @brief Default construct the @c mutable_shared_buffer.
*
*/
mutable_shared_buffer() noexcept :
m_data{std::make_shared<byte_vec>(size_type(0))} { }
/**
* @brief Construct by copying from a @c std::span of @c std::byte.
*
* @param sp @c std::byte span pointing to buffer of data. The data is
* copied into the internal buffer of the @c mutable_shared_buffer.
*
*/
template <std::size_t Ext>
explicit mutable_shared_buffer(std::span<const std::byte, Ext> sp) :
m_data{std::make_shared<byte_vec>(sp.data(), sp.data()+sp.size())} { }
/**
* @brief Construct by copying from a @c std::byte array.
*
* A @c std::span is first created, then the constructor taking
* a @c std::span is called.
*
* @pre Size cannot be greater than the source buffer.
*
* @param buf Non-null pointer to a @c std::byte buffer of data. The
* data is copied into the internal buffer of the @c mutable_shared_buffer.
*
* @param sz Size of buffer.
*
*/
mutable_shared_buffer(const std::byte* buf, std::size_t sz) :
mutable_shared_buffer(std::as_bytes(std::span<const std::byte>{buf, sz})) { }
/**
* @brief Move construct from a @c std::vector of @c std::bytes.
*
* Efficiently construct from a @c std::vector of @c std::bytes by moving
* into a @c mutable_shared_buffer.
*
* @note The @c std::byte @c std::vector passed in will be left in a
* "moved from" state (as it typical with move operations).
*
*/
explicit mutable_shared_buffer(byte_vec&& bv) noexcept :
m_data{std::make_shared<byte_vec>(size_type(0))} {
*m_data = std::move(bv);
}
/**
* @brief Construct a @c mutable_shared_buffer with an initial size, contents
* of each byte set to zero.
*
* Allocate zero initialized space which can be overwritten with data as needed.
* The @c data method is called to get access to the underlying @c std::byte
* buffer.
*
* @param sz Size for internal @c std::byte buffer.
*/
explicit mutable_shared_buffer(size_type sz) :
m_data{std::make_shared<byte_vec>(sz)} { }
/**
* @brief Construct by copying bytes from a @c std::span.
*
* The type of the span must be convertible to or be layout compatible with
* @c std::byte.
*
* @param sp @c std::span pointing to buffer of data. The @c std::span
* pointer is cast into a @c std::byte pointer and bytes are then copied.
*
*/
template <typename T, std::size_t Ext>
mutable_shared_buffer(std::span<const T, Ext> sp) :
mutable_shared_buffer(std::as_bytes(sp)) { }
/**
* @brief Construct by copying bytes from an arbitrary pointer.
*
* The pointer passed into this constructor is cast into a @c std::byte pointer and bytes
* are then copied. In particular, this method can be used for @c char pointers,
* @c void pointers, @c unsigned @c char pointers, etc.
*
* @pre Size cannot be greater than the source buffer.
*
* @param buf Non-null pointer to a buffer of data.
*
* @param sz Size of buffer, in bytes.
*/
template <typename T>
mutable_shared_buffer(const T* buf, size_type sz) :
mutable_shared_buffer(std::as_bytes(std::span<const T>{buf, sz})) { }
/**
* @brief Construct from input iterators.
*
* @pre Valid iterator range, where each element is convertible to a @c std::byte.
*
* @param beg Beginning input iterator of range.
* @param end Ending input iterator of range.
*
*/
template <typename InIt>
mutable_shared_buffer(InIt beg, InIt end) :
m_data(std::make_shared<byte_vec>(beg, end)) { }
/**
* @brief Return @c std::byte pointer to beginning of buffer.
*
* This method provides pointer access to the beginning of the buffer. If the
* buffer is empty the pointer cannot be dereferenced or undefined behavior will
* occur.
*
* Accessing past the end of the internal buffer (as defined by the @c size()
* method) results in undefined behavior.
*
* @return @c std::byte pointer to buffer.
*/
std::byte* data() noexcept { return m_data->data(); }
/**
* @brief Return @c const @c std::byte pointer to beginning of buffer.
*
* @c const method providing pointer access to the beginning of the buffer.
*
* @return @c const @c std::byte pointer to buffer.
*/
const std::byte* data() const noexcept { return m_data->data(); }
/**
* @brief Return size (number of bytes) of buffer.
*
* @return Size of buffer, which may be zero.
*/
size_type size() const noexcept { return m_data->size(); }
/**
* @brief Return access to underlying @c std::vector.
*
* This can be used to instantiate a @c dynamic_buffer as defined in the Networking TS
* or Asio API. Changing the @c std::vector from outside this class works because no
* state data is stored within this object that needs to be consistent with the
* @c std::vector contents.
*
* @return Reference to @c std::vector<std::byte>.
*/
byte_vec& get_byte_vec() noexcept { return *m_data; }
/**
* @brief Query to see if size is zero.
*
* @return @c true if empty (size equals zero).
*/
bool empty() const noexcept { return m_data->empty(); }
/**
* @brief Clear the internal contents back to an empty state.
*
* This method is handy after a @c mutable_shared_buffer has been moved into
* another object (e.g. a @c const_shared_buffer). At that point the contents
* are in a consistent but unknown state. Calling @c clear puts the internal
* buffer into a known and empty state.
*
*/
void clear() noexcept { m_data->clear(); }
/**
* @brief Resize internal buffer.
*
* @param sz New size for buffer. If the buffer is expanded, new bytes are added,
* each zero initialized. The size can also be contracted. @c resize does not
* destroy old data in the internal buffer, so @c clear may need to be called first.
*
* Resizing to zero results in an empty buffer, although calling @c clear is
* preferred.
*/
void resize(size_type sz) { m_data->resize(sz); }
/**
* @brief Swap with the contents of another @c mutable_shared_buffer object.
*/
void swap(mutable_shared_buffer& rhs) noexcept {
using std::swap; // swap idiom
swap(m_data, rhs.m_data);
}
/**
* @brief Append a @c std::byte buffer to the end of the internal buffer.
*
* @param buf Non-null pointer to @c std::byte buffer of data.
*
* @param sz Size of buffer.
*
* @return Reference to @c this (to allow method chaining).
*/
mutable_shared_buffer& append(const std::byte* buf, std::size_t sz) {
size_type old_sz = size();
resize(old_sz + sz); // set up buffer space
std::copy(buf, buf+sz, data()+old_sz);
return *this;
}
/**
* @brief Append a @c std::span to the end of the internal buffer.
*
* @param sp @c std::span of @c std::byte data.
*
* @return Reference to @c this (to allow method chaining).
*/
template <std::size_t Ext>
mutable_shared_buffer& append(std::span<const std::byte, Ext> sp) {
return append(sp.data(), sp.size());
}
/**
* @brief Append by copying bytes from an arbitrary pointer.
*
* The pointer passed into this method is cast into a @c std::byte pointer and bytes
* are then copied. In particular, this method can be used for @c char pointers,
* @c void pointers, @ unsigned @c char pointers, etc.
*
* @param buf Non-null pointer to a buffer of data.
*
* @param sz Size of buffer, in bytes.
*/
template <typename T>
mutable_shared_buffer& append(const T* buf, std::size_t sz) {
return append(std::as_bytes(std::span<const T>{buf, sz}));
}
/**
* @brief Append a @c std::span that is a non @c std::byte buffer.
*
* The @c std::span passed into this method is performs a cast on the
* data. In particular, this method can be used for @c char pointers,
* @c void pointers, @ unsigned @c char pointers, etc.
*
* The type of the span must be convertible to or be layout compatible with
* @c std::byte.
*
* @param sp @c std::span of arbitrary bytes.
*
*/
template <typename T, std::size_t Ext>
mutable_shared_buffer& append(std::span<const T, Ext> sp) {
return append(std::as_bytes(sp));
}
/**
* @brief Append the contents of another @c mutable_shared_buffer to the end.
*
* @param rhs @c mutable_shared_buffer to append from.
*
* @return Reference to @c this (to allow method chaining).
*/
mutable_shared_buffer& append(const mutable_shared_buffer& rhs) {
return append(rhs.data(), rhs.size());
}
/**
* @brief Append the contents of another @c mutable_shared_buffer to the end.
*
* See @c append method for details.
*/
mutable_shared_buffer& operator+=(const mutable_shared_buffer& rhs) {
return append(rhs);
}
/**
* @brief Append a single @c std::byte to the end.
*
* @param b Byte to append.
*
* @return Reference to @c this (to allow method chaining).
*/
mutable_shared_buffer& append(std::byte b) {
return append(&b, 1);
}
/**
* @brief Append a single @c std::byte to the end.
*
* See @c append method (single @c std::byte) for details.
*/
mutable_shared_buffer& operator+=(std::byte b) {
return append(b);
}
/**
* @brief Compare two @c mutable_shared_buffer objects for internal buffer
* byte-by-byte equality.
*
* Internally this invokes the @c std::vector @c operator== on @c std::byte
* elements.
*
* @return @c true if @c size() same for each, and each byte compares @c true.
*/
bool operator== (const mutable_shared_buffer& rhs) const noexcept {
return *m_data == *rhs.m_data;
}
/**
* @brief Compare two @c mutable_shared_buffer objects for internal buffer
* byte-by-byte spaceship operator ordering.
*
* Internally this invokes the @c std::vector @c <=> on @c std::byte
* elements.
*
* @return Spaceship operator comparison result.
*
*/
auto operator<=>(const mutable_shared_buffer& rhs) const noexcept {
return *m_data <=> *rhs.m_data;
}
}; // end mutable_shared_buffer class
// non-member functions
/**
* @brief Swap two @c mutable_shared_buffer objects.
*
*/
inline void swap(mutable_shared_buffer& lhs, mutable_shared_buffer& rhs) noexcept {
lhs.swap(rhs);
}
/**
* @brief A reference counted non-modifiable buffer class with various convenience methods,
* providing efficient copying and convenient buffer lifetime management.
*
* The primary difference between this class and the @c mutable_shared_buffer class is that
* once a @c const_shared_buffer object is constructed, nothing inside it can be modified. This
* allows it to be used with asynchronous IO functions which depend on the buffer staying the
* same (i.e. the internal pointer to the data and the size) for the full lifetime of the
* asynchronous operations.
*
* @invariant There will always be an internal buffer of data, even if the size is zero.
*
*/
class const_shared_buffer {
public:
using byte_vec = std::vector<std::byte>;
using size_type = typename byte_vec::size_type;
private:
std::shared_ptr<byte_vec> m_data;
private:
friend bool operator==(const mutable_shared_buffer&, const const_shared_buffer&) noexcept;
friend bool operator==(const const_shared_buffer&, const mutable_shared_buffer&) noexcept;
public:
const_shared_buffer() = delete;
// default copy and move construction, should do the right thing
const_shared_buffer(const const_shared_buffer&) = default;
const_shared_buffer(const_shared_buffer&&) = default;
// copy and move assignment disabled
const_shared_buffer& operator=(const const_shared_buffer&) = delete;
const_shared_buffer& operator=(const_shared_buffer&&) = delete;
/**
* @brief Construct by copying from a @c std::span of @c std::byte.
*
* @param sp @c std::byte span pointing to buffer of data. The data is
* copied into the internal buffer of the @c const_shared_buffer.
*
*/
template <std::size_t Ext>
explicit const_shared_buffer(std::span<const std::byte, Ext> sp) :
m_data(std::make_shared<byte_vec>(sp.data(), sp.data()+sp.size())) { }
/**
* @brief Construct by copying from a @c std::byte array.
*
* @pre Size cannot be greater than the source buffer.
*
* @param buf Non-null pointer to @c std::byte buffer of data. The data is
* copied into the internal buffer of the @c const_shared_buffer.
*
* @param sz Size of buffer.
*/
const_shared_buffer(const std::byte* buf, std::size_t sz) :
const_shared_buffer(std::as_bytes(std::span<const std::byte>{buf, sz})) { }
/**
* @brief Construct by copying from a @c std::span.
*
* The type of the span must be convertible to or be layout compatible with
* @c std::byte.
*
* @param sp @c std::span pointing to buffer of data. The @c std::span
* pointer is cast into a @c std::byte pointer and bytes are then copied.
*
*/
template <typename T, std::size_t Ext>
const_shared_buffer(std::span<const T, Ext> sp) :
const_shared_buffer(std::as_bytes(sp)) { }
/**
* @brief Construct by copying bytes from an arbitrary pointer.
*
* The pointer passed into this constructor is cast into a @c std::byte pointer and bytes
* are then copied. In particular, this method can be used for @c char pointers,
* @c void pointers, @c unsigned @c char pointers, etc.
*
* The type of the span must be convertible to or be layout compatible with
* @c std::byte.
*
* @pre Size cannot be greater than the source buffer.
*
* @param buf Non-null pointer to a buffer of data.
*
* @param sz Size of buffer, in bytes.
*/
template <typename T>
const_shared_buffer(const T* buf, std::size_t sz) :
const_shared_buffer(std::as_bytes(std::span<const T>{buf, sz})) { }
/**
* @brief Construct by copying from a @c mutable_shared_buffer object.
*
* This constructor will copy from a @c mutable_shared_buffer. There is an alternative
* constructor that is more efficient which moves from a @c mutable_shared_buffer
* instead of copying.
*
* @param rhs @c mutable_shared_buffer containing bytes to be copied.
*/
explicit const_shared_buffer(const mutable_shared_buffer& rhs) :
const_shared_buffer(rhs.data(), rhs.size()) { }
/**
* @brief Construct by moving from a @c mutable_shared_buffer object.
*
* This constructor will move from a @c mutable_shared_buffer into a @c const_shared_buffer.
* This allows efficient API boundaries, where application code can construct and fill in a
* @c mutable_shared_buffer, then @c std::move it into a @c const_shared_buffer for use
* with asynchronous functions.
*
* @param rhs @c mutable_shared_buffer to be moved from; after moving the
* @c mutable_shared_buffer will be empty.
*/
explicit const_shared_buffer(mutable_shared_buffer&& rhs) noexcept :
m_data(std::move(rhs.m_data)) {
rhs.m_data = std::make_shared<byte_vec>(0); // set rhs back to invariant
}
/**
* @brief Move construct from a @c std::vector of @c std::bytes.
*
* Efficiently construct from a @c std::vector of @c std::bytes by moving
* into a @c const_shared_buffer.
*
*/
explicit const_shared_buffer(byte_vec&& bv) noexcept :
m_data(std::make_shared<byte_vec>()) {
*m_data = std::move(bv);
}
/**
* @brief Construct from input iterators.
*
* @pre Valid iterator range, where each element is convertible to a @c std::byte.
*
* @param beg Beginning input iterator of range.
* @param end Ending input iterator of range.
*
*/
template <typename InIt>
const_shared_buffer(InIt beg, InIt end) : m_data(std::make_shared<byte_vec>(beg, end)) { }
/**
* @brief Return @c const @c std::byte pointer to beginning of buffer.
*
* This method provides pointer access to the beginning of the buffer. If the
* buffer is empty the pointer cannot be dereferenced or undefined behavior will
* occur.
*
* Accessing past the end of the internal buffer (as defined by the @c size()
* method) results in undefined behavior.
*
* @return @c const @c std::byte pointer to buffer.
*/
const std::byte* data() const noexcept { return m_data->data(); }
/**
* @brief Return size (number of bytes) of buffer.
*
* @return Size of buffer, which may be zero.
*/
size_type size() const noexcept { return m_data->size(); }
/**
* @brief Query to see if size is zero.
*
* @return @c true if empty (size equals zero).
*/
bool empty() const noexcept { return (*m_data).empty(); }
/**
* @brief Compare two @c const_shared_buffer objects for internal buffer
* byte-by-byte equality.
*
* Internally this invokes the @c std::vector @c operator== on @c std::byte
* elements.
*
* @return @c true if @c size() same for each, and each byte compares @c true.
*
*/
bool operator== (const const_shared_buffer& rhs) const noexcept {
return *m_data == *rhs.m_data;
}
/**
* @brief Compare two @c const_shared_buffer objects for internal buffer
* byte-by-byte spaceship operator ordering.
*
* Internally this invokes the @c std::vector @c <=> on @c std::byte
* elements.
*
* @return Spaceship operator comparison result.
*
*/
auto operator<=> (const const_shared_buffer& rhs) const noexcept {
return *m_data <=> *rhs.m_data;
}
}; // end const_shared_buffer class
// non-member functions
/**
* @brief Compare a @c const_shared_buffer object with a @c mutable_shared_buffer for
* internal buffer byte-by-byte equality.
*
* @return @c true if @c size() same for each, and each byte compares @c true.
*/
inline bool operator== (const const_shared_buffer& lhs, const mutable_shared_buffer& rhs) noexcept {
return *lhs.m_data == *rhs.m_data;
}
/**
* @brief Compare a @c mutable_shared_buffer object with a @c const_shared_buffer for
* internal buffer byte-by-byte equality.
*
* @return @c true if @c size() same for each, and each byte compares @c true.
*/
inline bool operator== (const mutable_shared_buffer& lhs, const const_shared_buffer& rhs) noexcept {
return *lhs.m_data == *rhs.m_data;
}
} // end namespace
#endif