|
std 1.0.1
The f64 CEL standard library
|
This tutorial shows C++ developers how to install the library, compile expressions, and retrieve scalar and tuple results. For individual operation semantics, use the CEL language book's standard library.
Use a C++20 compiler with IEEE 754 binary64 double, CMake 3.24 or later, and CPM. Configure and build the library as described in the README. The library depends on cel::parser, which supplies cel::runtime. You do not need a separate runtime dependency declaration.
The following complete program is built and run by the test suite:
The program prints:
For a multi-configuration generator, select the build configuration when building and running tests:
sqrt(9.0) and 9.0.sqrt() select the same operation. The receiver is the first operand: atan2(y, x) is also y.atan2(x). The installed functions remain available inside CEL closure bodies.
sin_cos produces a structural CEL tuple, not an opaque C++ object. Prepare it as std::tuple<double, double>, as the example shows. In CEL, sin_cos(0.0).0 selects sine and .1 selects cosine. The program owns its emitted operations and can outlive the parser. The caller supplies exclusive access to each stack during execution.
The parser rejects unsupported operand types, arities, and names during compilation with cel::parse_error. Integer and f32 overloads and powi are not installed.
During evaluation, clamp throws std::invalid_argument("invalid clamp bounds") for reversed or NaN bounds. Other floating-point domain failures return NaN or infinity as specified by the language book; they do not become new C++ evaluation exceptions. Allocation and dependency failures propagate to the caller.
Install the library once per lookup. Existing registrations with disjoint signatures remain usable; installation is not transactional if registration fails.
To install a release build, run:
Replace /PATH/TO/PREFIX with your installation prefix. This installs the standard library and its parser/runtime dependencies.
In the consuming project, find the package and link its exported target:
Replace your_app with your executable target. Pass the installation prefix as -DCMAKE_PREFIX_PATH=/PATH/TO/PREFIX when configuring the consumer. Verify that the example produces the output shown in this tutorial.
See the library reference for the complete retained signature table.