Skip to content

Commit cad2b0f

Browse files
Merge pull request #16 from contour-terminal/improvement/auto_tags
Introduced a way to generate tags automatically
2 parents ba8084f + 1a207a6 commit cad2b0f

File tree

5 files changed

+163
-181
lines changed

5 files changed

+163
-181
lines changed

.github/workflows/build.yml

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ jobs:
1313
name: "Check C++ style"
1414
runs-on: ubuntu-22.04
1515
steps:
16-
- uses: actions/checkout@v3
17-
- name: Run clang-format style check for C/C++/Protobuf programs.
18-
uses: jidicula/[email protected]
19-
with:
20-
clang-format-version: '16'
21-
check-path: '.'
22-
#exclude-regex: 'sse2neon.h'
16+
- uses: actions/checkout@v3
17+
- name: Install clang
18+
run: |
19+
wget https://apt.llvm.org/llvm.sh
20+
chmod +x llvm.sh
21+
sudo ./llvm.sh 17
22+
sudo apt-get install clang-format-17
23+
- name: "Clang-format"
24+
run: clang-format-17 --Werror --dry-run test-boxed-cpp.cpp include/boxed-cpp/boxed.hpp
2325

2426
editorconfig:
2527
name: "Check editorconfig"
@@ -33,51 +35,49 @@ jobs:
3335
strategy:
3436
fail-fast: false
3537
matrix:
38+
os: [ubuntu-22.04, ubuntu-20.04]
3639
cxx: [20]
3740
build_type: ["RelWithDebInfo"]
38-
compiler:
41+
llvm_version:
3942
[
40-
"g++-11",
41-
"clang++-15"
43+
"17",
44+
"18"
4245
]
43-
name: "Ubuntu 22.04 (${{ matrix.compiler }}, C++${{ matrix.cxx }}, ${{matrix.build_type}})"
44-
runs-on: ubuntu-22.04
46+
name: " ${{ matrix.os }} (clang-${{ matrix.llvm_version }}, C++${{ matrix.cxx }}, ${{matrix.build_type}})"
47+
runs-on: ${{ matrix.os }}
4548
outputs:
4649
id: "${{ matrix.compiler }} (C++${{ matrix.cxx }}, ${{ matrix.build_type }})"
4750
steps:
4851
- uses: actions/checkout@v3
49-
- name: ccache
50-
uses: hendrikmuhs/[email protected]
51-
with:
52-
key: "ccache-ubuntu2204-${{ matrix.compiler }}-${{ matrix.cxx }}-${{ matrix.build_type }}"
53-
max-size: 256M
52+
# - name: ccache
53+
# uses: hendrikmuhs/[email protected]
54+
# with:
55+
# key: "ccache-ubuntu2204-${{ matrix.compiler }}-${{ matrix.cxx }}-${{ matrix.build_type }}"
56+
# max-size: 256M
5457
- name: "update APT database"
5558
run: sudo apt -q update
5659

57-
- name: Set up Clang
58-
uses: egor-tensin/setup-clang@v1
59-
with:
60-
version: 15
6160

61+
- name: Install clang
62+
run: |
63+
wget https://apt.llvm.org/llvm.sh
64+
chmod +x llvm.sh
65+
sudo ./llvm.sh ${{ matrix.llvm_version }}
66+
# can not use clang-tidy until https://github.com/actions/runner-images/issues/8659 get fixed
6267
- name: "Download dependencies"
6368
run: sudo apt install cmake ninja-build # catch2
64-
# workaround for broken clang on ubuntu runner until https://github.com/actions/runner-images/issues/8659 get fixed
65-
#- uses: mjp41/workaround8649@7929373c0fe5caf844d8115adccef39e3b5362e7
66-
- name: Install Compilers
67-
run: sudo apt install -y g++-12
6869
- name: "Cmake configure"
6970
run: |
7071
cmake -S . -B build -G Ninja \
71-
-DBOXED_CPP_TESTS=OFF \
72-
-DENABLE_TIDY=ON \
73-
-DPEDANTIC_COMPILER=ON \
72+
-DBOXED_TESTING=ON \
73+
-DENABLE_TIDY=OFF \
74+
-DPEDANTIC_COMPILER=OFF \
7475
-DCMAKE_CXX_FLAGS="-Wno-unknown-warning-option" \
75-
-DCMAKE_CXX_COMPILER=${{ matrix.compiler }} \
7676
-DCMAKE_CXX_STANDARD=${{ matrix.cxx }} \
77+
-DCMAKE_CXX_COMPILER=clang++-${{ matrix.llvm_version }} \
7778
-DCMAKE_BUILD_TYPE=${{matrix.build_type}}
7879
- name: "build"
7980
run: cmake --build build --parallel 3
8081

8182
- name: "run test"
82-
if: ${{ false }} # disabled, because of Github runner image bug in compiler-vs-stdlib
8383
run: ./build/test-boxed-cpp

CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ install(EXPORT boxed-cpp-targets
5252
# ---------------------------------------------------------------------------
5353
# unit tests
5454

55-
option(BOXED_CPP_TESTS "Enables building of unittests for boxed-cpp [default: OFF]" OFF)
56-
if(BOXED_CPP_TESTS)
55+
option(BOXED_TESTING "Enables building of unittests for boxed-cpp [default: OFF]" OFF)
56+
if(BOXED_TESTING)
5757
find_package(Catch2 3.4.0 QUIET)
5858
if(NOT Catch2_FOUND)
5959
ThirdPartiesAdd_Catch2()
@@ -62,7 +62,8 @@ if(BOXED_CPP_TESTS)
6262
add_executable(test-boxed-cpp
6363
test-boxed-cpp.cpp
6464
)
65+
target_compile_features(test-boxed-cpp INTERFACE cxx_std_20)
6566
target_link_libraries(test-boxed-cpp boxed-cpp Catch2::Catch2WithMain)
6667
add_test(test-boxed-cpp ./test-boxed-cpp)
6768
endif()
68-
message(STATUS "[boxed-cpp] Compile unit tests: ${BOXED_CPP_TESTS}")
69+
message(STATUS "[boxed-cpp] Compile unit tests: ${BOXED_TESTING}")

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@ Example of creation boxed structures and usage
1717
#include <boxed-cpp/boxed.hpp>
1818

1919
// Create unique structures
20-
namespace tags { struct Speed{}; struct Permittivity{}; struct Permeability{}; }
21-
22-
using Speed = boxed::boxed<double, tags::Speed>;
23-
using Permittivity = boxed::boxed<double, tags::Permittivity>;
24-
using Permeability = boxed::boxed<double, tags::Permeability>;
2520

21+
using Speed = boxed::boxed<double>;
22+
using Permittivity = boxed::boxed<double>;
23+
using Permeability = boxed::boxed<double>;
2624

2725
int main()
2826
{
@@ -36,6 +34,9 @@ int main()
3634

3735
auto speed = wave_speed(vacuum_permittivity, vacuum_permeability);
3836
// speed == Speed(299792458.0);
37+
38+
// Wrong order of parameters will result in compilation error
39+
// wave_speed(vacuum_permeability, vacuum_permittivity);
3940
}
4041

4142
```
@@ -62,13 +63,13 @@ double value_d = speed_of_light * 2.0;
6263
```
6364

6465

65-
# More advanced usage
66-
You can forget about the order of parameters in your code. Complete code see: [godbolt](https://godbolt.org/z/K4r9d9far)
66+
# More examples of usage
67+
You can crate functions that will automatically adjust order of parameters. Complete code see: [godbolt](https://godbolt.org/z/aqobbcGe6)
6768

6869
``` c++
69-
using rho_type = boxed::boxed<double,Tag::Rho>;
70-
using theta_type = boxed::boxed<double,Tag::Theta>;
71-
using phi_type = boxed::boxed<double,Tag::Phi>;
70+
using rho_type = boxed::boxed<double>;
71+
using theta_type = boxed::boxed<double>;
72+
using phi_type = boxed::boxed<double>;
7273

7374
template <typename... F>
7475
struct overload: F...{ using F::operator()...;};
@@ -89,7 +90,6 @@ struct Wrap
8990
}
9091
};
9192

92-
9393
auto x_coord = Wrap([](rho_type rho){ return unbox(rho); },
9494
[](theta_type theta){ return sin(unbox(theta)); },
9595
[](phi_type phi){ return cos(unbox(phi)); }
@@ -101,9 +101,9 @@ int main()
101101
theta_type theta{3.14 / 3.0};
102102
phi_type phi{3.14/2.0};
103103

104-
assert(x_coord(rho,theta,phi) == x_coord(theta,rho,phi));
105-
assert(x_coord(rho,theta,phi) == x_coord(phi,rho,theta));
106-
assert(x_coord(rho,theta,phi) == x_coord(phi,rho,theta));
104+
std::cout << x_coord(rho,theta,phi) << std::endl; // 0.000689428
105+
std::cout << x_coord(phi,theta,rho) << std::endl; // 0.000689428
106+
std::cout << x_coord(rho,phi,theta) << std::endl; // 0.000689428
107107
}
108108
```
109109

0 commit comments

Comments
 (0)