geomc 1.0
A c++ linear algebra template library
|
Defines a type for storing a length or element count. More...
#include <geomc/Storage.h>
Public Types | |
typedef index_t | storage_t[0] |
Static Public Member Functions | |
static void | set (storage_t s, index_t v) |
Set the count (if stored in s ) to v . | |
static index_t | get (const storage_t s) |
Retrieve the count from s . | |
Defines a type for storing a length or element count.
Primarily for use in objects which may be either dynamically or statically sized according to a template parameter.
For statically-sized objects, no storage is needed for holding the length, since it is known at compile time. In the static case the storage type is a zero-length array. Dynamically-sized objects have runtime-determined length, and so one index_t
is needed to hold this value.
N | Count, or 0 if the count is to be determined at runtime. |
template <index_t N> class C { // this member will consume 0 bytes unless N is dynamic: typename Dimension<N>::storage_t size; // ... void setSize(index_t n) { // set `size` to `n` if N is dynamic, else do nothing. Dimension<N>::set(size,n); } index_t getSize(index_t n) { // return contents of `size` if N is dynamic, else N. return Dimension<N>::get(size); } }