diff --git a/docs/reference.rst b/docs/reference.rst index a314e24e..b3b8448b 100644 --- a/docs/reference.rst +++ b/docs/reference.rst @@ -10,4 +10,4 @@ Reference Documentation reference/sequence_access reference/adaptors reference/algorithms - reference/sources + reference/factories diff --git a/docs/reference/sources.rst b/docs/reference/factories.rst similarity index 69% rename from docs/reference/sources.rst rename to docs/reference/factories.rst index 77c67066..249bcf5b 100644 --- a/docs/reference/sources.rst +++ b/docs/reference/factories.rst @@ -1,38 +1,93 @@ -Sources -******* +Factories +********* .. namespace:: flux ``array_ptr`` ------------- -.. class:: template array_ptr +.. class:: template array_ptr : public inline_sequence_base> + + A type with "fat" pointer semantics, implemented as a ``(pointer, length)`` pair. It can be used across API boundaries as a "type erased" contiguous sequence. It is the Flux-native equivalent of :type:`std::span`. + + All :type:`array_ptr` s are trivially movable. If :var:`T` is ``const`` then :type:`array_ptr` is additionally trivially copyable, otherwise it is move-only. + + For the purposes of documentation below, the exposition-only concept :concept:`non_slicing_ptr_convertible` is defined as:: + + template + concept non_slicing_ptr_convertible = std::convertible_to; + :constructors: .. function:: array_ptr() = default; + Default initializes an empty :type:`array_ptr` + + :postconditions: + + :expr:`data() == nullptr` + + :expr:`size() == 0` + .. function:: template \ requires see_below \ - array_ptr::array_ptr(Seq& seq); + explicit array_ptr(Seq& seq); + + Constructs an :type:`array_ptr` from the contiguous sequence :var:`seq`. + + :postconditions: + + :expr:`data() == flux::data(seq)` + + :expr:`size() == flux::size(seq)` + + :requires: + + * :var:`Seq` is not a specialisation of :type:`array_ptr` + * :expr:`non_slicing_ptr_convertible>, T>` is ``true`` .. function:: template \ - requires see_below \ - array_ptr::array_ptr(array_ptr other); + requires (!std::same_as && non_slicing_ptr_convertible) \ + array_ptr(array_ptr const& other) noexcept; + + Implicit conversion constructor from a compatible :type:`array_ptr`. + + :postconditions: + + :expr:`data() == other.data()` + + :expr:`size() == other.size()` :friend functions: .. function:: friend auto operator==(array_ptr lhs, array_ptr rhs) -> bool; + Equivalent to:: + + lhs.data() == rhs.data() && lhs.size() == rhs.size() + + but ensures that the pointer comparison is always well defined. + + .. note:: + + :type:`array_ptr` has pointer semantics, and so equality comparison tests the addresses of the pointed-to objects. + + If you want to check whether the elements of two :type:`array_ptr` s compare equal, you can use :func:`flux::equal`. + ``empty`` --------- .. var:: template requires std::is_object_v contiguous_sequence auto empty; + A variable template that names a contiguous sequence of zero :var:`T` s. Any attempt to read from an :var:`empty` will result in a runtime error. + + :expr:`is_empty(empty)` is vacuously :texpr:`true`. + ``from_istream`` ---------------- @@ -40,6 +95,9 @@ Sources template \ auto from_istream(std::basic_istream& is) -> sequence auto; + Returns a single-pass, read-only sequence which yields successive :var:`T` s extracted from :var:`is` using :expr:`operator>>()`. The element type of the returned sequence is :expr:`T const&`. + + ``from_istreambuf`` ------------------- @@ -49,7 +107,13 @@ Sources .. function:: template \ - auto from_istream(std::basic_istream& is) -> sequence auto; + auto from_istreambuf(std::basic_istream& is) -> sequence auto; + + Returns a single-pass, read-only sequence which yields successive characters from the given streambuf using :func:`std::basic_streambuf::sgetc()`. Iteration is complete when the streambuf reaches EOF. + + The second overload is equivalent to:: + + from_streambuf(is.rdbuf()) ``from_range`` --------------