Simbody  3.7
SimTK::ArrayIndexTraits< X > Struct Template Reference

This templatized type is used by the Array_<T,X> classes to obtain the information they need to use the class X as an index class for the array. More...

Public Types

typedef X::size_type size_type
 The signed or unsigned integral type to which an object of index type X can be converted without producing any compiler warnings. More...
 
typedef X::difference_type difference_type
 A signed integral type large enough to hold the full range of possible signed differences i-j between two indices i and j of type X. More...
 

Static Public Member Functions

static size_type max_size ()
 The maximum allowable size for any Array_<T,X> that uses this type X as its index type. More...
 

Detailed Description

template<class X>
struct SimTK::ArrayIndexTraits< X >

This templatized type is used by the Array_<T,X> classes to obtain the information they need to use the class X as an index class for the array.

There must be a specialization here providing ArrayIndexTraits for each of the built-in integral types that is suitable for use as an index. Any other type X will qualify as an index if it defines the following members:

  • typedef size_type
  • typedef difference_type
  • static size_type max_size()
  • operator size_type() const (conversion from X to size_type)

max_size() determines the largest number of elements that a container may hold if its index type is X.

size_type must be an integral type large enough to hold all the values from 0 to max_size(), including all the index values (which range from 0 to max_size()-1). size_type may be signed or unsigned; it is the type returned by size(), max_size(), capacity(), etc. and may be compared directly against an index of type X without producing a compiler warning.

difference_type is a signed integral type that can hold all possible differences between two indices, that is, values between -(max_size()-1) and +(max_size()-1). In most cases we use an integral type with the same number of bits for size_type and difference_type but when the index type is very small (bool, unsigned char, or unsigned short) we want to allow the full range (2, 255, or 65535 elements, resp.) in which case we need a wider type to hold the differences.

The conversion operator ensures that we can write size_type(i) for an index i of type X. An explicit conversion member does not need to be present as long as the conversion size_type(i) already works as it does for all the integral type specializations.

The SimTK type-generating macro SimTK_DEFINE_UNIQUE_INDEX_TYPE() provides the necessary members so that these types can be used directly as index types for Array_ objects with no further preparation. For example, you can make an Array_<int,MobilizedBodyIndex> that stores ints that can be indexed only via MobilizedBodyIndex indices.

Template Parameters
XA type suitable for use as an Array_ index.
See also
Array_

Member Typedef Documentation

◆ size_type

template<class X>
typedef X::size_type SimTK::ArrayIndexTraits< X >::size_type

The signed or unsigned integral type to which an object of index type X can be converted without producing any compiler warnings.

◆ difference_type

template<class X>
typedef X::difference_type SimTK::ArrayIndexTraits< X >::difference_type

A signed integral type large enough to hold the full range of possible signed differences i-j between two indices i and j of type X.

Member Function Documentation

◆ max_size()

template<class X>
static size_type SimTK::ArrayIndexTraits< X >::max_size ( )
inlinestatic

The maximum allowable size for any Array_<T,X> that uses this type X as its index type.


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