Skip to content

Span doc #8504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 24, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions platform/Span.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@

namespace mbed {

/** \addtogroup platform */
/** @{*/
/**
* \defgroup platform_Span Span class
* @{
*/

// Internal details of Span
// It is used construct Span from Span of convertible types (non const -> const)
namespace span_detail {
Expand All @@ -47,12 +54,18 @@ class is_convertible

}

#if defined(DOXYGEN_ONLY)
/**
* Special value for the Extent parameter of Span.
* If the type uses this value, then the size of the array is stored in the object
* at runtime.
*
* @relates Span
*/
const ptrdiff_t SPAN_DYNAMIC_EXTENT = -1;
#else
#define SPAN_DYNAMIC_EXTENT -1
#endif

/**
* Nonowning view to a sequence of contiguous elements.
Expand Down Expand Up @@ -691,15 +704,15 @@ struct Span<ElementType, SPAN_DYNAMIC_EXTENT> {
* @return A subspan of this starting at Offset and Count long.
*/
template<std::ptrdiff_t Offset, std::ptrdiff_t Count>
Span<element_type, Count == SPAN_DYNAMIC_EXTENT ? SPAN_DYNAMIC_EXTENT : Count>
Span<element_type, Count>
subspan() const
{
MBED_ASSERT(0 <= Offset && Offset <= _size);
MBED_ASSERT(
(Count == SPAN_DYNAMIC_EXTENT) ||
(0 <= Count && (Count + Offset) <= _size)
);
return Span<element_type, Count == SPAN_DYNAMIC_EXTENT ? SPAN_DYNAMIC_EXTENT : Count>(
return Span<element_type, Count>(
_data + Offset,
Count == SPAN_DYNAMIC_EXTENT ? _size - Offset : Count
);
Expand Down Expand Up @@ -774,6 +787,8 @@ struct Span<ElementType, SPAN_DYNAMIC_EXTENT> {
*
* @return True if Spans in input have the same size and the same content and
* false otherwise.
*
* @relates Span
*/
template<typename T, typename U, ptrdiff_t LhsExtent, ptrdiff_t RhsExtent>
bool operator==(const Span<T, LhsExtent> &lhs, const Span<U, RhsExtent> &rhs)
Expand Down Expand Up @@ -827,6 +842,8 @@ bool operator==(T (&lhs)[LhsExtent], const Span<T, RhsExtent> &rhs)
*
* @return True if arrays in input do not have the same size or the same content
* and false otherwise.
*
* @relates Span
*/
template<typename T, typename U, ptrdiff_t LhsExtent, ptrdiff_t RhsExtent>
bool operator!=(const Span<T, LhsExtent> &lhs, const Span<U, RhsExtent> &rhs)
Expand Down Expand Up @@ -876,6 +893,8 @@ bool operator!=(T (&lhs)[LhsExtent], const Span<T, RhsExtent> &rhs)
*
* @note This helper avoids the typing of template parameter when Span is
* created 'inline'.
*
* @relates Span
*/
template<typename T, size_t Size>
Span<T, Size> make_Span(T (&elements)[Size])
Expand Down Expand Up @@ -914,6 +933,8 @@ Span<T, Extent> make_Span(T *elements)
*
* @note This helper avoids the typing of template parameter when Span is
* created 'inline'.
*
* @relates Span
*/
template<typename T>
Span<T> make_Span(T *array_ptr, ptrdiff_t array_size)
Expand Down Expand Up @@ -951,6 +972,8 @@ Span<const T, Extent> make_const_Span(const T (&elements)[Extent])
*
* @note This helper avoids the typing of template parameter when Span is
* created 'inline'.
*
* @relates Span
*/
template<size_t Extent, typename T>
Span<const T, Extent> make_const_Span(const T *elements)
Expand All @@ -971,13 +994,19 @@ Span<const T, Extent> make_const_Span(const T *elements)
*
* @note This helper avoids the typing of template parameter when Span is
* created 'inline'.
*
* @relates Span
*/
template<typename T>
Span<const T> make_const_Span(T *array_ptr, size_t array_size)
{
return Span<const T>(array_ptr, array_size);
}

/**@}*/

/**@}*/

} // namespace mbed

#endif /* MBED_PLATFORM_SPAN_H_ */