Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor polishing #14

Merged
merged 9 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
---
BasedOnStyle: Microsoft
AccessModifierOffset: '-2'
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: 'true'
AlignConsecutiveDeclarations: 'false'
AlignEscapedNewlines: Left
AlignOperands: 'true'
AlignTrailingComments: 'true'
AllowAllArgumentsOnNextLine: 'true'
AllowAllConstructorInitializersOnNextLine: 'true'
AllowAllParametersOfDeclarationOnNextLine: 'true'
AllowShortBlocksOnASingleLine: 'false'
AllowShortCaseLabelsOnASingleLine: 'true'
AllowShortFunctionsOnASingleLine: InlineOnly
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: Inline
AllowShortLoopsOnASingleLine: 'false'
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: 'false'
AlwaysBreakTemplateDeclarations: 'Yes'
BinPackArguments: 'false'
BinPackParameters: 'false'
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: 'true'
BreakConstructorInitializers: AfterColon
BreakInheritanceList: AfterColon
BreakStringLiterals: 'true'
ColumnLimit: '110'
CompactNamespaces: 'false'
ConstructorInitializerAllOnOneLineOrOnePerLine: 'true'
ConstructorInitializerIndentWidth: '4'
ContinuationIndentWidth: '4'
Cpp11BracedListStyle: 'false'
DerivePointerAlignment: 'false'
FixNamespaceComments: 'true'
IncludeBlocks: Regroup
IndentCaseLabels: true
IndentPPDirectives: BeforeHash
IndentWidth: '4'
IndentWrappedFunctionNames: 'false'
Language: Cpp
MaxEmptyLinesToKeep: '1'
NamespaceIndentation: Inner
PenaltyBreakAssignment: '0'
PointerAlignment: Left
ReflowComments: 'true'
SortIncludes: 'true'
SortUsingDeclarations: 'true'
SpaceAfterCStyleCast: 'true'
SpaceAfterLogicalNot: 'false'
SpaceAfterTemplateKeyword: 'true'
SpaceBeforeAssignmentOperators: 'true'
SpaceBeforeCpp11BracedList: 'true'
SpaceBeforeCtorInitializerColon: 'false'
SpaceBeforeInheritanceColon: 'false'
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: 'false'
SpaceInEmptyParentheses: 'false'
SpacesInAngles: 'false'
SpacesInCStyleCastParentheses: 'false'
SpacesInContainerLiterals: 'false'
SpacesInParentheses: 'false'
SpacesInSquareBrackets: 'false'
Standard: Cpp11
TabWidth: '4'
UseTab: Never
IncludeCategories:
- Regex: '^<(contour)/'
Priority: 0
- Regex: '^<(vtbackend)/'
Priority: 1
- Regex: '^<(vtparser)/'
Priority: 2
- Regex: '^<(vtpty)/'
Priority: 3
- Regex: '^<(vtrasterizer)/'
Priority: 4
- Regex: '^<(text_shaper)/'
Priority: 5
- Regex: '^<(crispy)/'
Priority: 6
- Regex: '^<(libunicode)/'
Priority: 40
- Regex: '^<(fmt)/'
Priority: 42
- Regex: '^<(yaml-cpp)/'
Priority: 44
- Regex: '^<(range)/'
Priority: 46
- Regex: '^<gsl/'
Priority: 48
- Regex: '^<fontconfig/'
Priority: 52
- Regex: '^<harfbuzz/'
Priority: 53
- Regex: '^<(QtCore|QtGui|QtDBus|QtWidgets|QtQml|QtQuick|QtNetwork|QtMultimedia)/'
Priority: 64
- Regex: '^<catch2/'
Priority: 70
- Regex: '^<sys/'
Priority: 80
- Regex: '^<[[:alnum:]_]+>'
Priority: 81
- Regex: '<[[:alnum:]_]+\.h>'
Priority: 82
- Regex: '.*'
Priority: 99
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,14 @@ insert_final_newline = true
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true

[LICENSE.txt]
end_of_line = unset
indent_size = unset
insert_final_newline = unset

[.clang-format]
indent_size = 2

[*.yml]
indent_size = 2
51 changes: 43 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,36 @@ on:
- master

jobs:
ubuntu_2204:
check_clang_format:
name: "Check C++ style"
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Run clang-format style check for C/C++/Protobuf programs.
uses: jidicula/[email protected]
with:
clang-format-version: '16'
check-path: '.'
#exclude-regex: 'sse2neon.h'

editorconfig:
name: "Check editorconfig"
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- uses: editorconfig-checker/action-editorconfig-checker@main
- run: editorconfig-checker

ubuntu:
strategy:
fail-fast: false
matrix:
cxx: [20]
build_type: ["RelWithDebInfo"]
compiler:
[
"g++-12",
"clang++-14"
"g++-11",
"clang++-15"
]
name: "Ubuntu 22.04 (${{ matrix.compiler }}, C++${{ matrix.cxx }}, ${{matrix.build_type}})"
runs-on: ubuntu-22.04
Expand All @@ -34,15 +54,30 @@ jobs:
- name: "update APT database"
run: sudo apt -q update

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

- name: "Download dependencies"
run: sudo apt install cmake ninja-build
run: sudo apt install cmake ninja-build # catch2
# workaround for broken clang on ubuntu runner until https://github.com/actions/runner-images/issues/8659 get fixed
#- uses: mjp41/workaround8649@7929373c0fe5caf844d8115adccef39e3b5362e7
- name: Install Compilers
run: sudo apt install -y g++-12
- name: "Cmake configure"
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}}
- name: "build "
run: |
cmake -S . -B build -G Ninja \
-DBOXED_CPP_TESTS=OFF \
-DENABLE_TIDY=ON \
-DPEDANTIC_COMPILER=ON \
-DCMAKE_CXX_FLAGS="-Wno-unknown-warning-option" \
-DCMAKE_CXX_COMPILER=${{ matrix.compiler }} \
-DCMAKE_CXX_STANDARD=${{ matrix.cxx }} \
-DCMAKE_BUILD_TYPE=${{matrix.build_type}}
- name: "build"
run: cmake --build build --parallel 3

- name: "run test"
if: ${{ false }} # disabled, because of Github runner image bug in compiler-vs-stdlib
run: ./build/test-boxed-cpp
7 changes: 3 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,15 @@ install(EXPORT boxed-cpp-targets

option(BOXED_CPP_TESTS "Enables building of unittests for boxed-cpp [default: OFF]" OFF)
if(BOXED_CPP_TESTS)
find_package(Catch2)
if (NOT Catch2_FOUND)
find_package(Catch2 3.4.0 QUIET)
if(NOT Catch2_FOUND)
ThirdPartiesAdd_Catch2()
endif()
enable_testing()
add_executable(test-boxed-cpp
test-boxed-cpp.cpp
test-main.cpp
)
target_link_libraries(test-boxed-cpp boxed-cpp Catch2::Catch2)
target_link_libraries(test-boxed-cpp boxed-cpp Catch2::Catch2WithMain)
add_test(test-boxed-cpp ./test-boxed-cpp)
endif()
message(STATUS "[boxed-cpp] Compile unit tests: ${BOXED_CPP_TESTS}")
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ struct Wrap


auto x_coord = Wrap([](rho_type rho){ return unbox(rho); },
[](theta_type theta){ return sin(unbox(theta)); },
[](phi_type phi){ return cos(unbox(phi)); }
[](theta_type theta){ return sin(unbox(theta)); },
[](phi_type phi){ return cos(unbox(phi)); }
);

int main()
Expand Down
4 changes: 2 additions & 2 deletions cmake/ThirdParties.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ macro(ThirdPartiesAdd_fmtlib)
endmacro()

macro(ThirdPartiesAdd_Catch2)
set(3rdparty_Catch2_VERSION "2.13.6" CACHE STRING "Embedded catch2 version")
set(3rdparty_Catch2_CHECKSUM "SHA256=48dfbb77b9193653e4e72df9633d2e0383b9b625a47060759668480fdf24fbd4" CACHE STRING "Embedded catch2 checksum")
set(3rdparty_Catch2_VERSION "3.4.0" CACHE STRING "Embedded catch2 version")
set(3rdparty_Catch2_CHECKSUM "SHA256=122928b814b75717316c71af69bd2b43387643ba076a6ec16e7882bfb2dfacbb" CACHE STRING "Embedded catch2 checksum")
set(3rdparty_Catch2_URL "https://github.com/catchorg/Catch2/archive/refs/tags/v${3rdparty_Catch2_VERSION}.tar.gz")
set(CATCH_BUILD_EXAMPLES OFF CACHE INTERNAL "")
set(CATCH_BUILD_EXTRA_TESTS OFF CACHE INTERNAL "")
Expand Down
56 changes: 33 additions & 23 deletions include/boxed-cpp/boxed.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once

#include <cstdint>
#include <type_traits>
#include <cassert>
#include <limits>
#include <iostream>
#include <limits>
#include <type_traits>

namespace boxed {
namespace boxed
{
// {{{ forward decls
template <typename T, typename Tag>
struct boxed;
Expand Down Expand Up @@ -38,8 +37,12 @@ constexpr bool is_boxed = helper::is_boxed<T>::value;
template <typename T, typename Tag>
struct boxed
{
static_assert(std::is_enum_v<T> || std::is_integral_v<T> || std::is_floating_point_v<T>,
"Boxing is only useful on integral & floating point types.");
// clang-format off
static_assert(
std::is_enum_v<T> || std::is_integral_v<T> || std::is_floating_point_v<T>,
"Boxing is only useful on integral & floating point types."
);
// clang-format on

using inner_type = T;
using element_type = T;
Expand All @@ -56,7 +59,7 @@ struct boxed

[[nodiscard]] constexpr T& get() noexcept { return value; }
[[nodiscard]] constexpr T const& get() const noexcept { return value; }
constexpr operator T() const && {return value;}
constexpr operator T() const&& { return value; }

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

template <typename T>
concept con_boxed = requires(T t)
{
typename T::inner_type;
};
concept con_boxed = requires(T t) { typename T::inner_type; };

// Casting a boxed type out of the box.
template <con_boxed T>
Expand Down Expand Up @@ -203,20 +203,30 @@ struct hash<boxed::boxed<T, U>>
};
} // namespace std
// {{{ fmtlib integration
// clang-format off
#if __has_include(<fmt/format.h>)

#include <fmt/format.h>
// clang-format on

namespace fmt
{
template <typename A, typename B>
struct formatter<boxed::boxed<A, B>> {
template <typename ParseContext>
constexpr auto parse(ParseContext& ctx) { return ctx.begin(); }
template <typename FormatContext>
auto format(const boxed::boxed<A, B> _value, FormatContext& ctx)
{
return fmt::format_to(ctx.out(), "{}", _value.value);
}
};
}

template <typename A, typename B>
struct formatter<boxed::boxed<A, B>>
{
template <typename ParseContext>
constexpr auto parse(ParseContext& ctx)
{
return ctx.begin();
}
template <typename FormatContext>
auto format(const boxed::boxed<A, B> _value, FormatContext& ctx)
{
return fmt::format_to(ctx.out(), "{}", _value.value);
}
};

} // namespace fmt
#endif
// }}}
Loading
Loading