File tree Expand file tree Collapse file tree 5 files changed +85
-0
lines changed
Expand file tree Collapse file tree 5 files changed +85
-0
lines changed Original file line number Diff line number Diff line change 1+ bazel- *
Original file line number Diff line number Diff line change 1+ cc_binary (
2+ name = "bazel-project" ,
3+ srcs = ["src/main.cpp" ],
4+ deps = [
5+ "@msd.channel" ,
6+ ],
7+ copts = ["--std=c++17" ],
8+ )
Original file line number Diff line number Diff line change 1+ bazel_dep (name = "msd.channel" )
2+
3+ msd_channel_module = """module(
4+ name = "msd.channel",
5+
6+ )"""
7+
8+ msd_channel_build = """package(default_visibility = ["//visibility:public"])
9+
10+ cc_library(
11+ name = "msd.channel",
12+ includes = ["include"],
13+ hdrs = glob(["include/**/*.*"]),
14+ )
15+ """
16+
17+ archive_override (
18+ module_name = "msd.channel" ,
19+ patch_cmds = [
20+ "echo '" + msd_channel_module + "' > MODULE.bazel" ,
21+ "echo '" + msd_channel_build + "' > BUILD.bazel" ,
22+ ],
23+ urls = ["https://github.com/andreiavrammsd/cpp-channel/archive/refs/tags/v0.8.3.zip" ],
24+ strip_prefix = "cpp-channel-0.8.3" ,
25+ integrity = "sha256-CVEC3XvmoghyBvwi7C4ytOtofyX41X02NVKQ/7ID5Nc=" ,
26+ )
Original file line number Diff line number Diff line change 1+ # CMake project
2+
3+ Example of using C++ Channel in a project with Bazel.
4+
5+ ## Requirements
6+ * C++11 compiler
7+ * Bazel
8+
9+ ## Build and run
10+
11+ ``` shell script
12+ bazel run //:bazel-project
13+
14+ docker run --rm -ti -v $PWD :/app -w /app --name bazel-project gcr.io/bazel-public/bazel:8.0.1 run //:bazel-project
15+ ```
Original file line number Diff line number Diff line change 1+ #include < cstddef>
2+ #include < iostream>
3+
4+ #include " msd/channel.hpp"
5+
6+ int main ()
7+ {
8+ constexpr std::size_t kChannelSize = 10 ;
9+ msd::channel<int > chan{kChannelSize };
10+
11+ int input{};
12+
13+ try {
14+ input = 1 ;
15+ chan << input;
16+
17+ input = 2 ;
18+ chan << input;
19+
20+ input = 3 ;
21+ chan << input;
22+ }
23+ catch (const msd::closed_channel& ex) {
24+ std::cout << ex.what () << ' \n ' ;
25+ return 1 ;
26+ }
27+
28+ for (auto out : chan) {
29+ std::cout << out << ' \n ' ;
30+
31+ if (chan.empty ()) {
32+ break ;
33+ }
34+ }
35+ }
You can’t perform that action at this time.
0 commit comments