Skip to content

Commit 1f00336

Browse files
committed
Span: replace reference to Size with Extent.
1 parent 6fcf1e8 commit 1f00336

File tree

1 file changed

+47
-49
lines changed

1 file changed

+47
-49
lines changed

platform/Span.h

Lines changed: 47 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
namespace mbed {
2727

2828
/**
29-
* Special value for the Size parameter of Span.
29+
* Special value for the Extent parameter of Span.
3030
* If the type use this value then the size of the array is stored in the object
3131
* at runtime.
3232
*/
@@ -47,18 +47,18 @@ namespace mbed {
4747
* @note You can create Span instances with the help of the function
4848
* template make_Span() and make_const_Span().
4949
*
50-
* @note Span<T, Size> objects can be implicitly converted to Span<T> objects
50+
* @note Span<T, Extent> objects can be implicitly converted to Span<T> objects
5151
* where required.
5252
*
5353
* @tparam T type of objects held by the array.
54-
* @tparam Size The size of the array viewed. The default value
54+
* @tparam Extent The size of the array viewed. The default value
5555
* SPAN_DYNAMIC_SIZE is special as it allows construction of Span objects of
5656
* any size (set at runtime).
5757
*/
58-
template<typename T, ptrdiff_t Size = SPAN_DYNAMIC_EXTENT>
58+
template<typename T, ptrdiff_t Extent = SPAN_DYNAMIC_EXTENT>
5959
struct Span {
6060

61-
MBED_STATIC_ASSERT(Size >= 0, "Invalid size for a Span");
61+
MBED_STATIC_ASSERT(Extent >= 0, "Invalid extent for a Span");
6262

6363
/**
6464
* Construct a view to an empty array.
@@ -78,20 +78,18 @@ struct Span {
7878
*/
7979
Span(T *array_ptr, size_t array_size) :
8080
_array(array_ptr) {
81-
MBED_ASSERT(array_size >= (size_t) Size);
81+
MBED_ASSERT(array_size >= (size_t) Extent);
8282
}
8383

8484
/**
8585
* Construct a Span from the reference to an array.
8686
*
8787
* @param elements Reference to the array viewed.
8888
*
89-
* @tparam Size Number of elements of T presents in the array.
90-
*
91-
* @post a call to size() will return Size, and data() will return
89+
* @post a call to size() will return Extent, and data() will return
9290
* a pointer to elements.
9391
*/
94-
Span(T (&elements)[Size]):
92+
Span(T (&elements)[Extent]):
9593
_array(elements) { }
9694

9795
/**
@@ -101,7 +99,7 @@ struct Span {
10199
*/
102100
size_t size() const
103101
{
104-
return _array ? Size : 0;
102+
return _array ? Extent : 0;
105103
}
106104

107105
/**
@@ -170,7 +168,7 @@ struct Span {
170168
* @return A new Span over the first @p count elements.
171169
*/
172170
Span<T> first(std::size_t count) const {
173-
MBED_ASSERT(count <= Size);
171+
MBED_ASSERT(count <= Extent);
174172
return Span<T>(_array, count);
175173
}
176174

@@ -183,7 +181,7 @@ struct Span {
183181
*/
184182
template<std::ptrdiff_t Count>
185183
Span<T, Count> first() const {
186-
MBED_ASSERT(Count <= Size);
184+
MBED_ASSERT(Count <= Extent);
187185
return Span<T, Count>(_array);
188186
}
189187

@@ -195,8 +193,8 @@ struct Span {
195193
* @return A new Span over the last @p count elements.
196194
*/
197195
Span<T> last(std::size_t count) const {
198-
MBED_ASSERT(count <= Size);
199-
return Span<T>(_array + (Size - count), count);
196+
MBED_ASSERT(count <= Extent);
197+
return Span<T>(_array + (Extent - count), count);
200198
}
201199

202200
/**
@@ -208,8 +206,8 @@ struct Span {
208206
*/
209207
template<std::ptrdiff_t Count>
210208
Span<T, Count> last() const {
211-
MBED_ASSERT(Count <= Size);
212-
return Span<T, Count>(_array + (Size - Count));
209+
MBED_ASSERT(Count <= Extent);
210+
return Span<T, Count>(_array + (Extent - Count));
213211
}
214212

215213
private:
@@ -261,8 +259,8 @@ struct Span<T, SPAN_DYNAMIC_EXTENT> {
261259
* static size.
262260
* @param other The Span object used to construct this.
263261
*/
264-
template<size_t Size>
265-
Span(const Span<T, Size> &other):
262+
template<size_t Extent>
263+
Span(const Span<T, Extent> &other):
266264
_array(other.data()), _size(other.size()) { }
267265

268266
/**
@@ -370,8 +368,8 @@ struct Span<T, SPAN_DYNAMIC_EXTENT> {
370368
* @return True if arrays in input have the same size and the same content
371369
* and false otherwise.
372370
*/
373-
template<typename T, typename U, ptrdiff_t LhsSize, ptrdiff_t RhsSize>
374-
bool operator==(const Span<T, LhsSize> &lhs, const Span<U, RhsSize> &rhs)
371+
template<typename T, typename U, ptrdiff_t LhsExtent, ptrdiff_t RhsExtent>
372+
bool operator==(const Span<T, LhsExtent> &lhs, const Span<U, RhsExtent> &rhs)
375373
{
376374
if (lhs.size() != rhs.size()) {
377375
return false;
@@ -393,8 +391,8 @@ bool operator==(const Span<T, LhsSize> &lhs, const Span<U, RhsSize> &rhs)
393391
* @return True if arrays in input have the same size and the same content
394392
* and false otherwise.
395393
*/
396-
template<typename T, ptrdiff_t LhsSize, ptrdiff_t RhsSize>
397-
bool operator==(const Span<T, LhsSize> &lhs, T (&rhs)[RhsSize])
394+
template<typename T, ptrdiff_t LhsExtent, ptrdiff_t RhsExtent>
395+
bool operator==(const Span<T, LhsExtent> &lhs, T (&rhs)[RhsExtent])
398396
{
399397
return lhs == Span<T>(rhs);
400398
}
@@ -408,8 +406,8 @@ bool operator==(const Span<T, LhsSize> &lhs, T (&rhs)[RhsSize])
408406
* @return True if arrays in input have the same size and the same content
409407
* and false otherwise.
410408
*/
411-
template<typename T, ptrdiff_t LhsSize, ptrdiff_t RhsSize>
412-
bool operator==(T (&lhs)[LhsSize], const Span<T, RhsSize> &rhs)
409+
template<typename T, ptrdiff_t LhsExtent, ptrdiff_t RhsExtent>
410+
bool operator==(T (&lhs)[LhsExtent], const Span<T, RhsExtent> &rhs)
413411
{
414412
return Span<T>(lhs) == rhs;
415413
}
@@ -423,8 +421,8 @@ bool operator==(T (&lhs)[LhsSize], const Span<T, RhsSize> &rhs)
423421
* @return True if arrays in input do not have the same size or the same
424422
* content and false otherwise.
425423
*/
426-
template<typename T, typename U, ptrdiff_t LhsSize, ptrdiff_t RhsSize>
427-
bool operator!=(const Span<T, LhsSize> &lhs, const Span<U, RhsSize> &rhs)
424+
template<typename T, typename U, ptrdiff_t LhsExtent, ptrdiff_t RhsExtent>
425+
bool operator!=(const Span<T, LhsExtent> &lhs, const Span<U, RhsExtent> &rhs)
428426
{
429427
return !(lhs == rhs);
430428
}
@@ -438,10 +436,10 @@ bool operator!=(const Span<T, LhsSize> &lhs, const Span<U, RhsSize> &rhs)
438436
* @return True if arrays in input have the same size and the same content
439437
* and false otherwise.
440438
*/
441-
template<typename T, ptrdiff_t LhsSize, ptrdiff_t RhsSize>
442-
bool operator!=(const Span<T, LhsSize> &lhs, T (&rhs)[RhsSize])
439+
template<typename T, ptrdiff_t LhsExtent, ptrdiff_t RhsExtent>
440+
bool operator!=(const Span<T, LhsExtent> &lhs, T (&rhs)[RhsExtent])
443441
{
444-
return !(lhs == Span<T, RhsSize>(rhs));
442+
return !(lhs == Span<T, RhsExtent>(rhs));
445443
}
446444

447445
/**
@@ -453,17 +451,17 @@ bool operator!=(const Span<T, LhsSize> &lhs, T (&rhs)[RhsSize])
453451
* @return True if arrays in input have the same size and the same content
454452
* and false otherwise.
455453
*/
456-
template<typename T, ptrdiff_t LhsSize, ptrdiff_t RhsSize>
457-
bool operator!=(T (&lhs)[LhsSize], const Span<T, RhsSize> &rhs)
454+
template<typename T, ptrdiff_t LhsExtent, ptrdiff_t RhsExtent>
455+
bool operator!=(T (&lhs)[LhsExtent], const Span<T, RhsExtent> &rhs)
458456
{
459-
return !(Span<T, LhsSize>(lhs) == rhs);
457+
return !(Span<T, LhsExtent>(lhs) == rhs);
460458
}
461459

462460
/**
463461
* Generate a Span from a reference to a C/C++ array.
464462
*
465463
* @tparam T Type of elements held in elements.
466-
* @tparam Size Number of items held in elements.
464+
* @tparam Extent Number of items held in elements.
467465
*
468466
* @param elements The reference to the array viewed.
469467
*
@@ -472,16 +470,16 @@ bool operator!=(T (&lhs)[LhsSize], const Span<T, RhsSize> &rhs)
472470
* @note This helper avoids the typing of template parameter when Span is
473471
* created 'inline'.
474472
*/
475-
template<typename T, size_t Size>
476-
Span<T, Size> make_Span(T (&elements)[Size])
473+
template<typename T, size_t Extent>
474+
Span<T, Extent> make_Span(T (&elements)[Extent])
477475
{
478-
return Span<T, Size>(elements);
476+
return Span<T, Extent>(elements);
479477
}
480478

481479
/**
482480
* Generate a Span from a pointer to a C/C++ array.
483481
*
484-
* @tparam Size Number of items held in elements.
482+
* @tparam Extent Number of items held in elements.
485483
* @tparam T Type of elements held in elements.
486484
*
487485
* @param elements The reference to the array viewed.
@@ -491,10 +489,10 @@ Span<T, Size> make_Span(T (&elements)[Size])
491489
* @note This helper avoids the typing of template parameter when Span is
492490
* created 'inline'.
493491
*/
494-
template<size_t Size, typename T>
495-
Span<T, Size> make_Span(T *elements)
492+
template<size_t Extent, typename T>
493+
Span<T, Extent> make_Span(T *elements)
496494
{
497-
return Span<T, Size>(elements, Size);
495+
return Span<T, Extent>(elements, Extent);
498496
}
499497

500498
/**
@@ -520,24 +518,24 @@ Span<T> make_Span(T *array_ptr, size_t array_size)
520518
* Generate a Span to a const content from a reference to a C/C++ array.
521519
*
522520
* @tparam T Type of elements held in elements.
523-
* @tparam Size Number of items held in elements.
521+
* @tparam Extent Number of items held in elements.
524522
*
525523
* @param elements The array viewed.
526524
* @return The Span to elements.
527525
*
528526
* @note This helper avoids the typing of template parameter when Span is
529527
* created 'inline'.
530528
*/
531-
template<typename T, size_t Size>
532-
Span<const T, Size> make_const_Span(const T (&elements)[Size])
529+
template<typename T, size_t Extent>
530+
Span<const T, Extent> make_const_Span(const T (&elements)[Extent])
533531
{
534-
return Span<const T, Size>(elements);
532+
return Span<const T, Extent>(elements);
535533
}
536534

537535
/**
538536
* Generate a Span to a const content from a pointer to a C/C++ array.
539537
*
540-
* @tparam Size Number of items held in elements.
538+
* @tparam Extent Number of items held in elements.
541539
* @tparam T Type of elements held in elements.
542540
*
543541
* @param elements The reference to the array viewed.
@@ -547,10 +545,10 @@ Span<const T, Size> make_const_Span(const T (&elements)[Size])
547545
* @note This helper avoids the typing of template parameter when Span is
548546
* created 'inline'.
549547
*/
550-
template<size_t Size, typename T>
551-
Span<const T, Size> make_const_Span(const T *elements)
548+
template<size_t Extent, typename T>
549+
Span<const T, Extent> make_const_Span(const T *elements)
552550
{
553-
return Span<const T, Size>(elements, Size);
551+
return Span<const T, Extent>(elements, Extent);
554552
}
555553

556554
/**

0 commit comments

Comments
 (0)