geomc 1.0
A c++ linear algebra template library
Public Types | Static Public Member Functions | List of all members
Dimension< N > Struct Template Reference

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.
 

Detailed Description

template<index_t N>
struct geom::Dimension< N >

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.

Template Parameters
NCount, or 0 if the count is to be determined at runtime.

Example

#include <geomc/Storage.h>
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);
    }
}

The documentation for this struct was generated from the following file: