File tree Expand file tree Collapse file tree 12 files changed +194
-30
lines changed
Expand file tree Collapse file tree 12 files changed +194
-30
lines changed Original file line number Diff line number Diff line change 1+ BasedOnStyle : LLVM
2+ IndentWidth : 4
3+ ColumnLimit : 120
4+ AlignEscapedNewlines : Left
5+ AlignAfterOpenBracket : AlwaysBreak
6+ #
7+ # Bind * to the type rather than the name.
8+ PointerAlignment : Left
9+ #
10+ # Put function name on separate line from return type.
11+ AlwaysBreakAfterReturnType : All
12+ #
13+ # Put arguments either all on same line or on separate lines.
14+ BinPackArguments : false
15+ #
16+ # Put function parameters on separate lines.
17+ BinPackParameters : false
18+ #
19+ # Open brace goes on new line only when starting a new struct, enum, or func.
20+ BreakBeforeBraces : Mozilla
21+ #
22+ # Don't sort includes in alphabetical order because Windows headers are odd.
23+ SortIncludes : false
Original file line number Diff line number Diff line change 2020 - name : Install build tools
2121 run : |
2222 sudo apt-get update
23- sudo apt-get install -y build-essential g++ clang
23+ sudo apt-get install -y build-essential g++ clang clang-format
2424
25- # 3. Build and run all examples dynamically
25+ # 3. Clang-format check
26+ - name : Clang-format Check
27+ run : |
28+ ./clang-check.sh *.cpp *.hpp *.c *.h
29+
30+ # 4. Build and run all examples dynamically
2631 - name : Build and Run
2732 run : |
2833 for san in address thread undefined; do
Original file line number Diff line number Diff line change @@ -101,7 +101,7 @@ Common compiler settings live in [common.mk](./common.mk):
101101
102102``` make
103103CXX := g++
104- CXXFLAGS := -std=c++20 -Wall -Wextra
104+ CXXFLAGS := -std=c++23 -Wall -Wextra
105105```
106106
107107Individual examples may extend this, e.g.:
@@ -131,6 +131,15 @@ make SANITIZE=
131131
132132---
133133
134+ ## Clang Format
135+ The ` clang-format ` is used to ensure the code format.
136+
137+ ``` bash
138+ ./clang-check.sh * .cpp * .hpp
139+ ```
140+
141+ ---
142+
134143## Continuous Integration
135144
136145GitHub Actions automatically builds all examples on:
@@ -140,11 +149,16 @@ GitHub Actions automatically builds all examples on:
140149
141150The CI setup requires ** no updates** when new example folders are added.
142151
152+ The CI will perform:
153+ 1 . ` ./clang-check.sh *.cpp *.hpp `
154+ 2 . ` make SANITIZE=[address, thread, undefined] `
155+ 3 . ` make run `
156+
143157---
144158
145159## Toolchain
146160
147- * C++20
161+ * C++23
148162* GNU Make
149163* GCC / Clang (CI currently uses GCC)
150164* Linux (Ubuntu)
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ set -euo pipefail
3+
4+ # Supported extensions
5+ supported_ext=(" c" " h" " cpp" " hpp" )
6+
7+ # Check if a file is supported
8+ is_supported_file () {
9+ local file=" $1 "
10+ local ext=" ${file##* .} "
11+ for e in " ${supported_ext[@]} " ; do
12+ [[ " $ext " == " $e " ]] && return 0
13+ done
14+ return 1
15+ }
16+
17+ # Run clang-format in dry-run mode on a single file
18+ format_file () {
19+ local file=" $1 "
20+ if is_supported_file " $file " ; then
21+ echo " Check Formatting $file "
22+ clang-format --dry-run --Werror " $file "
23+ else
24+ echo " Skipping unsupported file: $file "
25+ fi
26+ }
27+
28+ # Run clang-format on a glob pattern recursively
29+ format_pattern () {
30+ local pattern=" $1 "
31+ # Find files matching the pattern
32+ find . -type f -iname " $pattern " ! -path " ./.git/*" -print0 | while IFS= read -r -d ' ' file; do
33+ format_file " $file "
34+ done
35+ }
36+
37+ # Main
38+ if [ " $# " -eq 0 ]; then
39+ # Default: format all supported files
40+ for ext in " ${supported_ext[@]} " ; do
41+ format_pattern " *.$ext "
42+ done
43+ else
44+ for arg in " $@ " ; do
45+ if [ -f " $arg " ]; then
46+ format_file " $arg "
47+ else
48+ # Treat as a pattern
49+ format_pattern " $arg "
50+ fi
51+ done
52+ fi
Original file line number Diff line number Diff line change 2626# --------------------------
2727# Compiler / Linker flags
2828# --------------------------
29- CXXFLAGS := -std=c++20 -Wall -Wextra $(OPTFLAGS ) $(SAN_FLAGS )
29+ CXXFLAGS := -std=c++23 -Wall -Wextra $(OPTFLAGS ) $(SAN_FLAGS )
3030LDFLAGS := $(SAN_FLAGS )
3131
3232# --------------------------
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ $(TARGET): $(OBJS)
1717 $(CXX ) $(CXXFLAGS ) -c $< -o $@
1818
1919run : $(TARGET )
20- ./$(TARGET )
20+ ./$(TARGET ) $( ARGS )
2121
2222clean :
2323 rm -f $(OBJS ) $(TARGET )
Original file line number Diff line number Diff line change 55#include < memory>
66#include < thread>
77
8- template <typename T>
9- class ThreadSafeQueue {
10- public:
8+ template <typename T> class ThreadSafeQueue
9+ {
10+ public:
1111 ThreadSafeQueue () = default ;
1212 ~ThreadSafeQueue () = default ;
1313
14- void enqueue (T item) {
14+ void
15+ enqueue (T item)
16+ {
1517 std::lock_guard<std::mutex> lock (mutex_);
1618 queue_.push (std::move (item));
1719 cond_var_.notify_one ();
1820 }
1921
20- T dequeue () {
22+ T
23+ dequeue ()
24+ {
2125 std::unique_lock<std::mutex> lock (mutex_);
2226 cond_var_.wait (lock, [this ]() { return !queue_.empty (); });
2327 T item = queue_.front ();
2428 queue_.pop ();
2529 return item;
2630 }
2731
28- bool isEmpty () const {
32+ bool
33+ isEmpty () const
34+ {
2935 std::lock_guard<std::mutex> lock (mutex_);
3036 return queue_.empty ();
3137 }
3238
33- size_t size () const {
39+ size_t
40+ size () const
41+ {
3442 std::lock_guard<std::mutex> lock (mutex_);
3543 return queue_.size ();
3644 }
3745
38- private:
46+ private:
3947 mutable std::mutex mutex_;
4048 std::condition_variable cond_var_;
4149 std::queue<T> queue_;
4250};
4351
44- int main () {
52+ int
53+ main ()
54+ {
4555 ThreadSafeQueue<int > tsQueue;
4656
4757 // Enqueue some items
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ $(TARGET): $(OBJS)
1414 $(CXX ) $(CXXFLAGS ) -c $< -o $@
1515
1616run : $(TARGET )
17- ./$(TARGET )
17+ ./$(TARGET ) $( ARGS )
1818
1919clean :
2020 rm -f $(OBJS ) $(TARGET )
Original file line number Diff line number Diff line change 22#include < memory>
33#include < utility>
44
5- class Resource {
6- public:
7- explicit Resource (int id) : id_(id) {
8- std::cout << " Resource " << id_ << " acquired\n " ;
9- }
5+ class Resource
6+ {
7+ public:
8+ explicit Resource (int id) : id_(id) { std::cout << " Resource " << id_ << " acquired\n " ; }
109
11- ~Resource () {
12- std::cout << " Resource " << id_ << " released\n " ;
13- }
10+ ~Resource () { std::cout << " Resource " << id_ << " released\n " ; }
1411
15- void use () const {
12+ void
13+ use () const
14+ {
1615 std::cout << " Using resource " << id_ << " \n " ;
1716 }
1817
19- private:
18+ private:
2019 int id_;
2120};
2221
2322// Factory function: returns ownership
24- std::unique_ptr<Resource> make_resource (int id) {
23+ std::unique_ptr<Resource>
24+ make_resource (int id)
25+ {
2526 return std::make_unique<Resource>(id);
2627}
2728
2829// Takes ownership explicitly
29- void consume_resource (std::unique_ptr<Resource> res) {
30+ void
31+ consume_resource (std::unique_ptr<Resource> res)
32+ {
3033 std::cout << " Consuming resource\n " ;
3134 res->use ();
3235 // res is destroyed here
3336}
3437
3538// Borrows resource (no ownership transfer)
36- void inspect_resource (const Resource& res) {
39+ void
40+ inspect_resource (const Resource& res)
41+ {
3742 std::cout << " Inspecting resource\n " ;
3843 res.use ();
3944}
4045
41- int main () {
46+ int
47+ main ()
48+ {
4249 std::cout << " === create resource ===\n " ;
4350 auto r1 = make_resource (1 );
4451
Original file line number Diff line number Diff line change 1+ # pull in shared compiler settings
2+ include ../common.mk
3+
4+ # per-example flags
5+ CXXFLAGS += -pthread
6+
7+ TARGET := views-zip-enumerate
8+ SRCS := main.cpp
9+ OBJS := $(SRCS:.cpp=.o )
10+
11+ all : $(TARGET )
12+
13+ $(TARGET ) : $(OBJS )
14+ $(CXX ) $(CXXFLAGS ) -o $@ $^
15+
16+ % .o : % .cpp
17+ $(CXX ) $(CXXFLAGS ) -c $< -o $@
18+
19+ run : $(TARGET )
20+ ./$(TARGET ) $(ARGS )
21+
22+ clean :
23+ rm -f $(OBJS ) $(TARGET )
24+
25+ .PHONY : all clean run
You can’t perform that action at this time.
0 commit comments