diff --git a/.clang-format b/.clang-format index 2d264bf..4006393 100644 --- a/.clang-format +++ b/.clang-format @@ -1,6 +1,8 @@ --- -Language: Cpp BasedOnStyle: LLVM +IndentWidth: 2 +--- +Language: Cpp AccessModifierOffset: -2 AlignAfterOpenBracket: Align AlignArrayOfStructures: None @@ -89,11 +91,11 @@ IfMacros: - KJ_IF_MAYBE IncludeBlocks: Preserve IncludeCategories: - - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + - Regex: '^"(beman|llvm|llvm-c|clang|clang-c)/' Priority: 2 SortPriority: 0 CaseSensitive: false - - Regex: '^(<|"(gtest|gmock|isl|json)/)' + - Regex: '^(<|"(catch2|gtest|gmock|isl|json)/)' Priority: 3 SortPriority: 0 CaseSensitive: false diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index e1662e7..a9deb40 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,16 +1,16 @@ // For format details, see https://aka.ms/devcontainer.json. For config options, see the -// README at: https://github.com/devcontainers/templates/tree/main/src/cpp + // README at: https://github.com/devcontainers/templates/tree/main/src/cpp -{ - "name": "Beman Project Generic Devcontainer", - "image": "ghcr.io/bemanproject/devcontainers-gcc:14", - "postCreateCommand": "pre-commit", - "customizations": { - "vscode": { - "extensions": [ - "ms-vscode.cpptools", - "ms-vscode.cmake-tools" - ] - } - } -} + { + "name": "Beman Project Generic Devcontainer", + "image": "ghcr.io/bemanproject/devcontainers-gcc:14", + "postCreateCommand": "pre-commit", + "customizations": { + "vscode": { + "extensions": [ + "ms-vscode.cpptools", + "ms-vscode.cmake-tools" + ] + } + } + } diff --git a/.gitignore b/.gitignore index 4957963..2deb68a 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ # Miscellaneous build and testing folders build/ +compile_commands.json # Loose files .DS_Store diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ba8f774..8bc6d2d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,30 +2,39 @@ # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v5.0.0 + rev: v6.0.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer - id: check-yaml + exclude: ^\.clang-(format|tidy)$ - id: check-added-large-files # Clang-format for C++ # This brings in a portable version of clang-format. # See also: https://github.com/ssciwr/clang-format-wheel - repo: https://github.com/pre-commit/mirrors-clang-format - rev: v18.1.8 + rev: v21.1.6 hooks: - id: clang-format - types_or: [c++, c] + types_or: [c++, c, json] + + # # CMake linting and formatting + # - repo: https://github.com/BlankSpruce/gersemi + # rev: 0.23.1 + # hooks: + # - id: gersemi + # name: CMake linting + # exclude: ^.*/tests/.*/data/ # Exclude test data directories # Markdown linting # Config file: .markdownlint.yaml - repo: https://github.com/igorshubovych/markdownlint-cli - rev: v0.42.0 + rev: v0.46.0 hooks: - id: markdownlint - repo: https://github.com/codespell-project/codespell - rev: v2.3.0 + rev: v2.4.1 hooks: - id: codespell diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d0e4e8..9b475de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -cmake_minimum_required(VERSION 3.28) +cmake_minimum_required(VERSION 3.28...4.2) include(cmake/bootstrap_vcpkg.cmake) diff --git a/examples/cartesian_plane.cpp b/examples/cartesian_plane.cpp index d73c231..5e2fb55 100644 --- a/examples/cartesian_plane.cpp +++ b/examples/cartesian_plane.cpp @@ -9,6 +9,8 @@ import beman.bounds_test; namespace bt = beman::bounds_test; +namespace { + template concept SignedNumber = std::is_arithmetic_v && std::is_signed_v; @@ -28,22 +30,26 @@ constexpr auto try_reflect_y_axis(Point& p) noexcept { return bt::can_negate(p.x) ? std::optional>{std::in_place, static_cast(-p.x), p.y} : std::nullopt; } +} // namespace + int main() { auto test_reflect = [&](auto& pt) { std::cout << "Original: (" << pt.x << ", " << pt.y << ")\n"; - if (auto r = try_reflect_x_axis(pt)) + if (auto r = try_reflect_x_axis(pt)) { std::cout << "\tRefleted across X: (" << r->x << ", " << r->y << ")\n"; - else + } else { std::cout << "\tRefelction across X would cause overflow\n"; + } - if (auto r = try_reflect_y_axis(pt)) + if (auto r = try_reflect_y_axis(pt)) { std::cout << "\tRefleted across Y: (" << r->x << ", " << r->y << ")\n"; - else + } else { std::cout << "\tRefelction across Y would cause overflow\n"; + } }; - Point p{7, 15}; + Point p{.x = 7, .y = 15}; test_reflect(p); - Point q{12, std::numeric_limits::min()}; + Point q{.x = 12, .y = std::numeric_limits::min()}; test_reflect(q); }