Skip to content

Commit 313af86

Browse files
committed
..
1 parent b2cc292 commit 313af86

File tree

4 files changed

+121
-1
lines changed

4 files changed

+121
-1
lines changed

cpp.boost/bounded.buffer/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required (VERSION 3.22.2)
1+
cmake_minimum_required (VERSION 3.26)
22

33
project (bounded.buffer)
44

cpp.fp/count.lines/CMakeLists.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
cmake_minimum_required(VERSION 3.26)
2+
3+
project(count.lines)
4+
5+
set (CMAKE_CXX_STANDARD 23)
6+
set (CMAKE_EXPORT_COMPILE_COMMANDS ON)
7+
8+
set (SOURCES
9+
count.lines.cpp
10+
)
11+
12+
include_directories (
13+
/usr/local/include
14+
/opt/homebrew/include
15+
${CMAKE_CURRENT_SOURCE_DIR}
16+
)
17+
18+
link_directories (
19+
/usr/local/lib
20+
/opt/homebrew/lib
21+
)
22+
23+
add_executable(count.lines
24+
${SOURCES}
25+
)

cpp.fp/count.lines/count.lines.cpp

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <string>
4+
#include <fstream>
5+
6+
#include <range/v3/view/transform.hpp>
7+
#include <range/v3/range/conversion.hpp>
8+
9+
namespace view = ranges::views;
10+
using namespace ranges;
11+
using namespace std;
12+
13+
auto count_file_lines(ifstream in) -> int;
14+
auto count_lines(const string& filename) -> int;
15+
auto open_file(string const& filename) -> ifstream;
16+
17+
auto original_count_lines_in_files(const vector<string>& files) -> vector<int>
18+
{
19+
vector<int> results(files.size());
20+
21+
transform(files.cbegin(), files.cend(),
22+
results.begin(),
23+
count_lines);
24+
25+
return results;
26+
}
27+
28+
auto count_file_lines(ifstream in) -> int
29+
{
30+
return count(
31+
istreambuf_iterator<char>(in),
32+
istreambuf_iterator<char>(),
33+
'\n'
34+
);
35+
}
36+
37+
auto count_lines(const string& filename) -> int
38+
{
39+
ifstream in(filename);
40+
41+
if (!in.good())
42+
return 0;
43+
44+
return count(
45+
istreambuf_iterator<char>(in),
46+
istreambuf_iterator<char>(),
47+
'\n'
48+
);
49+
}
50+
51+
auto open_file(string const& filename) -> ifstream
52+
{
53+
try
54+
{
55+
return ifstream{filename};
56+
}
57+
catch(...)
58+
{}
59+
60+
return ifstream{};
61+
}
62+
63+
//
64+
// What a monad!
65+
//
66+
auto count_lines_in_files(vector<string>& files) -> vector<int>
67+
{
68+
return files
69+
| view::transform(count_lines)
70+
| to<vector>();
71+
}
72+
73+
auto count_lines_in_files2(vector<string>& files) -> vector<int>
74+
{
75+
return files
76+
| view::transform(open_file)
77+
| view::transform(count_file_lines)
78+
| to<vector>();
79+
}
80+
81+
int main(int argc, char* argv[])
82+
{
83+
vector<string> files{
84+
"/Users/yielding/code/big.read.write.cpp",
85+
"/Users/yielding/code/big.read.write.cpp"
86+
};
87+
88+
auto res = count_lines_in_files2(files);
89+
for (auto r : res)
90+
cout << r << " ";
91+
92+
return 0;
93+
}

cs/threadpool/producer.consumer/blocking.collection.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ static void NonBlockingConsumer(BlockingCollection<int> bc, CancellationToken ct
4949
break;
5050
}
5151

52+
// REAMRK
53+
// : consumers work here!
5254
// Slow down consumer just a little to cause
5355
// collection to fill up faster, and lead to "AddBlocked"
5456
Thread.SpinWait(500000);

0 commit comments

Comments
 (0)