any_encoding omni-encoding type

any_encoding is a class type whose sole purpose is to provide a type-generic, byte-based, runtime-deferred way of handling encodings.

Aliases

using ztd::text::any_encoding = any_byte_encoding<::std::byte>

The canonical erased encoding type which uses a std::byte as its code unit type and an unicode_code_point as its code point type, with spans for input and output operations.

Remark

If the input encoding does not match std::byte, it will be first wrapped in a ztd::text::encoding_scheme first.

template<typename _EncodeCodeUnit, typename _EncodeCodePoint = const unicode_code_point, typename _DecodeCodeUnit = ::std::add_const_t<_EncodeCodeUnit>, typename _DecodeCodePoint = ::std::remove_const_t<_EncodeCodePoint>, ::std::size_t _MaxCodeUnits = __txt_detail::__default_max_code_units_any_encoding, ::std::size_t _MaxCodePoints = __txt_detail::__default_max_code_points_any_encoding>
using ztd::text::any_encoding_of = any_encoding_with<::ztd::span<_EncodeCodeUnit>, ::ztd::span<_EncodeCodePoint>, ::ztd::span<_DecodeCodeUnit>, ::ztd::span<_DecodeCodePoint>, _MaxCodeUnits, _MaxCodePoints>

A type-erased encoding that uses the specified code unit, code point, and input/output ranges for the various operations.

using ztd::text::compat_any_encoding = any_byte_encoding<char>

The canonical erased encoding type which uses a char as its code unit type and an unicode_code_point as its code point type, with spans for input and output operations.

Remark

If the input encoding does not match char, it will be first wrapped in a ztd::text::encoding_scheme first. Use this type when dealing with what are effectively byte stream inputs but oriented in a legacy manner, such as old std::string or <iostream>-based work.

using ztd::text::ucompat_any_encoding = any_byte_encoding<unsigned char>

The canonical erased encoding type which uses a unsigned char as its code unit type and an unicode_code_point as its code point type, with spans for input and output operations.

Remark

If the input encoding does not match unsigned char, it will be first wrapped in a ztd::text::encoding_scheme first. Use this type when dealing with what are effectively byte stream inputs but oriented around a slightly more modern approach to proper unsigned data handling with unsigned char.

Base

This is based off of ztd::text::any_encoding_with; the only thing special about it is the constructor logic on top of ztd::text::any_encoding_with.

template<typename _Byte, typename _CodePoint = unicode_code_point>
class any_byte_encoding : public ztd::text::any_encoding_with<_Byte, const unicode_code_point, const _Byte, unicode_code_point>

An encoding type that wraps up other encodings to specifically traffic in the given _Byte type provided, which is typically set to std::byte .

Remark

This type traffics solely in std::span s, which for most people is fine. Others may want to interface with different iterator types (e.g., from a custom Rope implementation or other). For those, one must first create ranges that can operate with those iterators, then use them themselves. (It’s not an ideal process at the moment, and we are looking to make this experience better.) It is recommended to use the provided ztd::text::any_encoding type definition instead of accessing this directly, unless you have a reason for using a different byte type (e.g., interfacing with legacy APIs).

Template Parameters:

_Byte – The byte type to use. Typically, this is either unsigned char or std::byte .

Public Functions

any_byte_encoding() = delete

Cannot default-construct a ztd::text::any_byte_encoding object.

template<typename _EncodingArg, typename ..._Args, ::std::enable_if_t<!::std::is_same_v<remove_cvref_t<_EncodingArg>, any_byte_encoding> && !::std::is_same_v<__txt_detail::__code_unit_or_void_t<remove_cvref_t<_EncodingArg>>, _Byte> && !is_specialization_of_v<remove_cvref_t<_EncodingArg>, ::ztd::text::any_byte_encoding> && !::std::is_same_v<remove_cvref_t<_EncodingArg>, __base_t> && !is_specialization_of_v<remove_cvref_t<_EncodingArg>, ::std::in_place_type_t>>* = nullptr>
inline any_byte_encoding(_EncodingArg &&__encoding, _Args&&... __args)

Constructs a ztd::text::any_byte_encoding with the encoding object and any additional arguments.

Remark

If the provided encoding does not have a byte code_unit type, it is wrapped in an ztd::text::encoding_scheme first.

Parameters:
  • __encoding – [in] The encoding object that informs the ztd::text::any_byte_encoding what encoding object to store.

  • __args – [in] Any additional arguments used to construct the encoding in the erased storage.

template<typename _EncodingArg, typename ..._Args, ::std::enable_if_t<!::std::is_same_v<_Byte, code_unit_t<remove_cvref_t<_EncodingArg>>>>* = nullptr>
inline any_byte_encoding(::std::in_place_type_t<_EncodingArg>, _Args&&... __args)

Constructs a ztd::text::any_byte_encoding with the encoding object and any additional arguments.

Remark

If the provided encoding does not have a byte code_unit type, it is wrapped in an ztd::text::encoding_scheme first.

Template Parameters:

_EncodingArg – The Encoding specified by the std::in_place_type<...> argument.

Parameters:

__args – [in] Any additional arguments used to construct the encoding in the erased storage.

template<typename _EncodingArg, typename ..._Args, ::std::enable_if_t<::std::is_same_v<_Byte, code_unit_t<remove_cvref_t<_EncodingArg>>>>* = nullptr>
inline any_byte_encoding(::std::in_place_type_t<_EncodingArg> __tag, _Args&&... __args)

Constructs a ztd::text::any_byte_encoding with the encoding object and any additional arguments.

Remark

If the provided encoding does not have a byte code_unit type, it is wrapped in an ztd::text::encoding_scheme first.

Template Parameters:

_EncodingArg – The Encoding specified by the std::in_place_type<...> argument.

Parameters:
  • __tag – [in] A tag containing the encoding type.

  • __args – [in] Any additional arguments used to construct the encoding in the erased storage.

any_byte_encoding(const any_byte_encoding&) = delete

Cannot copy-construct a ztd::text::any_byte_encoding object.

any_byte_encoding &operator=(const any_byte_encoding&) = delete

Cannot copy-assign a ztd::text::any_byte_encoding object.

any_byte_encoding(any_byte_encoding&&) = default

Move-constructs a ztd::text::any_byte_encoding from the provided r-value reference.

Remark

This leaves the passed-in r-value reference without an encoding object. Calling any function on a moved-fron ztd::text::any_byte_encoding, except for destruction, is a violation and invokes Undefined Behavior (generally, a crash).

any_byte_encoding &operator=(any_byte_encoding&&) = default

Move-assigns a ztd::text::any_byte_encoding from the provided r-value reference.

Remark

This leaves the passed-in r-value reference without an encoding object. Calling any function on a moved-fron ztd::text::any_byte_encoding, except for destruction, is a violation and invokes Undefined Behavior (generally, a crash).