encode_view

The encode_view class provides a one-by-one view of the stored range’s code points as the desired encoding’s code units. Dereferencing the iterators returns a single code_unit value corresponding to the desired encoding’s transformation of the internal code points.

The range-based classes are excellent ways to walk over units of information in a low-memory environment, as they only store the minimum amount of data necessary to perform their operations on the fly. This reduces the speed but is fine for one-at-a-time encoding operations. To encode eagerly and in bulk, see the encode functions.

template<typename _Encoding, typename _Range = __txt_detail::__default_char_view_t<code_point_t<_Encoding>>, typename _ErrorHandler = default_handler_t, typename _State = encode_state_t<_Encoding>>
class encode_view : public view_base

A view over a range of code points, presenting the code points as code units. Uses the _Encoding specified to do so.

Remark

The view presents code units one at a time, regardless of how many code units are output by one decode operation. This means if, for example, one (1) UTF-32 code point becomes four (4) UTF-8 code units, it will present each code unit one at a time. If you are looking to explicitly know what a single encode operation maps into as far as number of code points to code units (and vice-versa), you will have to use lower-level interfaces.

Template Parameters:
  • _Encoding – The encoding to read the underlying range of code points as.

  • _Range – The range of input that will be fed into the _FromEncoding’s decode operation.

  • _ErrorHandler – The error handler for any encode-step failures.

  • _State – The state type to use for the encode operations to intermediate code points.

Public Types

using iterator = encode_iterator<_Encoding, _StoredRange, _ErrorHandler, _State>

The iterator type for this view.

using sentinel = encode_sentinel_t

The sentinel type for this view.

using range_type = _Range

The underlying range type.

using encoding_type = _Encoding

The encoding type used for transformations.

using error_handler_type = _ErrorHandler

The error handler when an encode operation fails.

using state_type = encode_state_t<encoding_type>

The state type used for encode operations.

Public Functions

constexpr encode_view() = default

Default constructor. Defaulted.

constexpr encode_view(const encode_view&) = default

Copy constructor. Defaulted.

constexpr encode_view(encode_view&&) = default

Move constructor. Defaulted.

template<typename _ArgRange, ::std::enable_if_t<!::std::is_same_v<remove_cvref_t<_ArgRange>, encode_view> && !::std::is_same_v<remove_cvref_t<_ArgRange>, iterator>>* = nullptr>
inline constexpr encode_view(_ArgRange &&__range) noexcept(::std::is_nothrow_constructible_v<iterator, _ArgRange>)

Constructs an encode_view from the underlying range.

Remark

the stored encoding, error handler, and state type are default-constructed.

Parameters:

__range – [in] The input range to wrap and iterate over.

inline constexpr encode_view(range_type __range, encoding_type __encoding) noexcept(::std::is_nothrow_constructible_v<iterator, range_type, encoding_type>)

Constructs an encode_view from the underlying range.

Parameters:
  • __range – [in] The input range to wrap and iterate over.

  • __encoding – [in] The encoding object to call .encode or equivalent functionality on.

inline constexpr encode_view(range_type __range, encoding_type __encoding, error_handler_type __error_handler) noexcept(::std::is_nothrow_constructible_v<iterator, range_type, encoding_type, error_handler_type>)

Constructs an encode_view from the underlying range.

Parameters:
  • __range – [in] The input range to wrap and iterate over.

  • __encoding – [in] The encoding object to call .encode or equivalent functionality on.

  • __error_handler – [in] A previously-made encode_view iterator.

inline constexpr encode_view(range_type __range, encoding_type __encoding, error_handler_type __error_handler, state_type __state) noexcept(::std::is_nothrow_constructible_v<iterator, range_type, encoding_type, error_handler_type, state_type>)

Constructs an encode_view from the underlying range.

Parameters:
  • __range – [in] The input range to wrap and iterate over.

  • __encoding – [in] The encoding object to call .encode or equivalent functionality on.

  • __error_handler – [in] A previously-made encode_view iterator.

  • __state – [in] The state to user for the encode operation.

inline constexpr encode_view(iterator __it) noexcept(::std::is_nothrow_move_constructible_v<iterator>)

Constructs an encoding_view from one of its iterators, reconstituting the range.

Parameters:

__it – [in] A previously-made encode_view iterator.

constexpr encode_view &operator=(const encode_view&) = default

Copy assignment operator. Defaulted.

constexpr encode_view &operator=(encode_view&&) = default

Move assignment operator. Defaulted.

inline constexpr iterator begin() & noexcept

The beginning of the range.

inline constexpr iterator begin() const & noexcept

The beginning of the range.

inline constexpr iterator begin() && noexcept

The beginning of the range.

inline constexpr sentinel end() const noexcept

The end of the range. Uses a sentinel type and not a special iterator.

template<typename _Encoding, typename _Range, typename _ErrorHandler = default_handler_t, typename _State = encode_state_t<_Encoding>>
class encode_iterator : public __txt_detail::__encoding_iterator<__txt_detail::__transaction::__encode, encode_iterator<_Encoding, _Range, default_handler_t, encode_state_t<_Encoding>>, __txt_detail::__iterator_storage<_Encoding, _Range, default_handler_t, encode_state_t<_Encoding>>>

An iterator over an iterator of code points, presenting the code points as code units. Uses the _Encoding specified to do so.

Remark

This type produces proxies as their reference type, and are only readable, not writable iterators. The iterator presents code units one at a time, regardless of how many code units are output by one decode operation. This means if, for example, one (1) UTF-32 code point becomes four (4) UTF-8 code units, it will present each code unit one at a time. If you are looking to explicitly know what a single encode operation maps into as far as number of code points to code units (and vice-versa), you will have to use lower-level interfaces.

Template Parameters:
  • _Encoding – The encoding to read the underlying range of code points as.

  • _Range – The range of input that will be fed into the _FromEncoding’s decode operation.

  • _ErrorHandler – The error handler for any encode-step failures.

  • _State – The state type to use for the encode operations to intermediate code points.

Public Types

using range_type = typename __iterator_base_it::range_type

The underlying range type.

using iterator = typename __iterator_base_it::iterator

The base iterator type.

using encoding_type = typename __iterator_base_it::encoding_type

The encoding type used for transformations.

using error_handler_type = typename __iterator_base_it::error_handler_type

The error handler when an encode operation fails.

using state_type = typename __iterator_base_it::state_type

The state type used for encode operations.

using iterator_category = typename __iterator_base_it::iterator_category

The strength of the iterator category, as defined in relation to the base.

using iterator_concept = typename __iterator_base_it::iterator_concept

The strength of the iterator concept, as defined in relation to the base.

using value_type = typename __iterator_base_it::value_type

The object type that gets output on every dereference.

using pointer = typename __iterator_base_it::pointer

A pointer type to the value_type.

using reference = typename __iterator_base_it::value_type

The value returned from derefencing the iterator.

Remark

This is a proxy iterator, so the reference is a non-reference value_type.

using difference_type = typename __iterator_base_it::difference_type

The type returned when two of these pointers are subtracted from one another.

Remark

It’s not a very useful type…

Public Functions

constexpr encode_iterator() = default

Default constructor. Defaulted.

constexpr encode_iterator(const encode_iterator&) = default

Copy constructor. Defaulted.

constexpr encode_iterator(encode_iterator&&) = default

Move constructor. Defaulted.

template<typename _ArgRange, ::std::enable_if_t<!::std::is_same_v<remove_cvref_t<_ArgRange>, encode_iterator>>* = nullptr>
inline constexpr encode_iterator(_ArgRange &&__range) noexcept(::std::is_nothrow_constructible_v<__iterator_base_it, range_type>)

Constructs a ztd::text::decode_iterator from the explicitly given __range.

Remark

Each argument is moved/forwarded in.

Parameters:

__range – [in] The range value that will be read from.

inline constexpr encode_iterator(range_type __range, encoding_type __encoding) noexcept(::std::is_nothrow_constructible_v<__iterator_base_it, range_type, encoding_type>)

Constructs a ztd::text::encode_iterator from the explicitly given __range, and __encoding.

Remark

Each argument is moved in.

Parameters:
  • __range – [in] The range value that will be read from.

  • __encoding – [in] The encoding object to use.

inline constexpr encode_iterator(range_type __range, error_handler_type __error_handler) noexcept(::std::is_nothrow_constructible_v<__iterator_base_it, range_type, error_handler_type>)

Constructs a ztd::text::encode_iterator from the explicitly given __range, and __error_handler.

Remark

Each argument is moved in.

Parameters:
  • __range – [in] The range value that will be read from.

  • __error_handler – [in] The error handler to use for reporting errors.

inline constexpr encode_iterator(range_type __range, encoding_type __encoding, error_handler_type __error_handler) noexcept(::std::is_nothrow_constructible_v<__iterator_base_it, range_type, encoding_type, error_handler_type>)

Constructs a ztd::text::encode_iterator from the explicitly given __range, __encoding, and __error_handler.

Remark

Each argument is moved in.

Parameters:
  • __range – [in] The range value that will be read from.

  • __encoding – [in] The encoding object to use.

  • __error_handler – [in] The error handler to use for reporting errors.

inline constexpr encode_iterator(range_type __range, encoding_type __encoding, error_handler_type __error_handler, state_type __state) noexcept(::std::is_nothrow_constructible_v<__iterator_base_it, range_type, encoding_type, error_handler_type, state_type>)

Constructs a ztd::text::encode_iterator from the explicitly given __range, __encoding, __error_handler and __state.

Remark

Each argument is moved in.

Parameters:
  • __range – [in] The range value that will be read from.

  • __encoding – [in] The encoding object to use.

  • __error_handler – [in] The error handler to use for reporting errors.

  • __state – [in] The current state.

constexpr encode_iterator &operator=(const encode_iterator&) = default

Copy assignment operator. Defaulted.

constexpr encode_iterator &operator=(encode_iterator&&) = default

Move assignment operator. Defaulted.