Library for creating deferred evaluation expressions in C++23.
deferred provides:
- functions to declare constants and variables,
- functions to create deferred evaluation expressions from functions,
deferred-enabled commonly used operators.
- C++23 capable compiler.
- CMake 3.28.1 and higher.
Compilers tested:
- Clang 16.0.0 (macOS)
- GCC 13.3.0 (Ubuntu)
- MSVC 19.44 (Windows)
Standard CMake build process:
mkdir build
cd build
cmake ..
cmake --build .The library is header-only. You can:
- Copy the
include/deferreddirectory to your project. - Install via CMake:
cmake --install build --prefix /path/to/install
- Use as a sub-project in CMake:
add_subdirectory(deferred) target_link_libraries(my_target PRIVATE deferred::deferred)
Generate documentation with Doxygen:
# From the build directory
cmake --build . --target documentationThe output will be in the build/html directory.
// examples/trivial/main.cpp
#include <iostream>
#include <deferred/deferred.hpp>
int main()
{
auto v = deferred::variable<int>();
auto x = deferred::constant(2);
auto y = deferred::constant(3);
auto expression = (v * x) + y;
v = 10;
auto res = expression();
std::cout << res << "==" << (10 * 2) + 3 << '\n';
return 0;
}Examples can be found in the examples/ directory. They are compiled by default.
Tests are written using Catch2 v3. To run tests after building:
ctest --output-on-failure- Using callable objects and functions with side-effects in
invoke()andif_then_else()will result in a constant expression, assignable toconstant_. - Using
deferredwith other expression template based classes (e.g.,std::valarray) may not be possible.