close
Skip to content

bemanproject/cache_latest

Repository files navigation

beman.cache_latest: A Beman Library

Library Status Continuous Integration Tests Lint Check (pre-commit) Coverage Standard Target

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.

Implements: std::views::cache_latest proposed in P3138 views::cache_latest and in the working draft for C++26.

Status: Under development and not yet ready for production use.

License

beman.cache_latest is licensed under the Apache License v2.0 with LLVM Exceptions.

Usage

The following code snippet illustrates using beman::cache_latest:

#include <beman/cache_latest/cache_latest.hpp>

int main()
{
    std::vector<int> v = {1, 2, 3, 4, 5};

    auto even_squares = v
        | std::views::transform([](int i){
                std::print("transform: {}\n", i);
                return i * i;
            })
        | beman::cache_latest
        | std::views::filter([](int i){
                std::print("filter: {}\n", i);
                return i % 2 == 0;
            });

    for (int i : even_squares) {
        std::print("Got: {}\n", i);
    }
}

Full runnable examples can be found in examples/.

Dependencies

Build Environment

This project requires at least the following to build:

  • A C++ compiler that conforms to the C++23 standard or greater
  • CMake 3.30 or later
  • (Test Only) GoogleTest

You can disable building tests by setting CMake option BEMAN_CACHE_LATEST_BUILD_TESTS to OFF when configuring the project.

Supported Platforms

Compiler Version C++ Standards Standard Library
GCC 15-14 C++26, C++23 libstdc++
Clang 20-19 C++26, C++23 libstdc++, libc++

Development

See the Contributing Guidelines.

Integrate beman.cache_latest into your project

Build

You can build cache_latest using a CMake workflow preset:

cmake --workflow --preset gcc-release

To list available workflow presets, you can invoke:

cmake --list-presets=workflow

For details on building beman.cache_latest without using a CMake preset, refer to the Contributing Guidelines.

Installation

To install beman.cache_latest globally after building with the gcc-release preset, you can run:

sudo cmake --install build/gcc-release

Alternatively, to install to a prefix, for example /opt/beman, you can run:

sudo cmake --install build/gcc-release --prefix /opt/beman

This will generate the following directory structure:

/opt/beman
├── include
│   └── beman
│       └── cache_latest
│           ├── cache_latest.hpp
│           └── ...
└── lib
    └── cmake
        └── beman.cache_latest
            ├── beman.cache_latest-config-version.cmake
            ├── beman.cache_latest-config.cmake
            └── beman.cache_latest-targets.cmake

CMake Configuration

If you installed beman.cache_latest to a prefix, you can specify that prefix to your CMake project using CMAKE_PREFIX_PATH; for example, -DCMAKE_PREFIX_PATH=/opt/beman.

You need to bring in the beman.cache_latest package to define the beman::cache_latest CMake target:

find_package(beman.cache_latest REQUIRED)

You will then need to add beman::cache_latest to the link libraries of any libraries or executables that include beman.cache_latest headers.

target_link_libraries(yourlib PUBLIC beman::cache_latest)

Using beman.cache_latest

To use beman.cache_latest in your C++ project, include an appropriate beman.cache_latest header from your source code.

#include <beman/cache_latest/cache_latest.hpp>

Note

beman.cache_latest headers are to be included with the beman/cache_latest/ prefix. Altering include search paths to spell the include target another way (e.g. #include <cache_latest.hpp>) is unsupported.

Contributing

Please do! You encourage you to checkout our contributor's guide. Issues and pull requests are appreciated.

About

views::cache_latest for C++26

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors