| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent cac94b9 commit d51bb5f
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -154,9 +154,27 @@ class mutable_shared_buffer { | |||
| 154 | 154 | * copied into the internal buffer of the @c mutable_shared_buffer. | |
| 155 | 155 | * | |
| 156 | 156 | */ | |
| 157 | - explicit mutable_shared_buffer(std::span<const std::byte> sp) : | ||
| 157 | + template <std::size_t Ext> | ||
| 158 | + explicit mutable_shared_buffer(std::span<const std::byte, Ext> sp) : | ||
| 158 | 159 | m_data{std::make_shared<byte_vec>(sp.data(), sp.data()+sp.size())} { } | |
| 159 | 160 | ||
| 161 | + /** | ||
| 162 | + * @brief Construct by copying from a @c std::byte array. | ||
| 163 | + * | ||
| 164 | + * A @c std::span is first created, then the constructor taking | ||
| 165 | + * a @c std::span is called. | ||
| 166 | + * | ||
| 167 | + * @pre Size cannot be greater than the source buffer. | ||
| 168 | + * | ||
| 169 | + * @param buf Non-null pointer to a @c std::byte buffer of data. The | ||
| 170 | + * data is copied into the internal buffer of the @c mutable_shared_buffer. | ||
| 171 | + * | ||
| 172 | + * @param sz Size of buffer. | ||
| 173 | + * | ||
| 174 | + */ | ||
| 175 | + mutable_shared_buffer(const std::byte* buf, size_type sz) : | ||
| 176 | + mutable_shared_buffer(std::span<const std::byte>(buf, sz)) { } | ||
| 177 | + | ||
| 160 | 178 | /** | |
| 161 | 179 | * @brief Move construct from a @c std::vector of @c std::bytes. | |
| 162 | 180 | * | |
@@ -174,7 +192,7 @@ class mutable_shared_buffer { | |||
| 174 | 192 | ||
| 175 | 193 | /** | |
| 176 | 194 | * @brief Construct a @c mutable_shared_buffer with an initial size, contents | |
| 177 | - * set to zero. | ||
| 195 | + * of each byte set to zero. | ||
| 178 | 196 | * | |
| 179 | 197 | * Allocate zero initialized space which can be overwritten with data as needed. | |
| 180 | 198 | * The @c data method is called to get access to the underlying @c std::byte | |
@@ -186,35 +204,18 @@ class mutable_shared_buffer { | |||
| 186 | 204 | m_data{std::make_shared<byte_vec>(sz)} { } | |
| 187 | 205 | ||
| 188 | 206 | ||
| 189 | - /** | ||
| 190 | - * @brief Construct by copying from a @c std::byte array. | ||
| 191 | - * | ||
| 192 | - * A @c std::span is first created, then the constructor taking | ||
| 193 | - * a @c std::span is called. | ||
| 194 | - * | ||
| 195 | - * @pre Size cannot be greater than the source buffer. | ||
| 196 | - * | ||
| 197 | - * @param buf Non-null pointer to a @c std::byte buffer of data. The | ||
| 198 | - * data is copied into the internal buffer of the @c mutable_shared_buffer. | ||
| 199 | - * | ||
| 200 | - * @param sz Size of buffer. | ||
| 201 | - * | ||
| 202 | - */ | ||
| 203 | - mutable_shared_buffer(const std::byte* buf, size_type sz) : | ||
| 204 | - mutable_shared_buffer(std::span<const std::byte>(buf, sz)) { } | ||
| 205 | - | ||
| 206 | 207 | /** | |
| 207 | 208 | * @brief Construct by copying bytes from a @c std::span. | |
| 208 | 209 | * | |
| 209 | - * The type of the span must be convertible to or layout compatible with | ||
| 210 | + * The type of the span must be convertible to or be layout compatible with | ||
| 210 | 211 | * @c std::byte. | |
| 211 | 212 | * | |
| 212 | 213 | * @param sp @c std::span pointing to buffer of data. The @c std::span | |
| 213 | 214 | * pointer is cast into a @c std::byte pointer and bytes are then copied. | |
| 214 | 215 | * | |
| 215 | 216 | */ | |
| 216 | - template <typename T> | ||
| 217 | - mutable_shared_buffer(std::span<const T> sp) : | ||
| 217 | + template <typename T, std::size_t Ext> | ||
| 218 | + mutable_shared_buffer(std::span<const T, Ext> sp) : | ||
| 218 | 219 | mutable_shared_buffer(std::bit_cast<const std::byte *>(sp.data()), sp.size()) { } | |
| 219 | 220 | ||
| 220 | 221 | /** | |
@@ -350,7 +351,8 @@ class mutable_shared_buffer { | |||
| 350 | 351 | * | |
| 351 | 352 | * @return Reference to @c this (to allow method chaining). | |
| 352 | 353 | */ | |
| 353 | - mutable_shared_buffer& append(std::span<const std::byte> sp) { | ||
| 354 | + template <std::size_t Ext> | ||
| 355 | + mutable_shared_buffer& append(std::span<const std::byte, Ext> sp) { | ||
| 354 | 356 | return append(sp.data(), sp.size()); | |
| 355 | 357 | } | |
| 356 | 358 | ||
@@ -377,14 +379,14 @@ class mutable_shared_buffer { | |||
| 377 | 379 | * data. In particular, this method can be used for @c char pointers, | |
| 378 | 380 | * @c void pointers, @ unsigned @c char pointers, etc. | |
| 379 | 381 | * | |
| 380 | - * The type of the span must be convertible to or layout compatible with | ||
| 382 | + * The type of the span must be convertible to or be layout compatible with | ||
| 381 | 383 | * @c std::byte. | |
| 382 | 384 | * | |
| 383 | 385 | * @param sp @c std::span of arbitrary bytes. | |
| 384 | 386 | * | |
| 385 | 387 | */ | |
| 386 | - template <typename T> | ||
| 387 | - mutable_shared_buffer& append(std::span<const T> sp) { | ||
| 388 | + template <typename T, std::size_t Ext> | ||
| 389 | + mutable_shared_buffer& append(std::span<const T, Ext> sp) { | ||
| 388 | 390 | return append(std::bit_cast<const std::byte *>(sp.data()), sp.size()); | |
| 389 | 391 | } | |
| 390 | 392 | ||
@@ -513,7 +515,8 @@ class const_shared_buffer { | |||
| 513 | 515 | * copied into the internal buffer of the @c const_shared_buffer. | |
| 514 | 516 | * | |
| 515 | 517 | */ | |
| 516 | - explicit const_shared_buffer(std::span<const std::byte> sp) : | ||
| 518 | + template <std::size_t Ext> | ||
| 519 | + explicit const_shared_buffer(std::span<const std::byte, Ext> sp) : | ||
| 517 | 520 | m_data(std::make_shared<byte_vec>(sp.data(), sp.data()+sp.size())) { } | |
| 518 | 521 | /** | |
| 519 | 522 | * @brief Construct by copying from a @c std::byte array. | |
@@ -526,7 +529,7 @@ class const_shared_buffer { | |||
| 526 | 529 | * @param sz Size of buffer. | |
| 527 | 530 | */ | |
| 528 | 531 | const_shared_buffer(const std::byte* buf, size_type sz) : | |
| 529 | - const_shared_buffer(std::span<const std::byte>(buf, sz)) { } | ||
| 532 | + const_shared_buffer(std::span<const std::byte>{buf, buf+sz}) { } | ||
| 530 | 533 | ||
| 531 | 534 | /** | |
| 532 | 535 | * @brief Construct by copying bytes from an arbitrary pointer. | |
@@ -535,7 +538,7 @@ class const_shared_buffer { | |||
| 535 | 538 | * are then copied. In particular, this method can be used for @c char pointers, | |
| 536 | 539 | * @c void pointers, @c unsigned @c char pointers, etc. | |
| 537 | 540 | * | |
| 538 | - * The type of the span must be convertible to or layout compatible with | ||
| 541 | + * The type of the span must be convertible to or be layout compatible with | ||
| 539 | 542 | * @c std::byte. | |
| 540 | 543 | * | |
| 541 | 544 | * @pre Size cannot be greater than the source buffer. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -46,10 +46,12 @@ void generic_pointer_append_test() { | |||
| 46 | 46 | auto sb { generic_pointer_construction_test<chops::mutable_shared_buffer, PT>() }; | |
| 47 | 47 | auto sav_sz { sb.size() }; | |
| 48 | 48 | const PT arr[] { 5, 6, 7 }; | |
| 49 | - sb.append (arr, 3); | ||
| 49 | + const PT* ptr_arr { arr }; | ||
| 50 | + sb.append (ptr_arr, 3); | ||
| 50 | 51 | REQUIRE (sb.size() == (sav_sz + 3)); | |
| 51 | - // sb.append (std::span<PT>(arr, 3)); | ||
| 52 | - // REQUIRE (sb.size() == (sav_sz + 6)); | ||
| 52 | + std::span<const PT> sp { arr }; | ||
| 53 | + sb.append (sp); | ||
| 54 | + REQUIRE (sb.size() == (sav_sz + 6)); | ||
| 53 | 55 | } | |
| 54 | 56 | ||
| 55 | 57 | template <typename SB> | |
| Back | FazBrowse Home | New Git URL |
0 commit comments