Skip to content

Commit 3f88a02

Browse files
committed
Replace using-directives with namespace alias in examples and docs
Replace `using namespace boost::capy;` with `namespace capy = boost::capy;` and qualify all capy names with `capy::` across all 17 example source files and 14 corresponding documentation pages. Doc code listings are verified to match compiled source files exactly.
1 parent 0c428f0 commit 3f88a02

31 files changed

Lines changed: 637 additions & 604 deletions

doc/modules/ROOT/pages/7.examples/7a.hello-task.adoc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ The minimal Capy program: a task that prints a message.
2020
#include <boost/capy.hpp>
2121
#include <iostream>
2222
23-
using namespace boost::capy;
23+
namespace capy = boost::capy;
2424
25-
task<> say_hello()
25+
capy::task<> say_hello()
2626
{
2727
std::cout << "Hello from Capy!\n";
2828
co_return;
2929
}
3030
3131
int main()
3232
{
33-
thread_pool pool;
34-
run_async(pool.get_executor())(say_hello());
33+
capy::thread_pool pool;
34+
capy::run_async(pool.get_executor())(say_hello());
3535
return 0;
3636
}
3737
----
@@ -50,7 +50,7 @@ target_link_libraries(hello_task PRIVATE capy)
5050

5151
[source,cpp]
5252
----
53-
task<> say_hello()
53+
capy::task<> say_hello()
5454
{
5555
std::cout << "Hello from Capy!\n";
5656
co_return;
@@ -65,7 +65,7 @@ Tasks are lazy: calling `say_hello()` creates a task object but does not execute
6565

6666
[source,cpp]
6767
----
68-
thread_pool pool;
68+
capy::thread_pool pool;
6969
----
7070

7171
`thread_pool` provides an execution context with worker threads. By default, it creates one thread per CPU core.
@@ -76,7 +76,7 @@ The pool's destructor waits for all work to complete before returning. This ensu
7676

7777
[source,cpp]
7878
----
79-
run_async(pool.get_executor())(say_hello());
79+
capy::run_async(pool.get_executor())(say_hello());
8080
----
8181

8282
`run_async` bridges non-coroutine code (like `main`) to coroutine code. The two-call syntax:

doc/modules/ROOT/pages/7.examples/7b.producer-consumer.adoc

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,43 +23,44 @@ Two tasks communicating via an async event, with strand serialization.
2323
#include <iostream>
2424
#include <latch>
2525
26-
using namespace boost::capy;
26+
namespace capy = boost::capy;
2727
2828
int main()
2929
{
30-
thread_pool pool; // thread_pool
31-
strand s{pool.get_executor()}; // strand - serializes execution
32-
std::latch done(1); // std::latch - wait for completion
30+
capy::thread_pool pool;
31+
capy::strand s{pool.get_executor()};
32+
std::latch done(1);
3333
34-
auto on_complete = [&done](auto&&...) { done.count_down(); }; // lambda
35-
auto on_error = [&done](std::exception_ptr) { done.count_down(); }; // lambda
34+
auto on_complete = [&done](auto&&...) { done.count_down(); };
35+
auto on_error = [&done](std::exception_ptr) { done.count_down(); };
3636
37-
async_event data_ready; // async_event
38-
int shared_value = 0; // int
37+
capy::async_event data_ready;
38+
int shared_value = 0;
3939
40-
auto producer = [&]() -> task<> {
40+
auto producer = [&]() -> capy::task<> {
4141
std::cout << "Producer: preparing data...\n";
4242
shared_value = 42;
4343
std::cout << "Producer: data ready, signaling\n";
4444
data_ready.set();
4545
co_return;
4646
};
4747
48-
auto consumer = [&]() -> task<> {
48+
auto consumer = [&]() -> capy::task<> {
4949
std::cout << "Consumer: waiting for data...\n";
50-
co_await data_ready.wait();
50+
auto [ec] = co_await data_ready.wait();
51+
(void)ec;
5152
std::cout << "Consumer: received value " << shared_value << "\n";
5253
co_return;
5354
};
5455
5556
// Run both tasks concurrently using when_all, through a strand.
5657
// The strand serializes execution, ensuring thread-safe access
5758
// to the shared async_event and shared_value.
58-
auto run_both = [&]() -> task<> {
59-
co_await when_all(producer(), consumer());
59+
auto run_both = [&]() -> capy::task<> {
60+
co_await capy::when_all(producer(), consumer());
6061
};
6162
62-
run_async(s, on_complete, on_error)(run_both());
63+
capy::run_async(s, on_complete, on_error)(run_both());
6364
6465
done.wait(); // Block until tasks complete
6566
return 0;
@@ -80,7 +81,7 @@ target_link_libraries(producer_consumer PRIVATE capy)
8081

8182
[source,cpp]
8283
----
83-
strand s{pool.get_executor()}; // strand - serializes execution
84+
capy::strand s{pool.get_executor()};
8485
----
8586

8687
A `strand` is an executor adaptor that serializes execution. All coroutines dispatched through a strand are guaranteed not to run concurrently, making it safe to access shared state without explicit locking. Note that `async_event` is not thread-safe, so using a strand ensures safe access.
@@ -89,7 +90,7 @@ A `strand` is an executor adaptor that serializes execution. All coroutines disp
8990

9091
[source,cpp]
9192
----
92-
async_event data_ready; // async_event
93+
capy::async_event data_ready;
9394
----
9495

9596
`async_event` is a one-shot signaling mechanism. One task can `set()` it; other tasks can `wait()` for it. When set, all waiting tasks resume.
@@ -98,7 +99,7 @@ async_event data_ready; // async_event
9899

99100
[source,cpp]
100101
----
101-
auto producer = [&]() -> task<> {
102+
auto producer = [&]() -> capy::task<> {
102103
std::cout << "Producer: preparing data...\n";
103104
shared_value = 42;
104105
std::cout << "Producer: data ready, signaling\n";
@@ -113,9 +114,10 @@ The producer prepares data and signals completion by calling `set()`.
113114

114115
[source,cpp]
115116
----
116-
auto consumer = [&]() -> task<> {
117+
auto consumer = [&]() -> capy::task<> {
117118
std::cout << "Consumer: waiting for data...\n";
118-
co_await data_ready.wait();
119+
auto [ec] = co_await data_ready.wait();
120+
(void)ec;
119121
std::cout << "Consumer: received value " << shared_value << "\n";
120122
co_return;
121123
};
@@ -130,11 +132,11 @@ The consumer waits until the event is set. The `co_await data_ready.wait()` susp
130132
// Run both tasks concurrently using when_all, through a strand.
131133
// The strand serializes execution, ensuring thread-safe access
132134
// to the shared async_event and shared_value.
133-
auto run_both = [&]() -> task<> {
134-
co_await when_all(producer(), consumer());
135+
auto run_both = [&]() -> capy::task<> {
136+
co_await capy::when_all(producer(), consumer());
135137
};
136138
137-
run_async(s, on_complete, on_error)(run_both());
139+
capy::run_async(s, on_complete, on_error)(run_both());
138140
----
139141

140142
`when_all` runs both tasks concurrently within the same parent coroutine context, but the strand ensures they don't run at the same time on different threads. The producer signals `data_ready` when the value is set, and the consumer waits for the signal before reading.

doc/modules/ROOT/pages/7.examples/7c.buffer-composition.adoc

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Composing buffer sequences without allocation for scatter/gather I/O.
2323
#include <array>
2424
#include <vector>
2525
26-
using namespace boost::capy;
26+
namespace capy = boost::capy;
2727
2828
void demonstrate_single_buffers()
2929
{
@@ -35,9 +35,9 @@ void demonstrate_single_buffers()
3535
std::vector<char> vec = {'V', 'e', 'c', 't', 'o', 'r'};
3636
3737
// make_buffer creates buffer views (no copies)
38-
auto str_buf = make_buffer(str); // mutable_buffer
39-
auto arr_buf = make_buffer(arr, sizeof(arr) - 1); // mutable_buffer - Exclude null terminator
40-
auto vec_buf = make_buffer(vec); // mutable_buffer
38+
auto str_buf = capy::make_buffer(str); // mutable_buffer
39+
auto arr_buf = capy::make_buffer(arr, sizeof(arr) - 1); // mutable_buffer - Exclude null terminator
40+
auto vec_buf = capy::make_buffer(vec); // mutable_buffer
4141
4242
std::cout << "String buffer: " << str_buf.size() << " bytes\n";
4343
std::cout << "Array buffer: " << arr_buf.size() << " bytes\n";
@@ -48,19 +48,19 @@ void demonstrate_buffer_pair()
4848
{
4949
std::cout << "\n=== Buffer Pair (Scatter/Gather) ===\n\n";
5050
51-
// const_buffer_pair is std::array<const_buffer, 2>
51+
// capy::const_buffer_pair is std::array<const_buffer, 2>
5252
std::string header = "Content-Type: text/plain\r\n\r\n";
5353
std::string body = "Hello, World!";
5454
55-
const_buffer_pair message = {{
56-
make_buffer(header),
57-
make_buffer(body)
55+
capy::const_buffer_pair message = {{
56+
capy::make_buffer(header),
57+
capy::make_buffer(body)
5858
}};
5959
6060
// Calculate total size
61-
std::size_t total = buffer_size(message);
61+
std::size_t total = capy::buffer_size(message);
6262
std::cout << "Total message size: " << total << " bytes\n";
63-
std::cout << "Buffer count: " << buffer_length(message) << "\n";
63+
std::cout << "Buffer count: " << capy::buffer_length(message) << "\n";
6464
6565
// Iterate through buffers
6666
std::cout << "\nBuffer contents:\n";
@@ -83,17 +83,17 @@ void demonstrate_buffer_array()
8383
std::string empty_line = "\r\n";
8484
std::string body = R"({"status":"ok"})";
8585
86-
std::array<const_buffer, 5> http_response = {{
87-
make_buffer(status),
88-
make_buffer(content_type),
89-
make_buffer(server),
90-
make_buffer(empty_line),
91-
make_buffer(body)
86+
std::array<capy::const_buffer, 5> http_response = {{
87+
capy::make_buffer(status),
88+
capy::make_buffer(content_type),
89+
capy::make_buffer(server),
90+
capy::make_buffer(empty_line),
91+
capy::make_buffer(body)
9292
}};
9393
94-
std::size_t total = buffer_size(http_response);
94+
std::size_t total = capy::buffer_size(http_response);
9595
std::cout << "HTTP response size: " << total << " bytes\n";
96-
std::cout << "Buffer count: " << buffer_length(http_response) << "\n";
96+
std::cout << "Buffer count: " << capy::buffer_length(http_response) << "\n";
9797
9898
// In real code with streams:
9999
// co_await write(stream, http_response);
@@ -108,13 +108,13 @@ void demonstrate_mutable_buffers()
108108
char buf1[64];
109109
char buf2[64];
110110
111-
mutable_buffer_pair recv_buffers = {{
112-
mutable_buffer(buf1, sizeof(buf1)),
113-
mutable_buffer(buf2, sizeof(buf2))
111+
capy::mutable_buffer_pair recv_buffers = {{
112+
capy::mutable_buffer(buf1, sizeof(buf1)),
113+
capy::mutable_buffer(buf2, sizeof(buf2))
114114
}};
115115
116-
std::cout << "Prepared " << buffer_length(recv_buffers)
117-
<< " buffers with " << buffer_size(recv_buffers)
116+
std::cout << "Prepared " << capy::buffer_length(recv_buffers)
117+
<< " buffers with " << capy::buffer_size(recv_buffers)
118118
<< " bytes total capacity\n";
119119
120120
// In real code:
@@ -146,8 +146,8 @@ target_link_libraries(buffer_composition PRIVATE capy)
146146

147147
[source,cpp]
148148
----
149-
auto str_buf = make_buffer(str); // mutable_buffer
150-
auto arr_buf = make_buffer(arr, sizeof(arr) - 1); // mutable_buffer
149+
auto str_buf = capy::make_buffer(str); // mutable_buffer
150+
auto arr_buf = capy::make_buffer(arr, sizeof(arr) - 1); // mutable_buffer
151151
----
152152

153153
`make_buffer` creates buffer views from various sources. No data is copied—the buffers reference the original storage.
@@ -156,9 +156,9 @@ auto arr_buf = make_buffer(arr, sizeof(arr) - 1); // mutable_buffer
156156

157157
[source,cpp]
158158
----
159-
const_buffer_pair message = {{
160-
make_buffer(header),
161-
make_buffer(body)
159+
capy::const_buffer_pair message = {{
160+
capy::make_buffer(header),
161+
capy::make_buffer(body)
162162
}};
163163
----
164164

@@ -168,9 +168,9 @@ const_buffer_pair message = {{
168168

169169
[source,cpp]
170170
----
171-
std::array<const_buffer, 5> http_response = {{
172-
make_buffer(status),
173-
make_buffer(content_type),
171+
std::array<capy::const_buffer, 5> http_response = {{
172+
capy::make_buffer(status),
173+
capy::make_buffer(content_type),
174174
// ...
175175
}};
176176
----

0 commit comments

Comments
 (0)