Commit Graph

24 Commits (6b3bf28d0d54fd377ed7c61b1e500d99685be5ec)

Author SHA1 Message Date
Vincent Coubard 913f219fc1 Span: Fix type used in is_convertible traits. 2018-08-29 19:42:46 +01:00
Vincent Coubard 9d1fd9983c Span: Fix documentation. 2018-08-24 17:51:58 +01:00
Amanda Butler bf08651d3a
Copy edit Span.h
Copy edit file, mostly for consistent capitalization, punctuation and tense.
2018-08-24 09:31:10 -05:00
Vincent Coubard af69e1fb8b Span: use static assert to kill copy construction from an incompatible span type.
Copy construction between Span of compatible type is allowed to fulfil the use
case Span<T> -> Span<const T>. This is achieved by a templated copy constructor
like constructor.

In p0122, the overload is discarded from the constructor set if the ElementType
of the Span in input is not convertible into the ElementType of the Span being
constructed.

To discard function overload, SFINAE has to be used which polutes the documentation
and make the code harder to read and maintain.

Unlike p0122, our Span class doesn't exposes (yet) functions with default argument
or functions that convert container in input into span the only overload with the
a single parameter that we exposes are:
- template<size_t N> Span(ElementType (&element)[N])
- Span(const Span& other): <- generated by the compiler.

For both of this functions we expect exact match and their resolution should not
interfere with the constructor that converts from another type of Span.

As a result it is possible to rely solely on C++ default resolution rules as we
won't hit cases were constructors convert from another type (std::array, std
container, span) and raise an error with a static assert if the element type
can't be converted.

If another copy - conversion - constructor is added then SFINAE has to be
reintroduced.
2018-08-24 11:10:17 +01:00
Vincent Coubard d5051a8ca7 Span: Allow copy construction from convertible span.
Addition of these overloads help when Span<const T> is constructed from Span<T>.
2018-08-23 18:41:53 +01:00
Vincent Coubard b7f074ef68 Span: Fix opening brace position. 2018-08-23 14:02:26 +01:00
Vincent Coubard 2a6c6d5985 Span: Use mbed way of writing types in documentation example. 2018-08-23 12:41:04 +01:00
Vincent Coubard 33ca10192d Span: Fix documentation. 2018-08-23 11:38:32 +01:00
Vincent Coubard 6b08320573 Span: Fix doxygen tags. 2018-08-23 09:02:28 +01:00
Vincent Coubard 4e7fa91b94 Span: amend documentation 2018-08-22 15:11:27 +01:00
Vincent Coubard 95fc284a83 Span: add boundary check in subscript operator for debug profile 2018-08-22 13:32:54 +01:00
Vincent Coubard f6dd5eaa31 Span: Fix static assert message in default constructor. 2018-08-22 13:31:26 +01:00
Vincent Coubard 26b546bab3 Span: Improve readability of precondition checks 2018-08-22 09:40:51 +01:00
Vincent Coubard 938d802ea0 Span: Fix subspan return type 2018-08-22 09:40:50 +01:00
Vincent Coubard 54e2d92c95 Span: Improve consistency with standard.
This commit aims to make Span implementation more in line with what is present in N4762:
- use appropiate index types where applicable.
- use typedefed type inside the class (index_type, reference, pointer, element_type)
- assertion where applicable
- restrict default construction to Span with extent == 0 or extent == dynamic.
- construct span from a range of pointer
- remove non const overload of the subscript operator
- remove non const overload of the data function
- implement subspan function
- implement missing first and last function of dynamic span
2018-08-21 18:20:58 +01:00
Vincent Coubard 3985fb8d62 Span: Fix documentation error. 2018-08-20 12:00:20 +01:00
Vincent Coubard 1f00336c7e Span: replace reference to Size with Extent. 2018-08-20 11:58:48 +01:00
Vincent Coubard 6fcf1e8284 Span: Make type pointer and reference declaration consistent with guideline. 2018-08-20 10:47:41 +01:00
Vincent Coubard 9b9d33a7b4 Span: Fix typo. 2018-08-20 10:41:47 +01:00
Vincent Coubard 3fb3173876 Span: Fix odd condition in Span::empty. 2018-08-20 10:30:35 +01:00
Vincent Coubard 43170d21bf Span: Make name of dynamic span tag consistent with C++ standard. 2018-08-20 10:29:43 +01:00
Vincent Coubard eba1dc6dd6 Span: Improve comparison operator to array by using fixed size Span. 2018-08-20 09:13:31 +01:00
Vincent Coubard 7f195b8ec1 Span: Cleanup usage of ptrdiff_t and size_t 2018-08-20 09:13:17 +01:00
Vincent Coubard d8c788a413 Platform: Add C++ Span class.
The Span class allows the creation of views over contiguous memory. The view
do not own memory, is typed and has a length. It can be used as a replacement of
the traditional pair of pointer and size in parameters or class fields.

Main operations:
- size(): return the lenght of the memory viewed
- empty(): return if the memory viewed is empty
- [index]: access elements viewed
- data(): return a pointer to the memory viewed.
- first(count): Create a subview from the first count elements.
- last(count): Create a subview from the last count elements.
- == and !=: compare two views or a view to array and return if they are equal or
not.

The Span class came in two flavors:
- Static size: The size is encoded in the Span type and it is as lightweitgh as
a single pointer,
- Dynamic size: The object can store arbitrary views and it costs one pointer
and the size of the view.
2018-08-19 20:20:05 +01:00