|
Boost : |
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2008-05-02 19:25:19
AMDG
Simonson, Lucanus J wrote:
> I think providing both compile time and runtime
> accessors is fine. The runtime accessors can be implemented in terms of
> the compile time ones in the cases where the type doesn't provide
> indexing (such as a tuple based point.) People wanting better
> performance with the runtime accessor can specialize it where
> appropriate.
>
Cool.
>> Have you measured the performance when adapting a struct like this:
>> struct Point {
>> int x;
>> int y;
>> };
>>
>
> Yes, when compiled with optimization it is identical to access the
> struct members directly or through the accessors (and the extra wrapper
> class from the original design as well.) Please note: if you forget to
> use the result of your computation, dead code removal leads to a
> misleading result because the compiler is more successful in removing
> dead code in the case where there is less to be removed, so take care
> confirming my result.
>
Ok. There might be extra optimizations possible when the index is known
at compile time as opposed to run time. (I'm not talking about the
difference
between get<X>(p) and p[X], here, but the difference between when X is
known at compile time using templates to avoid code duplication vs. runtime.
and using function arguments). This is really a property of the
algorithm rather
than the point class, though.
In Christ,
Steven Watanabe
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk