• A container reverse-adaptor for range-based for loops

    From Bonita Montero@21:1/5 to All on Sun Sep 19 12:12:56 2021
    Am 19.09.2021 um 11:23 schrieb Bonita Montero:
    ...
    template<typename Container>
    concept concept_reverser = requires( Container cont )
    {
    typename Container::reverse_iterator;
        { cont.rbegin() } -> std::convertible_to<typename Container::reverse_iterator>;
        { cont.rend()   } -> std::convertible_to<typename Container::reverse_iterator>;
    };
    #endif
    ...

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Bonita Montero@21:1/5 to All on Sun Sep 19 11:23:37 2021
    #pragma once
    #if defined(__cpp_concepts)
    #include <concepts>

    template<typename Container>
    concept concept_reverser = requires( Container cont )
    {
    { cont.rbegin() } -> std::convertible_to<typename Container::reverse_iterator>;
    { cont.rend() } -> std::convertible_to<typename Container::reverse_iterator>;
    };
    #endif

    template<typename Container>
    #if defined(__cpp_concepts)
    requires concept_reverser<Container>
    #endif
    struct reverser
    {
    using iterator = typename Container::reverse_iterator;
    reverser( Container &cont );
    iterator begin();
    iterator end();
    private:
    Container &m_cont;
    };

    template<typename Container>
    #if defined(__cpp_concepts)
    requires concept_reverser<Container>
    #endif
    inline
    reverser<Container>::reverser( Container &cont ) :
    m_cont( cont )
    {
    }

    template<typename Container>
    #if defined(__cpp_concepts)
    requires concept_reverser<Container>
    #endif
    inline
    typename reverser<Container>::iterator reverser<Container>::begin()
    {
    return m_cont.rbegin();
    }

    template<typename Container>
    #if defined(__cpp_concepts)
    requires concept_reverser<Container>
    #endif
    inline
    typename reverser<Container>::iterator reverser<Container>::end()
    {
    return m_cont.rend();
    }

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)