<commit_before>#include <algorithm>
#include <ranges>
#include <vector>
#include <string>
#include <sstream>
#include <iostream>
#include <iterator>


std::vector<int> count_lines_in_files(std::vector<std::string> const& strs) {
    auto const& tmp_vals = 
        strs | std::ranges::views::transform([](std::string const& str) {
            std::istringstream in{str};
            return std::count(
                std::istreambuf_iterator<char>(in),
                std::istreambuf_iterator<char>(),
                '\n');
        });
    
    std::vector<int> cnts{};
    std::copy(std::cbegin(tmp_vals), std::cend(tmp_vals), std::back_inserter(cnts));
    
    return cnts;
}


int main() {    
    for (auto const line_count : count_lines_in_files( { "1\n2\n3" }))
       std::cout << line_count << " line(s)\n";

    return 0;
}<commit_msg>[i_cukic-func_progr_in_cpp][ch 01] slightly rewrite an example with ranges and lambdas<commit_after>#include <algorithm>
#include <iostream>
#include <iterator>
#include <ranges>
#include <sstream>
#include <string>
#include <vector>
namespace test {

std::vector<int> countLines(std::vector<std::string> const& strs) {
    std::vector<int> ret{};
    
    auto const& tmpVals = strs |
        std::ranges::views::transform([](auto const& str) {
            std::istringstream in{str};
            return std::count(
                std::istreambuf_iterator<char>{in},
                std::istreambuf_iterator<char>{},
                '\n');
        });

    std::copy(std::cbegin(tmpVals), std::cend(tmpVals), std::back_inserter(ret));        
    
    return ret;
}

void run() {
    for (auto const cnt: countLines( { "1\n2\n3", "1\n2\n3", "1\n2\n3" } ))
        std::cout << "line count: " << cnt << std::endl;
}
} // test


int main() {
    std::cout << "test => [ok]" << std::endl; test::run(); std::cout << std::endl;

    return 0;
}
{'fraction_non_alphanumeric': 0.1768131286394918, 'fraction_numerical': 0.008470089994706194, 'mean_word_length': 3.0471092077087794, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 28, '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': '5569239', 'n_tokens_mistral': 669, 'n_tokens_neox': 652, 'n_words': 129}