<commit_before>/*
 * Copyright (C) 2021 ScyllaDB
 */

/*
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

#pragma once

#include <seastar/core/coroutine.hh>
#include "sstables/consumer.hh"

#if __cpp_impl_coroutine >= 201902L
#  define COROUTINE_NS std
#else
#  define COROUTINE_NS std::experimental
#endif

/* To construct an processing_result_generator object, you need a function that is a coroutine (uses co_yield)
 * and has return type of this class. The execution of the coroutine can be then controlled using this class.
 * To execute a fragment of the coroutine that ends at an co_yield, and get the yielded value use generate().
 * Each subsequent generate() call starts after the last co_yield and continues until another one is encountered.
 *
 * Explanation of C++ coroutines below:
 * A "co_yield val" call is equivalent to "co_await yield_value(val)". In yield_value we save the value in
 * "current_value", and it returns a suspend_always object, causing the coroutine to return to the caller after
 * each co_yield.
 * The await_transform() method is deleted, so we don't use co_await directly without yielding any value.
 * The unhandled_exception() method is called when an unhandled exception is detected in the coroutine. We
 * save it to a local variable, and check it in our generate() calls.
 */
class processing_result_generator {
public:
    struct promise_type;
    struct read_awaiter {
        data_consumer::read_status _rs;
        read_awaiter(data_consumer::read_status rs) : _rs(rs) {}<commit_msg>sstables/processing_result_generator.hh: refine check for coroutine standard<commit_after>/*
 * Copyright (C) 2021 ScyllaDB
 */

/*
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

#pragma once

#include <seastar/core/coroutine.hh>
#include "sstables/consumer.hh"

// Clang < 15 only supports the TS
#if __has_include(<coroutine>) && (!defined(__clang__) || __clang_major__ >= 15)
#  define COROUTINE_NS std
#else
#  define COROUTINE_NS std::experimental
#endif

/* To construct an processing_result_generator object, you need a function that is a coroutine (uses co_yield)
 * and has return type of this class. The execution of the coroutine can be then controlled using this class.
 * To execute a fragment of the coroutine that ends at an co_yield, and get the yielded value use generate().
 * Each subsequent generate() call starts after the last co_yield and continues until another one is encountered.
 *
 * Explanation of C++ coroutines below:
 * A "co_yield val" call is equivalent to "co_await yield_value(val)". In yield_value we save the value in
 * "current_value", and it returns a suspend_always object, causing the coroutine to return to the caller after
 * each co_yield.
 * The await_transform() method is deleted, so we don't use co_await directly without yielding any value.
 * The unhandled_exception() method is called when an unhandled exception is detected in the coroutine. We
 * save it to a local variable, and check it in our generate() calls.
 */
class processing_result_generator {
public:
    struct promise_type;
    struct read_awaiter {
        data_consumer::read_status _rs;
        read_awaiter(data_consumer::read_status rs) : _rs(rs) {}
{'fraction_non_alphanumeric': 0.076347771891555, 'fraction_numerical': 0.006855718292302898, 'mean_word_length': 4.440677966101695, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, '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': '512572', 'n_tokens_mistral': 962, 'n_tokens_neox': 932, 'n_words': 387}