<commit_before>// Copyright (c) 2016, <NAME>
//
// This file is distributed under the MIT License. See the accompanying file
// LICENSE.txt or http://www.opensource.org/licenses/mit-license.php for terms
// and conditions.

#ifndef TEXT_VIEW_ITEXT_ITERATOR_HPP // {
#define TEXT_VIEW_ITEXT_ITERATOR_HPP


#include <iterator>
#include <range/v3/range_traits.hpp>
#include <range/v3/utility/iterator_traits.hpp>
#include <text_view_detail/adl_customization.hpp>
#include <text_view_detail/concepts.hpp>
#include <text_view_detail/iterator_preserve.hpp>
#include <text_view_detail/subobject.hpp>


namespace std {
namespace experimental {
inline namespace text {


namespace text_detail {

template<typename ET, typename VT,
CONCEPT_REQUIRES_(
    TextEncoding<ET>(),
    ranges::View<VT>())>
class itext_cursor_base
    : private subobject<typename ET::state_type>
{
    using base_type = subobject<typename ET::state_type>;
    using encoding_type = ET;
    using view_type = VT;
    using iterator_type =
        ranges::range_iterator_t<
            typename std::add_const<view_type>::type>;
    using state_type = typename encoding_type::state_type;

public:
    itext_cursor_base() = default;

    itext_cursor_base(
        state_type state,
        const view_type *view)
    :
        base_type{std::move(state)},
        view(view)
    {}

    const state_type& state() const noexcept {
        return base_type::get();
    }
    state_type& state() noexcept {
        return base_type::get();
    }

    const view_type* underlying_view() const noexcept {
        return view;
    }

private:
    const view_type *view;
};

template<TextEncoding ET, ranges::View VT>
requires TextDecoder<ET, ranges::iterator_t<std::add_const_t<VT>>>()
class itext_cursor_data
    : public itext_cursor_base<ET, VT>
{
    using encoding_type = typename itext_cursor_data::encoding_type;
    using view_type = typename itext_cursor_data::view_type;
    using state_type = typename itext_cursor_data::state_type;
    using iterator_type = typename itext_cursor_data::iterator_type;

public:
    itext_cursor_data() = default;

    itext_cursor_data(
        state_type state,
        const view_type *view,
        iterator_type current)
    :
        itext_cursor_base<ET, VT>{std::move(state), view},
        current(std::move(current))
    {}

    const iterator_type& base() const noexcept {
        return current;
    }
    iterator_type& base() noexcept {
        return current;
    }

private:
    iterator_type current;
};

template<TextEncoding ET, ranges::View VT>
requires TextForwardDecoder<ET, ranges::iterator_t<std::add_const_t<VT>>>()
class itext_cursor_data<ET, VT>
    : public itext_cursor_base<ET, VT>
{
    using encoding_type = typename itext_cursor_data::encoding_type;
    using view_type = typename itext_cursor_data::view_type;
    using state_type = typename itext_cursor_data::state_type;
    using iterator_type = typename itext_cursor_data::iterator_type;

    struct current_view_type {
        current_view_type()
            : first{}, last{} {}
        current_view_type(iterator_type first, iterator_type last)
            : first{first}, last{last} {}

        iterator_type begin() const { return first; }
        iterator_type end() const { return last; }

        iterator_type first;
        iterator_type last;
    };

public:
    itext_cursor_data() = default;

    itext_cursor_data(
        state_type state,
        const view_type *view,
        iterator_type first)
    :<commit_msg>range-v3 port: Updated itext_cursor_data to use enable_if in place of concept based partial ordering.<commit_after>// Copyright (c) 2016, <NAME>
//
// This file is distributed under the MIT License. See the accompanying file
// LICENSE.txt or http://www.opensource.org/licenses/mit-license.php for terms
// and conditions.

#ifndef TEXT_VIEW_ITEXT_ITERATOR_HPP // {
#define TEXT_VIEW_ITEXT_ITERATOR_HPP


#include <iterator>
#include <range/v3/range_traits.hpp>
#include <range/v3/utility/iterator_traits.hpp>
#include <text_view_detail/adl_customization.hpp>
#include <text_view_detail/concepts.hpp>
#include <text_view_detail/iterator_preserve.hpp>
#include <text_view_detail/subobject.hpp>


namespace std {
namespace experimental {
inline namespace text {


namespace text_detail {

template<typename ET, typename VT,
CONCEPT_REQUIRES_(
    TextEncoding<ET>(),
    ranges::View<VT>())>
class itext_cursor_base
    : private subobject<typename ET::state_type>
{
    using base_type = subobject<typename ET::state_type>;
    using encoding_type = ET;
    using view_type = VT;
    using iterator_type =
        ranges::range_iterator_t<
            typename std::add_const<view_type>::type>;
    using state_type = typename encoding_type::state_type;

public:
    itext_cursor_base() = default;

    itext_cursor_base(
        state_type state,
        const view_type *view)
    :
        base_type{std::move(state)},
        view(view)
    {}

    const state_type& state() const noexcept {
        return base_type::get();
    }
    state_type& state() noexcept {
        return base_type::get();
    }

    const view_type* underlying_view() const noexcept {
        return view;
    }

private:
    const view_type *view;
};


// Primary class template is incomplete.
template<typename ET, typename VT, typename Enable = void,
CONCEPT_REQUIRES_(
    TextEncoding<ET>(),
    ranges::View<VT>(),
    TextDecoder<
        ET,
        ranges::range_iterator_t<
            typename std::add_const<VT>::type>>())>
class itext_cursor_data;

// Specialization for input views.
template<typename ET, typename VT>
class itext_cursor_data<
          ET,
          VT,
          typename std::enable_if<
              ! (bool)TextForwardDecoder<
                          ET,
                          ranges::range_iterator_t<
                              typename std::add_const<VT>::type>>()>::type>
: public itext_cursor_base<ET, VT>
{
    using encoding_type = typename itext_cursor_data::encoding_type;
    using view_type = typename itext_cursor_data::view_type;
    using state_type = typename itext_cursor_data::state_type;
    using iterator_type = typename itext_cursor_data::iterator_type;

public:
    itext_cursor_data() = default;

    itext_cursor_data(
        state_type state,
        const view_type *view,
        iterator_type current)
    :
        itext_cursor_base<ET, VT>{std::move(state), view},
        current(std::move(current))
    {}

    const iterator_type& base() const noexcept {
        return current;
    }
    iterator_type& base() noexcept {
        return current;
    }

private:
    iterator_type current;
};

// Specialization for forward views.
template<typename ET, typename VT>
class itext_cursor_data<
          ET,
          VT,
          typename std::enable_if<
              (bool)TextForwardDecoder<
                  ET,
                  ranges::range_iterator_t<
                      typename std::add_const<VT>::type>>()>::type>
: public itext_cursor_base<ET, VT>
{
    using encoding_type = typename itext_cursor_data::encoding_type;
    using view_type = typename itext_cursor_data::view_type;
    using state_type = typename itext_cursor_data::state_type;
    using iterator_type = typename itext_cursor_data::iterator_type;

    struct current_view_type {
        current_view_type()
            : first{}, last{} {}
        current_view_type(iterator_type first, iterator_type last)
            : first{first}, last{last} {}

        iterator_type begin() const { return first; }
        iterator_type end() const { return last; }

        iterator_type first;
        iterator_type last;
    };

public:
    itext_cursor_data() = default;

    itext_cursor_data(
        state_type state,
        const view_type *view,
        iterator_type first)
    :
{'fraction_non_alphanumeric': 0.09823934677213575, 'fraction_numerical': 0.001658586374075019, 'mean_word_length': 3.235008103727715, 'pattern_counts': {'":': 0, '<': 66, '<?xml version=': 0, '>': 66, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1778156', 'n_tokens_mistral': 2435, 'n_tokens_neox': 2366, 'n_words': 532}