Skip to content
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
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
infra/** linguist-vendored
cookiecutter/** linguist-vendored
*.bib -linguist-detectable
*.tex -linguist-detectable
papers/* linguist-documentation
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 5 additions & 11 deletions .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -78,15 +78,15 @@ 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'"
- platform:
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"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 }}
Expand Down
73 changes: 73 additions & 0 deletions .github/workflows/reusable-beman-pre-commit.yml
Original file line number Diff line number Diff line change
@@ -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"
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
/compile_commands.json
/build

# ignore emacs temp files
*~
\#*\#

# ignore vscode settings
.vscode
1 change: 1 addition & 0 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 6 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
)
Expand Down
2 changes: 1 addition & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/${presetName}",
"cacheVariables": {
"CMAKE_CXX_STANDARD": "20"
"CMAKE_CXX_STANDARD": "23"
}
},
{
Expand Down
46 changes: 13 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-->

<!-- markdownlint-disable-next-line line-length -->
![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.
<!-- markdownlint-disable-next-line line-length -->
`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).
<!-- markdownlint-disable-next-line line-length -->
**Implements**: `std::views::cache_latest` proposed in [P3138 `views::cache_latest`](https://wg21.link/P3138) and in the working draft for C++26.

<!-- markdownlint-disable-next-line line-length -->
**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 <include/beman/cache_latest.hpp>
Expand Down Expand Up @@ -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,
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
set(BEMAN_EXEMPLAR_VERSION @PROJECT_VERSION@)


set(BEMAN_CACHE_LAST_VERSION @PROJECT_VERSION@)

@PACKAGE_INIT@

Expand Down
24 changes: 7 additions & 17 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
6 changes: 2 additions & 4 deletions examples/identity_direct_usage.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <beman/exemplar/identity.hpp>
#include <beman/cache_latest/cache_latest.hpp>

#include <iostream>

namespace exe = beman::exemplar;

int main() {
std::cout << exe::identity()(2024) << '\n';
std::cout << "hello" << '\n';
return 0;
}
6 changes: 6 additions & 0 deletions include/beman/cache_latest/cache_latest.hpp
Original file line number Diff line number Diff line change
@@ -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 <ranges>
#include <optional>
#include <type_traits>
Expand Down
1 change: 0 additions & 1 deletion src/beman/cache_latest/cache_latest.cpp
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
#include <beman/cache_latest/cache_latest.hpp>

6 changes: 5 additions & 1 deletion tests/beman/cache_latest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading