Home

Awesome

compile_time Build Status

compile_time is a bag-of-tricks which allows the user to perform computation at compile time. The project requires C++11. To use compile_time in your project, clone the project and add the include directory to your include path.

The functions provided in this library can be evaluated both at compile and run times but it is strongly discouraged that you use these at run time since the performance is likely to be extremely poor as compared to an implementation done specifically for run time.

Dependencies

Usage

Please have a look at the tests for the header you want to use.

Available Functions

Math

Strings

Demo

// demo.cpp
#include <cmath>
#include "compile_time/math.hpp"

namespace CT = compile_time;

int main() {
    constexpr auto x     = 1.2;
    constexpr auto sin_1 = CT::sin(x); // evaluates at compile_time
    auto           sin_2 = CT::sin(x); // compiler decides when to evaluate
    volatile auto  sin_3 = CT::sin(x); // evaluates at runtime
    auto           sin_4 =   ::sin(x); // cmath sin, evaluates at runtime
    return (int)(sin_1 + sin_2 + sin_3 + sin_4); // to ensure the vars are not optimized out
}

Here is a call log of the program showing the functions called (generated using valgrind) Valgrind output

Code Guidelines

Every function: