In C ++, I am trying to write a wrapper around an integer of 64 bits. My assumption is that if correctly written and all methods are nested, such a wrapper should be as effective as the real type. The answer to this question on SO seems to agree with my expectation.
I wrote this code to test my expectation:
class B { private: uint64_t _v; public: inline B() {}; inline B(uint64_t v) : _v(v) {}; inline B& operator=(B rhs) { _v = rhs._v; return *this; }; inline B& operator+=(B rhs) { _v += rhs._v; return *this; }; inline operator uint64_t() const { return _v; }; }; int main(int argc, char* argv[]) { typedef uint64_t;
When I run this using typedef BT ; instead of typedef uint64_t T reported time was sequentially compiled with VC ++ 10% slower. With g ++, the characteristics are the same if I use the shell or not.
Since g ++ does this, I think there are no technical reasons why VC ++ cannot optimize it correctly. Is there something I can do to optimize it?
I already tried playing with the optimization flag without success
c ++ optimization visual-c ++ wrapper
Mathieu pagé
source share