Skip to content

Commit 74059da

Browse files
Merge pull request #14 from contour-terminal/minor-polishing
Minor polishing
2 parents 0e97186 + e4af94b commit 74059da

File tree

9 files changed

+274
-103
lines changed

9 files changed

+274
-103
lines changed

.clang-format

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
---
2+
BasedOnStyle: Microsoft
3+
AccessModifierOffset: '-2'
4+
AlignAfterOpenBracket: Align
5+
AlignConsecutiveMacros: 'true'
6+
AlignConsecutiveDeclarations: 'false'
7+
AlignEscapedNewlines: Left
8+
AlignOperands: 'true'
9+
AlignTrailingComments: 'true'
10+
AllowAllArgumentsOnNextLine: 'true'
11+
AllowAllConstructorInitializersOnNextLine: 'true'
12+
AllowAllParametersOfDeclarationOnNextLine: 'true'
13+
AllowShortBlocksOnASingleLine: 'false'
14+
AllowShortCaseLabelsOnASingleLine: 'true'
15+
AllowShortFunctionsOnASingleLine: InlineOnly
16+
AllowShortIfStatementsOnASingleLine: Never
17+
AllowShortLambdasOnASingleLine: Inline
18+
AllowShortLoopsOnASingleLine: 'false'
19+
AlwaysBreakAfterReturnType: None
20+
AlwaysBreakBeforeMultilineStrings: 'false'
21+
AlwaysBreakTemplateDeclarations: 'Yes'
22+
BinPackArguments: 'false'
23+
BinPackParameters: 'false'
24+
BreakBeforeBinaryOperators: NonAssignment
25+
BreakBeforeBraces: Custom
26+
BreakBeforeTernaryOperators: 'true'
27+
BreakConstructorInitializers: AfterColon
28+
BreakInheritanceList: AfterColon
29+
BreakStringLiterals: 'true'
30+
ColumnLimit: '110'
31+
CompactNamespaces: 'false'
32+
ConstructorInitializerAllOnOneLineOrOnePerLine: 'true'
33+
ConstructorInitializerIndentWidth: '4'
34+
ContinuationIndentWidth: '4'
35+
Cpp11BracedListStyle: 'false'
36+
DerivePointerAlignment: 'false'
37+
FixNamespaceComments: 'true'
38+
IncludeBlocks: Regroup
39+
IndentCaseLabels: true
40+
IndentPPDirectives: BeforeHash
41+
IndentWidth: '4'
42+
IndentWrappedFunctionNames: 'false'
43+
Language: Cpp
44+
MaxEmptyLinesToKeep: '1'
45+
NamespaceIndentation: Inner
46+
PenaltyBreakAssignment: '0'
47+
PointerAlignment: Left
48+
ReflowComments: 'true'
49+
SortIncludes: 'true'
50+
SortUsingDeclarations: 'true'
51+
SpaceAfterCStyleCast: 'true'
52+
SpaceAfterLogicalNot: 'false'
53+
SpaceAfterTemplateKeyword: 'true'
54+
SpaceBeforeAssignmentOperators: 'true'
55+
SpaceBeforeCpp11BracedList: 'true'
56+
SpaceBeforeCtorInitializerColon: 'false'
57+
SpaceBeforeInheritanceColon: 'false'
58+
SpaceBeforeParens: ControlStatements
59+
SpaceBeforeRangeBasedForLoopColon: 'false'
60+
SpaceInEmptyParentheses: 'false'
61+
SpacesInAngles: 'false'
62+
SpacesInCStyleCastParentheses: 'false'
63+
SpacesInContainerLiterals: 'false'
64+
SpacesInParentheses: 'false'
65+
SpacesInSquareBrackets: 'false'
66+
Standard: Cpp11
67+
TabWidth: '4'
68+
UseTab: Never
69+
IncludeCategories:
70+
- Regex: '^<(contour)/'
71+
Priority: 0
72+
- Regex: '^<(vtbackend)/'
73+
Priority: 1
74+
- Regex: '^<(vtparser)/'
75+
Priority: 2
76+
- Regex: '^<(vtpty)/'
77+
Priority: 3
78+
- Regex: '^<(vtrasterizer)/'
79+
Priority: 4
80+
- Regex: '^<(text_shaper)/'
81+
Priority: 5
82+
- Regex: '^<(crispy)/'
83+
Priority: 6
84+
- Regex: '^<(libunicode)/'
85+
Priority: 40
86+
- Regex: '^<(fmt)/'
87+
Priority: 42
88+
- Regex: '^<(yaml-cpp)/'
89+
Priority: 44
90+
- Regex: '^<(range)/'
91+
Priority: 46
92+
- Regex: '^<gsl/'
93+
Priority: 48
94+
- Regex: '^<fontconfig/'
95+
Priority: 52
96+
- Regex: '^<harfbuzz/'
97+
Priority: 53
98+
- Regex: '^<(QtCore|QtGui|QtDBus|QtWidgets|QtQml|QtQuick|QtNetwork|QtMultimedia)/'
99+
Priority: 64
100+
- Regex: '^<catch2/'
101+
Priority: 70
102+
- Regex: '^<sys/'
103+
Priority: 80
104+
- Regex: '^<[[:alnum:]_]+>'
105+
Priority: 81
106+
- Regex: '<[[:alnum:]_]+\.h>'
107+
Priority: 82
108+
- Regex: '.*'
109+
Priority: 99

.editorconfig

+11
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,14 @@ insert_final_newline = true
77
end_of_line = lf
88
charset = utf-8
99
trim_trailing_whitespace = true
10+
11+
[LICENSE.txt]
12+
end_of_line = unset
13+
indent_size = unset
14+
insert_final_newline = unset
15+
16+
[.clang-format]
17+
indent_size = 2
18+
19+
[*.yml]
20+
indent_size = 2

.github/workflows/build.yml

+43-8
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,36 @@ on:
99
- master
1010

1111
jobs:
12-
ubuntu_2204:
12+
check_clang_format:
13+
name: "Check C++ style"
14+
runs-on: ubuntu-22.04
15+
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'
23+
24+
editorconfig:
25+
name: "Check editorconfig"
26+
runs-on: ubuntu-22.04
27+
steps:
28+
- uses: actions/checkout@v2
29+
- uses: editorconfig-checker/action-editorconfig-checker@main
30+
- run: editorconfig-checker
31+
32+
ubuntu:
1333
strategy:
1434
fail-fast: false
1535
matrix:
1636
cxx: [20]
1737
build_type: ["RelWithDebInfo"]
1838
compiler:
1939
[
20-
"g++-12",
21-
"clang++-14"
40+
"g++-11",
41+
"clang++-15"
2242
]
2343
name: "Ubuntu 22.04 (${{ matrix.compiler }}, C++${{ matrix.cxx }}, ${{matrix.build_type}})"
2444
runs-on: ubuntu-22.04
@@ -34,15 +54,30 @@ jobs:
3454
- name: "update APT database"
3555
run: sudo apt -q update
3656

37-
- name: Install Compilers
38-
run: sudo apt install -y g++-11 clang-14
57+
- name: Set up Clang
58+
uses: egor-tensin/setup-clang@v1
59+
with:
60+
version: 15
3961

4062
- name: "Download dependencies"
41-
run: sudo apt install cmake ninja-build
63+
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
4268
- name: "Cmake configure"
43-
run: cmake -S . -B build -G Ninja -D BOXED_CPP_TESTS=ON -D ENABLE_TIDY=ON -DPEDANTIC_COMPILER=ON -D CMAKE_CXX_FLAGS="-Wno-unknown-warning-option" -DCMAKE_CXX_COMPILER=${{ matrix.compiler }} -DCMAKE_CXX_STANDARD=${{ matrix.cxx }} -DCMAKE_BUILD_TYPE=${{matrix.build_type}}
44-
- name: "build "
69+
run: |
70+
cmake -S . -B build -G Ninja \
71+
-DBOXED_CPP_TESTS=OFF \
72+
-DENABLE_TIDY=ON \
73+
-DPEDANTIC_COMPILER=ON \
74+
-DCMAKE_CXX_FLAGS="-Wno-unknown-warning-option" \
75+
-DCMAKE_CXX_COMPILER=${{ matrix.compiler }} \
76+
-DCMAKE_CXX_STANDARD=${{ matrix.cxx }} \
77+
-DCMAKE_BUILD_TYPE=${{matrix.build_type}}
78+
- name: "build"
4579
run: cmake --build build --parallel 3
4680

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

CMakeLists.txt

+3-4
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,15 @@ install(EXPORT boxed-cpp-targets
5454

5555
option(BOXED_CPP_TESTS "Enables building of unittests for boxed-cpp [default: OFF]" OFF)
5656
if(BOXED_CPP_TESTS)
57-
find_package(Catch2)
58-
if (NOT Catch2_FOUND)
57+
find_package(Catch2 3.4.0 QUIET)
58+
if(NOT Catch2_FOUND)
5959
ThirdPartiesAdd_Catch2()
6060
endif()
6161
enable_testing()
6262
add_executable(test-boxed-cpp
6363
test-boxed-cpp.cpp
64-
test-main.cpp
6564
)
66-
target_link_libraries(test-boxed-cpp boxed-cpp Catch2::Catch2)
65+
target_link_libraries(test-boxed-cpp boxed-cpp Catch2::Catch2WithMain)
6766
add_test(test-boxed-cpp ./test-boxed-cpp)
6867
endif()
6968
message(STATUS "[boxed-cpp] Compile unit tests: ${BOXED_CPP_TESTS}")

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ struct Wrap
9191

9292

9393
auto x_coord = Wrap([](rho_type rho){ return unbox(rho); },
94-
[](theta_type theta){ return sin(unbox(theta)); },
95-
[](phi_type phi){ return cos(unbox(phi)); }
94+
[](theta_type theta){ return sin(unbox(theta)); },
95+
[](phi_type phi){ return cos(unbox(phi)); }
9696
);
9797

9898
int main()

cmake/ThirdParties.cmake

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ macro(ThirdPartiesAdd_fmtlib)
4747
endmacro()
4848

4949
macro(ThirdPartiesAdd_Catch2)
50-
set(3rdparty_Catch2_VERSION "2.13.6" CACHE STRING "Embedded catch2 version")
51-
set(3rdparty_Catch2_CHECKSUM "SHA256=48dfbb77b9193653e4e72df9633d2e0383b9b625a47060759668480fdf24fbd4" CACHE STRING "Embedded catch2 checksum")
50+
set(3rdparty_Catch2_VERSION "3.4.0" CACHE STRING "Embedded catch2 version")
51+
set(3rdparty_Catch2_CHECKSUM "SHA256=122928b814b75717316c71af69bd2b43387643ba076a6ec16e7882bfb2dfacbb" CACHE STRING "Embedded catch2 checksum")
5252
set(3rdparty_Catch2_URL "https://github.com/catchorg/Catch2/archive/refs/tags/v${3rdparty_Catch2_VERSION}.tar.gz")
5353
set(CATCH_BUILD_EXAMPLES OFF CACHE INTERNAL "")
5454
set(CATCH_BUILD_EXTRA_TESTS OFF CACHE INTERNAL "")

include/boxed-cpp/boxed.hpp

+33-23
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
// SPDX-License-Identifier: Apache-2.0
22
#pragma once
33

4-
#include <cstdint>
5-
#include <type_traits>
6-
#include <cassert>
7-
#include <limits>
84
#include <iostream>
5+
#include <limits>
6+
#include <type_traits>
97

10-
namespace boxed {
8+
namespace boxed
9+
{
1110
// {{{ forward decls
1211
template <typename T, typename Tag>
1312
struct boxed;
@@ -38,8 +37,12 @@ constexpr bool is_boxed = helper::is_boxed<T>::value;
3837
template <typename T, typename Tag>
3938
struct boxed
4039
{
41-
static_assert(std::is_enum_v<T> || std::is_integral_v<T> || std::is_floating_point_v<T>,
42-
"Boxing is only useful on integral & floating point types.");
40+
// clang-format off
41+
static_assert(
42+
std::is_enum_v<T> || std::is_integral_v<T> || std::is_floating_point_v<T>,
43+
"Boxing is only useful on integral & floating point types."
44+
);
45+
// clang-format on
4346

4447
using inner_type = T;
4548
using element_type = T;
@@ -56,7 +59,7 @@ struct boxed
5659

5760
[[nodiscard]] constexpr T& get() noexcept { return value; }
5861
[[nodiscard]] constexpr T const& get() const noexcept { return value; }
59-
constexpr operator T() const && {return value;}
62+
constexpr operator T() const&& { return value; }
6063

6164
template <typename To>
6265
[[nodiscard]] constexpr auto as() const noexcept
@@ -158,10 +161,7 @@ constexpr auto unbox(boxed::boxed<From, FromTag> const& from) noexcept
158161
}
159162

160163
template <typename T>
161-
concept con_boxed = requires(T t)
162-
{
163-
typename T::inner_type;
164-
};
164+
concept con_boxed = requires(T t) { typename T::inner_type; };
165165

166166
// Casting a boxed type out of the box.
167167
template <con_boxed T>
@@ -203,20 +203,30 @@ struct hash<boxed::boxed<T, U>>
203203
};
204204
} // namespace std
205205
// {{{ fmtlib integration
206+
// clang-format off
206207
#if __has_include(<fmt/format.h>)
208+
207209
#include <fmt/format.h>
210+
// clang-format on
211+
208212
namespace fmt
209213
{
210-
template <typename A, typename B>
211-
struct formatter<boxed::boxed<A, B>> {
212-
template <typename ParseContext>
213-
constexpr auto parse(ParseContext& ctx) { return ctx.begin(); }
214-
template <typename FormatContext>
215-
auto format(const boxed::boxed<A, B> _value, FormatContext& ctx)
216-
{
217-
return fmt::format_to(ctx.out(), "{}", _value.value);
218-
}
219-
};
220-
}
214+
215+
template <typename A, typename B>
216+
struct formatter<boxed::boxed<A, B>>
217+
{
218+
template <typename ParseContext>
219+
constexpr auto parse(ParseContext& ctx)
220+
{
221+
return ctx.begin();
222+
}
223+
template <typename FormatContext>
224+
auto format(const boxed::boxed<A, B> _value, FormatContext& ctx)
225+
{
226+
return fmt::format_to(ctx.out(), "{}", _value.value);
227+
}
228+
};
229+
230+
} // namespace fmt
221231
#endif
222232
// }}}

0 commit comments

Comments
 (0)