diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..793dce7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,5 @@ +infra/** linguist-vendored +cookiecutter/** linguist-vendored +*.bib -linguist-detectable +*.tex -linguist-detectable +papers/* linguist-documentation diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 022eaa3..a99da1c 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -20,4 +20,4 @@ # .pre-commit-config.yaml @wusatosi # Add other project owners here # .markdownlint.yaml @wusatosi # Add other project owners here -* @bretbrownjr @camio @dietmarkuehl @neatudarius @steve-downey @wusatosi +* @neatudarius @wusatosi @JeffGarland @changkhothuychung diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index 56c54a7..75451ab 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -66,7 +66,7 @@ jobs: - description: "Macos Appleclang" os: macos-latest toolchain: "cmake/appleclang-toolchain.cmake" - cpp_version: [17, 20, 23, 26] + cpp_version: [23, 26] cmake_args: - description: "Default" - description: "TSan" @@ -78,7 +78,7 @@ jobs: description: "Ubuntu GCC" os: ubuntu-latest toolchain: "cmake/gnu-toolchain.cmake" - cpp_version: 17 + cpp_version: 23 cmake_args: description: "Werror" args: "-DCMAKE_CXX_FLAGS='-Werror=all -Werror=extra'" @@ -86,7 +86,7 @@ jobs: description: "Ubuntu GCC" os: ubuntu-latest toolchain: "cmake/gnu-toolchain.cmake" - cpp_version: 17 + cpp_version: 23 cmake_args: description: "Dynamic" args: "-DBUILD_SHARED_LIBS=on" @@ -170,7 +170,7 @@ jobs: ninja --version - name: Configure CMake run: | - cmake -B build -S . -DCMAKE_CXX_STANDARD=17 ${{ matrix.args.arg }} + cmake -B build -S . -DCMAKE_CXX_STANDARD=23 ${{ matrix.args.arg }} env: CMAKE_GENERATOR: "Ninja Multi-Config" - name: Build Release @@ -196,18 +196,12 @@ jobs: compilers: - class: GNU version: 14 - - class: GNU - version: 13 - - class: GNU - version: 12 - class: LLVM version: 20 - class: LLVM version: 19 - class: LLVM version: 18 - - class: LLVM - version: 17 name: "Compiler: ${{ matrix.compilers.class }} ${{ matrix.compilers.version }}" steps: - uses: actions/checkout@v4 @@ -246,7 +240,7 @@ jobs: echo "CXX=$CXX" >> "$GITHUB_OUTPUT" - name: Configure CMake run: | - cmake -B build -S . -DCMAKE_CXX_STANDARD=20 + cmake -B build -S . -DCMAKE_CXX_STANDARD=23 env: CC: ${{ steps.install-compiler.outputs.CC }} CXX: ${{ steps.install-compiler.outputs.CXX }} diff --git a/.github/workflows/reusable-beman-pre-commit.yml b/.github/workflows/reusable-beman-pre-commit.yml new file mode 100644 index 0000000..1f3dc0f --- /dev/null +++ b/.github/workflows/reusable-beman-pre-commit.yml @@ -0,0 +1,73 @@ +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +name: 'Beman pre-commit check' +on: + workflow_call: +jobs: + pre-commit-push: + name: Pre-Commit check on Push + runs-on: ubuntu-latest + if: ${{ github.event_name == 'push' }} + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: 3.13 + + # We wish to run pre-commit on all files instead of the changes + # only made in the push commit. + # + # So linting error persists when there's formatting problem. + - uses: pre-commit/action@v3.0.1 + + pre-commit-pr: + name: Pre-Commit check on PR + runs-on: ubuntu-latest + if: ${{ github.event_name == 'pull_request_target' }} + + permissions: + contents: read + checks: write + issues: write + pull-requests: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # pull_request_target checkout the base of the repo + # We need to checkout the actual pr to lint the changes. + - name: Checkout pr + run: gh pr checkout ${{ github.event.number }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: 3.13 + + # we only lint on the changed file in PR. + - name: Get Changed Files + id: changed-files + uses: tj-actions/changed-files@v45 + + # See: + # https://github.com/tj-actions/changed-files?tab=readme-ov-file#using-local-git-directory- + - uses: pre-commit/action@v3.0.1 + id: run-pre-commit + with: + extra_args: --files ${{ steps.changed-files.outputs.all_changed_files }} + + # Review dog posts the suggested change from pre-commit to the pr. + - name: suggester / pre-commit + uses: reviewdog/action-suggester@v1 + if: ${{ failure() && steps.run-pre-commit.conclusion == 'failure' }} + with: + tool_name: pre-commit + level: warning + reviewdog_flags: "-fail-level=error" diff --git a/.gitignore b/.gitignore index 286a38e..0cb4a66 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,9 @@ /compile_commands.json /build + +# ignore emacs temp files +*~ +\#*\# + +# ignore vscode settings +.vscode diff --git a/.markdownlint.yaml b/.markdownlint.yaml index 81f5fcd..21c2849 100644 --- a/.markdownlint.yaml +++ b/.markdownlint.yaml @@ -7,3 +7,4 @@ MD033: false # Update the comment in .clang-format if we no-longer tie these two column limits. MD013: line_length: 119 + code_blocks: false diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ddba471..ec25e9f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,7 +13,7 @@ repos: # 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: v20.1.7 hooks: - id: clang-format types_or: [c++, c] @@ -27,10 +27,11 @@ repos: # Markdown linting # Config file: .markdownlint.yaml - - repo: https://github.com/igorshubovych/markdownlint-cli - rev: v0.42.0 - hooks: - - id: markdownlint + # Commented out to disable this by default. Uncomment to enable markdown linting. + # - repo: https://github.com/igorshubovych/markdownlint-cli + # rev: v0.42.0 + # hooks: + # - id: markdownlint - repo: https://github.com/codespell-project/codespell rev: v2.3.0 diff --git a/CMakeLists.txt b/CMakeLists.txt index f32c534..534b8f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ option( # [CMAKE.SKIP_EXAMPLES] option( - BEMAN_cache_latest_BUILD_EXAMPLES + BEMAN_CACHE_LATEST_BUILD_EXAMPLES "Enable building examples. Default: ON. Values: { ON, OFF }." ${PROJECT_IS_TOP_LEVEL} ) diff --git a/CMakePresets.json b/CMakePresets.json index 34d6e81..58d0983 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -7,7 +7,7 @@ "generator": "Ninja", "binaryDir": "${sourceDir}/build/${presetName}", "cacheVariables": { - "CMAKE_CXX_STANDARD": "20" + "CMAKE_CXX_STANDARD": "23" } }, { diff --git a/README.md b/README.md index 19662f4..2de20ce 100644 --- a/README.md +++ b/README.md @@ -5,21 +5,22 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception --> -![Library Status](https://raw.githubusercontent.com/bemanproject/beman/refs/heads/main/images/badges/beman_badge-beman_library_under_development.svg) ![Continuous Integration Tests](https://github.com/bemanproject/cache_latest/actions/workflows/ci_tests.yml/badge.svg) ![Lint Check (pre-commit)](https://github.com/bemanproject/cache_latest/actions/workflows/pre-commit.yml/badge.svg) +![Library Status](https://raw.githubusercontent.com/bemanproject/beman/refs/heads/main/images/badges/beman_badge-beman_library_under_development.svg) ![Continuous Integration Tests](https://github.com/bemanproject/cache_latest/actions/workflows/ci_tests.yml/badge.svg) ![Standard Target](https://github.com/bemanproject/beman/blob/main/images/badges/cpp26.svg) -`beman.cache_latest` is a minimal C++ library conforming to [The Beman Standard](https://github.com/bemanproject/beman/blob/main/docs/BEMAN_STANDARD.md). -This can be used as a template for those intending to write Beman libraries. -It may also find use as a minimal and modern C++ project structure. + +`beman.cache_latest` is a C++ ranges adaptor that caches the result of the last dereference of the underlying iterator. The reason for doing this is efficiency - specifically avoiding extra iterator dereferences. + +The library conforms to [The Beman Standard](https://github.com/bemanproject/beman/blob/main/docs/BEMAN_STANDARD.md). -**Implements**: `std::cache_latest` proposed in [Standard Library Concepts (P3138R3)](https://wg21.link/P3138R3). + +**Implements**: `std::views::cache_latest` proposed in [P3138 `views::cache_latest`](https://wg21.link/P3138) and in the working draft for C++26. + **Status**: [Under development and not yet ready for production use.](https://github.com/bemanproject/beman/blob/main/docs/BEMAN_LIBRARY_MATURITY_MODEL.md#under-development-and-not-yet-ready-for-production-use) ## Usage -`std::cache_latest` is a range adaptor type that caches the result of the last dereference of the underlying iterator - -The following code snippet illustrates how we can achieve a default projection using `beman::cache_latest`: +The following code snippet illustrates using `beman::cache_latest`: ```cpp #include @@ -52,8 +53,8 @@ int main() This project requires at least the following to build: -* C++17 -* CMake 3.25 +* C++23 +* CMake 3.28 This project pulls [Google Test](https://github.com/google/googletest) from GitHub as a development dependency for its testing framework, @@ -62,33 +63,12 @@ You can disable this behavior by setting cmake option [`BEMAN_CACHE_LATEST_BUILD_TESTS`](#beman_cache_latest_build_tests) to `OFF` when configuring the project. -However, -some examples and tests will not be compiled -unless provided compiler support **C++20** or ranges capabilities enabled. - -> [!TIP] -> -> In the logs you will be able to see if there are any examples that aren't enabled -> due to compiler capabilities or the configured C++ version. -> -> Below is an example: -> -> ```txt -> -- Looking for __cpp_lib_ranges -> -- Looking for __cpp_lib_ranges - not found -> CMake Warning at examples/CMakeLists.txt:12 (message): -> Missing range support! Skip: identity_as_default_projection -> -> -> Examples to be built: identity_direct_usage -> ``` - ### Supported Platforms This project officially supports: -* GNU GCC Compiler \[version 12-14\] -* LLVM Clang++ Compiler \[version 17-20\] +* GNU GCC Compiler \[version 14+\] +* LLVM Clang++ Compiler \[version 18-20\] * AppleClang compiler on Mac OS * MSVC compiler on Windows diff --git a/cmake/beman.exemplar-config.cmake.in b/cmake/beman.cache_last-config.cmake.in similarity index 71% rename from cmake/beman.exemplar-config.cmake.in rename to cmake/beman.cache_last-config.cmake.in index 5769cc3..98d849f 100644 --- a/cmake/beman.exemplar-config.cmake.in +++ b/cmake/beman.cache_last-config.cmake.in @@ -1,4 +1,6 @@ -set(BEMAN_EXEMPLAR_VERSION @PROJECT_VERSION@) + + +set(BEMAN_CACHE_LAST_VERSION @PROJECT_VERSION@) @PACKAGE_INIT@ diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 49aaf25..5211b8f 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -2,26 +2,16 @@ set(ALL_EXAMPLES identity_direct_usage) -# Example `identity_as_default_projection` need ranges support: -include(CheckCXXSymbolExists) -check_cxx_symbol_exists(__cpp_lib_ranges "ranges" HAS_RANGES) - -if(HAS_RANGES) - list(APPEND ALL_EXAMPLES identity_as_default_projection) -else() - message( - WARNING - "Missing range support! Skip: identity_as_default_projection" - ) -endif() - message("Examples to be built: ${ALL_EXAMPLES}") foreach(example ${ALL_EXAMPLES}) - add_executable(beman.exemplar.examples.${example}) - target_sources(beman.exemplar.examples.${example} PRIVATE ${example}.cpp) + add_executable(beman.cache_latest.examples.${example}) + target_sources( + beman.cache_latest.examples.${example} + PRIVATE ${example}.cpp + ) target_link_libraries( - beman.exemplar.examples.${example} - PRIVATE beman::exemplar + beman.cache_latest.examples.${example} + PRIVATE beman::cache_latest ) endforeach() diff --git a/examples/identity_direct_usage.cpp b/examples/identity_direct_usage.cpp index 236a63d..e850e5e 100644 --- a/examples/identity_direct_usage.cpp +++ b/examples/identity_direct_usage.cpp @@ -1,12 +1,10 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#include +#include #include -namespace exe = beman::exemplar; - int main() { - std::cout << exe::identity()(2024) << '\n'; + std::cout << "hello" << '\n'; return 0; } diff --git a/include/beman/cache_latest/cache_latest.hpp b/include/beman/cache_latest/cache_latest.hpp index c577120..128ea18 100644 --- a/include/beman/cache_latest/cache_latest.hpp +++ b/include/beman/cache_latest/cache_latest.hpp @@ -1,6 +1,12 @@ #ifndef BEMAN_CACHE_LATEST_H #define BEMAN_CACHE_LATEST_H +// clang-format off +#if __cplusplus < 202302L + #error "C++23 or later is required" +#endif +// clang-format on + #include #include #include diff --git a/src/beman/cache_latest/cache_latest.cpp b/src/beman/cache_latest/cache_latest.cpp index 153a97b..df45346 100644 --- a/src/beman/cache_latest/cache_latest.cpp +++ b/src/beman/cache_latest/cache_latest.cpp @@ -1,2 +1 @@ #include - diff --git a/tests/beman/cache_latest/CMakeLists.txt b/tests/beman/cache_latest/CMakeLists.txt index e15e5a5..654918c 100644 --- a/tests/beman/cache_latest/CMakeLists.txt +++ b/tests/beman/cache_latest/CMakeLists.txt @@ -3,7 +3,11 @@ include(GoogleTest) add_executable(beman.cache_latest.tests.cache_latest) -target_sources(beman.cache_latest.tests.cache_latest PRIVATE cache_latest.test.cpp) + +target_sources( + beman.cache_latest.tests.cache_latest + PRIVATE cache_latest.test.cpp +) target_link_libraries( beman.cache_latest.tests.cache_latest PRIVATE beman::cache_latest GTest::gtest GTest::gtest_main