Header only expression template interface for vector types in C++.
- Do straightforward arithmetic operations with vector types (class only needs constructor(size), size() and operator[] methods) using operator overloading (+,-,*,/)
- Lazy evaluate only the needed results (no internal caching). Other than that, you can chain expresssions to your liking, without any additional runtime cost !
Here is example of what you can do:
#include "lazyval.h"
using namespace Lazy;
auto a = std::vector<float>(48, 6);
// Create templated symbolic expression tree
auto t = 4 * (a + a + a + a + 4) / std::vector<float>(48, 6);
// Evaluate only t[4]
std::cout << t[4];
// Evaluate the whole vector, use this if you need to cache/get all the results.
std::vector<float> v = t;
The size is always equal to the smallest vector in the whole expression tree. Scalars apply to all elements, but don't affect the size.
For forced evaluation or conversion, please use either conversion operator or eval() member method.
If you want to apply a lambda over 1 - 3 operands, use map() functions.
Ternary operator is possible using cond() function.
Works with C++17 and GCC, Clang. (Maybe MSVC too...)