unexpected abstraction penalty in C++

From: alex goldman (hello_at_spamm.er)
Date: 05/29/05


Date: Sun, 29 May 2005 00:58:01 -0700

class c {
    int x;
public:
    inline c() : x(0) {}
    inline c(int i) { x = i; }
    inline operator const int& () const { return x; }
    inline operator int& () { return x; }
};

If I use objects of type `c' as if they were int's, I see about 1.5x
slow-down compared to using regular int's (timed using GCC-3.3.4 -O3). Is
it reasonable to expect modern compilers to optimize this, so that there is
no abstraction penalty?



Relevant Pages