Re: [boost] Geometry/Vector Lib

In-Reply-To: <20060922201042.GO21158@lie.Stanford.EDU> irving@cs.stanford.edu (Geoffrey Irving) wrote (abridged):
Especially if you can make it a static assert (which I'm not sure of).
Making it a static assert is not straightforward because addresses are not compile-time constants. The straightforward way to compute offsets is by subtracting addresses. -- Dave Harris, Nottingham, UK.

On Sat, Sep 23, 2006 at 04:53:00PM +0100, Dave Harris wrote:
In-Reply-To: <20060922201042.GO21158@lie.Stanford.EDU> irving@cs.stanford.edu (Geoffrey Irving) wrote (abridged):
Especially if you can make it a static assert (which I'm not sure of).
Making it a static assert is not straightforward because addresses are not compile-time constants. The straightforward way to compute offsets is by subtracting addresses.
I wasn't asking whether it was straightforward, just possible. This should work: template<class T> class vectorN { public: T x1, x2, ..., xN; T& operator[](unsigned int i) {assert(i<Nu);return (&x1)[i];} private: struct checker:public vectorN { T padding[256-N]; } BOOST_STATIC_ASSERT((sizeof(checker)==256*sizeof(T))); }; Since elements of arrays are required to be in contiguous memory locations, the variables x1 through xN must also be contigous if the static assert passes. I don't know if this is a necessary condition, but it's certainly sufficient. Here I'm assuming that the compiler aligns to at most 256 bytes. Geoffrey
participants (2)
-
brangdon@cix.compulink.co.uk
-
Geoffrey Irving