.. _codec: ************* codecs::codec ************* Defined in header ```` .. code-block:: cpp template concept codec = requires(IS1 is1, IS2 is2) { codecs::codec_traits; { T::template encode(is1) } -> meta::same_as; { T::template decode(is2) } -> meta::same_as; }; ---- The **codec** concept specifies the requirements of input encoding/decoding. It is *mgs*' highest-level component. Notation ======== * **is1** - value of type ``IS1`` * **is2** - value of type ``IS2`` * **Traits** - type of ``typename T::traits`` * **E** - type of ``typename T::traits::default_encoded_output`` * **D** - type of ``typename T::traits::default_decoded_output`` Template arguments ================== Definitions ----------- .. table:: :align: left ======= =============================================================================================================================================== **R1** Return type of ``encode``, defaults to ``typename T::traits::default_encoded_output``. **R2** Return type of ``decode``, defaults to ``typename T::traits::default_decoded_output``. **IS1** Type passed to ``encode``, defaults to :ref:`codecs::iterator_sentinel_source\, meta::sentinel_t\> `. **IS2** Type passed to ``decode``, defaults to :ref:`codecs::iterator_sentinel_source\, meta::sentinel_t\> `. ======= =============================================================================================================================================== Constraints ----------- .. table:: :align: left ========== ===================================================== **Traits** :ref:`codecs::codec_traits\ ` **IS1** :ref:`input_source` **IS2** :ref:`input_source` ========== ===================================================== Valid expressions ================= .. table:: :align: left =============================== =========== Expression Return type =============================== =========== **T::template encode(is1)** ``R1`` **T::template decode(is2)** ``R2`` =============================== =========== Expression semantics ==================== .. table:: :align: left =============================== ====================================================== Expression Semantics =============================== ====================================================== **T::template decode(is1)** Encodes the source's input into a value of type ``R1`` **T::template decode(is2)** Decodes the source's input into a value of type ``R2`` =============================== ====================================================== Concept emulation ================= .. code-block:: cpp namespace mgs { namespace codecs { template struct is_codec { /* ... */ }; template constexpr auto is_codec_v = is_codec::value; template >> using codec = T; } // namespace codecs } // namespace mgs Example ======= .. code-block:: cpp #include #include using namespace mgs::codecs; int main() { static_assert(is_codec_v, ""); static_assert(is_codec_v>, ""); } See also ======== * :ref:`iterator_t` * :ref:`sentinel_t` * :ref:`iterator_sentinel_source` * :ref:`codec_traits` * :ref:`same_as` * :ref:`input_source`