C/C++ macro/template blackmagic to generate unique name

后端 未结 4 1528
孤城傲影
孤城傲影 2020-11-29 17:29

Macros are fine. Templates are fine. Pretty much whatever it works is fine.

The example is OpenGL; but the technique is C++ specific and relies on no knowledge of Op

4条回答
  •  一向
    一向 (楼主)
    2020-11-29 18:09

    I think it's now possible to do something like this:

    struct GlTranslate
    {
        operator()(double x,double y,double z, std::function f)
        {
            glPushMatrix(); glTranslatef(x, y, z);
            f();
            glPopMatrix();
        }
    };
    

    then in the code

    GlTranslate(x, y, z,[&]()
    {
    // your code goes here
    });
    

    Obviously, C++11 is needed

提交回复
热议问题