What's the best way to force the user of a C++ function to acknowledge the semantic meaning of parameters that are numerical constants?

后端 未结 7 2083
故里飘歌
故里飘歌 2021-02-13 15:27

I\'d like to write function interfaces that force the user to acknowledge the semantic meaning of built-in constants. For example, I\'d like to take

void rotate(         


        
7条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-13 15:48

    It is absolutely possible to write OOP code that is as efficient as the procedural code. Even more, sometimes you can gain surprising speedups if you take advantage of the added semantics or class-based code. One of the great examples of such an advantage is std::swap. Yes, use templates ;).

    What makes it possible to write an effective Radian class is inlining. However, use it wisely!

    Checklist:

    • read about efficient inlining
    • take care to have an explicit constructor
    • take care to properly use the keyword const where applicable
    • read about Optimizing C++
    • finally, if you do a lot of expressions involving your class, google up about Expression Templates

提交回复
热议问题