<commit_before>#pragma once

#include <agency/future.hpp>
#include <agency/execution_categories.hpp>
#include <agency/functional.hpp>
#include <functional>
#include <utility>

namespace agency
{


class sequential_executor
{
  public:
    using execution_category = sequential_execution_tag;

    template<class Function, class Factory>
    void execute(Function f, size_t n, Factory shared_factory)
    {
      auto shared_parm = shared_factory();

      for(size_t i = 0; i < n; ++i)
      {
        f(i, shared_parm);
      }
    }

    template<class Function, class Factory>
    std::future<void> async_execute(Function f, size_t n, Factory shared_factory)
    {
      return std::async(std::launch::deferred, [=]
      {
        this->execute(f, n, shared_factory);
      });
    }

    template<class Function, class Factory>
    std::future<void> then_execute(Function f, size_t n, std::future<void>& fut, Factory shared_factory)
    {
      return detail::then(fut, std::launch::deferred, [=](std::future<void>& predecessor)
      {
        this->execute(f, n, shared_factory);
      });
    }

    template<class Function, class T, class Factory>
    std::future<void> then_execute(Function f, size_t n, std::future<T>& fut, Factory shared_factory)
    {
      return detail::then(fut, std::launch::deferred, [=](std::future<T>& predecessor) mutable
      {
        using second_type = decltype(shared_factory());

        auto first = predecessor.get();

        this->execute([=](size_t idx, std::pair<T,second_type>& p) mutable
        {
          f(idx, p.first, p.second);
        },
        n,
        [=]
        {
          return std::make_pair(first, shared_factory());
        });
      });
    }
};


} // end agency
<commit_msg>Make then_execute's lambda mutable<commit_after>#pragma once

#include <agency/future.hpp>
#include <agency/execution_categories.hpp>
#include <agency/functional.hpp>
#include <functional>
#include <utility>

namespace agency
{


class sequential_executor
{
  public:
    using execution_category = sequential_execution_tag;

    template<class Function, class Factory>
    void execute(Function f, size_t n, Factory shared_factory)
    {
      auto shared_parm = shared_factory();

      for(size_t i = 0; i < n; ++i)
      {
        f(i, shared_parm);
      }
    }

    template<class Function, class Factory>
    std::future<void> async_execute(Function f, size_t n, Factory shared_factory)
    {
      return std::async(std::launch::deferred, [=]
      {
        this->execute(f, n, shared_factory);
      });
    }

    template<class Function, class Factory>
    std::future<void> then_execute(Function f, size_t n, std::future<void>& fut, Factory shared_factory)
    {
      return detail::then(fut, std::launch::deferred, [=](std::future<void>& predecessor)
      {
        this->execute(f, n, shared_factory);
      });
    }

    template<class Function, class T, class Factory>
    std::future<void> then_execute(Function f, size_t n, std::future<T>& fut, Factory shared_factory)
    {
      return detail::then(fut, std::launch::deferred, [=](std::future<T>& predecessor) mutable
      {
        using second_type = decltype(shared_factory());

        auto first = predecessor.get();

        this->execute([=](size_t idx, std::pair<T,second_type>& p) mutable
        {
          f(idx, p.first, p.second);
        },
        n,
        [=]() mutable
        {
          return std::make_pair(first, shared_factory());
        });
      });
    }
};


} // end agency

{'fraction_non_alphanumeric': 0.13727710161335976, 'fraction_numerical': 0.0005660911406736484, 'mean_word_length': 2.9574468085106385, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1659661', 'n_tokens_mistral': 1146, 'n_tokens_neox': 1094, 'n_words': 244}