Is there any kind of “expression class” (C++)

前端 未结 9 1433
眼角桃花
眼角桃花 2020-12-13 14:45

I am creating a game that lets the player enter input, changes some states, then checks if a \"goal value\" is true (obviously this description is muchly simplified), and I

9条回答
  •  渐次进展
    2020-12-13 15:23

    Static expressions

    (amendment to Macke's post)

    When your expressions are known at compile time, you can use std::function. However, the performance might not be optimal.

    You can automatically register test at compile-time and execute them at run-time with (presumambly) minimal runtime overhead, using C++11 templates and macros. A proof-of-concept implementation can be found here.

    In the long run, a language feature named "Contracts" could do the job. (N4415, N4435, N4378) Today, there are various libraries available to support contract programming.

提交回复
热议问题