Skip to content

evgeny-panasyuk/ctte

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

ctte

C++ compile-time template engine, proof-of-concept.

LIVE DEMO

Example #1

{
    int counter = 2;
    char character = '!';
    double value = 0.5;

    for_each_part
    (
        auto x,
        "val = $value$, cnt = $counter$, ch = $character$, again v=$value$;\n",
        counter, character, value
    )
    {
        print_it(x);
    };
}

Output is:

val = 0.5, cnt = 2, ch = !, again v=0.5;

Example #2

{
    int counter = 2;
    char character = '!';
    double value = 0.5;

    auto print = [](auto x)
    {
        print_it(x);
    };
    process_format
    (
        print,
        "val = $value$, cnt = $counter$, ch = $character$, again v=$value$;\n",
        counter, character, value
    );
}

Output is:

val = 0.5, cnt = 2, ch = !, again v=0.5;

Generated assembler code

Both examples produce same assembler code as following handwritten version:

{
    int counter = 2;
    char character = '!';
    double value = 0.5;

    print_it("val = ");
    print_it(value);
    print_it(", cnt = ");
    print_it(counter);
    print_it(", ch = ");
    print_it(character);
    print_it(", again v=");
    print_it(value);
    print_it(";\n");
}

Difference is only in identifier names, check ctte/proof_of_concept/*.asm.

About

C++ compile-time template engine

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published