<commit_before>/************************************************
 *  flatten_iterator.hpp
 *  ESA++
 *
 *  Copyright (c) 2014, <NAME>
 *  Distributed under The BSD 3-Clause License
 ************************************************/

#ifndef ESAPP_FLATTEN_ITERATOR_HPP_
#define ESAPP_FLATTEN_ITERATOR_HPP_

#include <memory>
#include <type_traits>
#include <utility>

#include "generator.hpp"

namespace esapp
{

template <typename I> class flatten_iterator;

/************************************************
 * Inline Helper Function(s)
 ************************************************/

template <typename Iterable>
inline auto make_flatten_iterator(Iterable const &iterable)
    -> flatten_iterator<decltype(iterable.begin())>
{
    typedef decltype(make_flatten_iterator(iterable)) it_t;
    return it_t(iterable.begin(), iterable.end());
}

/************************************************
 * Declaration: class flatten_iterator
 ************************************************/

template <typename Iterator>
class flatten_iterator
    : public generator<
        flatten_iterator<Iterator>,
        Iterator,
        typename std::remove_const<
            typename std::remove_reference<
                decltype(*(std::declval<Iterator>()->begin()))
            >::type
        >::type
    >
{
private: // Private Type(s)
    typedef generator<
        flatten_iterator,
        Iterator,
        typename std::remove_const<
            typename std::remove_reference<
                decltype(*(std::declval<Iterator>()->begin()))
            >::type
        >::type
    > supercls_t;

public: // Public Type(s)
    typedef typename supercls_t::iterator_category iterator_category;
    typedef typename supercls_t::value_type value_type;
    typedef typename supercls_t::reference reference;
    typedef typename supercls_t::pointer pointer;
    typedef typename supercls_t::difference_type difference_type;
    typedef typename supercls_t::input_iterator input_iterator;
    typedef decltype(std::declval<Iterator>()->begin()) value_iterator;

public: // Public Method(s)
    flatten_iterator(void) = default;
    flatten_iterator(input_iterator const &begin, input_iterator const &end);
    flatten_iterator(flatten_iterator const &it);

    flatten_iterator end(void) const;
    void next(void);
    reference dereference(void) const;
    bool equal(flatten_iterator const &it) const;

private: // Private Method(s)
    flatten_iterator(input_iterator const &begin,
                   input_iterator const &end,
                   std::unique_ptr<value_iterator> &&val_it_ptr);

private: // Private Property(ies)
    std::unique_ptr<value_iterator> val_it_ptr_;
}; // class flatten_iterator

/************************************************
 * Implementation: class flatten_iterator
 ************************************************/

template <typename I>
inline flatten_iterator<I>::flatten_iterator(input_iterator const &begin,
                                         input_iterator const &end)
    : supercls_t(begin, end), val_it_ptr_(nullptr)
{
    if (this->it_ != this->end_)
    {
        val_it_ptr_.reset(new value_iterator(this->it_->begin()));
    }
}

template <typename I>
inline flatten_iterator<I>::flatten_iterator(flatten_iterator const &it)
    : supercls_t(it.it_, it.end_)
{
    if (it.val_it_ptr_.get() != nullptr)
    {
        val_it_ptr_.reset(new value_iterator(*(it.val_it_ptr_)));
    }
    else
    {
        val_it_ptr_.reset();
    }
}

template <typename I>
inline flatten_iterator<I>::flatten_iterator(input_iterator const &begin,
                                         input_iterator const &end,
                                         std::unique_ptr<value_iterator> &&val_it_ptr)
    : supercls_t(begin, end), val_it_ptr_(std::move(val_it_ptr))
{
    // do nothing
}

template <typename I>
inline flatten_iterator<I> flatten_iterator<I>::end(void) const
{
    return flatten_iterator(this->end_, this->end_,
                          decltype(val_it_ptr_)(nullptr));
}<commit_msg>Correct indentations<commit_after>/************************************************
 *  flatten_iterator.hpp
 *  ESA++
 *
 *  Copyright (c) 2014, <NAME>
 *  Distributed under The BSD 3-Clause License
 ************************************************/

#ifndef ESAPP_FLATTEN_ITERATOR_HPP_
#define ESAPP_FLATTEN_ITERATOR_HPP_

#include <memory>
#include <type_traits>
#include <utility>

#include "generator.hpp"

namespace esapp
{

template <typename I> class flatten_iterator;

/************************************************
 * Inline Helper Function(s)
 ************************************************/

template <typename Iterable>
inline auto make_flatten_iterator(Iterable const &iterable)
    -> flatten_iterator<decltype(iterable.begin())>
{
    typedef decltype(make_flatten_iterator(iterable)) it_t;
    return it_t(iterable.begin(), iterable.end());
}

/************************************************
 * Declaration: class flatten_iterator
 ************************************************/

template <typename Iterator>
class flatten_iterator
    : public generator<
        flatten_iterator<Iterator>,
        Iterator,
        typename std::remove_const<
            typename std::remove_reference<
                decltype(*(std::declval<Iterator>()->begin()))
            >::type
        >::type
    >
{
private: // Private Type(s)
    typedef generator<
        flatten_iterator,
        Iterator,
        typename std::remove_const<
            typename std::remove_reference<
                decltype(*(std::declval<Iterator>()->begin()))
            >::type
        >::type
    > supercls_t;

public: // Public Type(s)
    typedef typename supercls_t::iterator_category iterator_category;
    typedef typename supercls_t::value_type value_type;
    typedef typename supercls_t::reference reference;
    typedef typename supercls_t::pointer pointer;
    typedef typename supercls_t::difference_type difference_type;
    typedef typename supercls_t::input_iterator input_iterator;
    typedef decltype(std::declval<Iterator>()->begin()) value_iterator;

public: // Public Method(s)
    flatten_iterator(void) = default;
    flatten_iterator(input_iterator const &begin, input_iterator const &end);
    flatten_iterator(flatten_iterator const &it);

    flatten_iterator end(void) const;
    void next(void);
    reference dereference(void) const;
    bool equal(flatten_iterator const &it) const;

private: // Private Method(s)
    flatten_iterator(input_iterator const &begin,
                   input_iterator const &end,
                   std::unique_ptr<value_iterator> &&val_it_ptr);

private: // Private Property(ies)
    std::unique_ptr<value_iterator> val_it_ptr_;
}; // class flatten_iterator

/************************************************
 * Implementation: class flatten_iterator
 ************************************************/

template <typename I>
inline flatten_iterator<I>::flatten_iterator(input_iterator const &begin,
                                         input_iterator const &end)
    : supercls_t(begin, end), val_it_ptr_(nullptr)
{
    if (this->it_ != this->end_)
    {
        val_it_ptr_.reset(new value_iterator(this->it_->begin()));
    }
}

template <typename I>
inline flatten_iterator<I>::flatten_iterator(flatten_iterator const &it)
    : supercls_t(it.it_, it.end_)
{
    if (it.val_it_ptr_.get() != nullptr)
    {
        val_it_ptr_.reset(new value_iterator(*(it.val_it_ptr_)));
    }
    else
    {
        val_it_ptr_.reset();
    }
}

template <typename I>
inline flatten_iterator<I>::flatten_iterator(
    input_iterator const &begin, input_iterator const &end,
    std::unique_ptr<value_iterator> &&val_it_ptr)
    : supercls_t(begin, end), val_it_ptr_(std::move(val_it_ptr))
{
    // do nothing
}

template <typename I>
inline flatten_iterator<I> flatten_iterator<I>::end(void) const
{
    return flatten_iterator(this->end_, this->end_,
                            decltype(val_it_ptr_)(nullptr));
}
{'fraction_non_alphanumeric': 0.19550561797752808, 'fraction_numerical': 0.0012484394506866417, 'mean_word_length': 3.863995142683667, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 83, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5602068', 'n_tokens_mistral': 2310, 'n_tokens_neox': 2233, 'n_words': 450}