Native Dimension

An abstract dimension; distinct native dimensions are orthogonal

Context

_images/ditaa-659193ba2d0787ced94dc95be37a8fe363b27025.png

Introduction

Identifies an abstract dimension, for example mass or time.

#include <xo/unit/dimension.hpp>

For example can use this enum to index basis members of a scaled_unit instance:

#include <xo/unit/quantity.hpp>

using namespace xo::qty;

auto x = q::kilometers(100) / q::hours(1);

auto bpu1 = x.lookup_dim(dim::time);
auto bpu2 = x.lookup_dim(dim::distance);

Enum

enum class xo::qty::dimension

represent an abstract dimension.

xo-unit units are expressed as a cartesian product of powers of these dimensions.

Values:

enumerator invalid

sentinel value. not a dimension

enumerator mass

weight. native unit = 1 gram

enumerator distance

distance. native unit = 1 meter

enumerator time

time. native unit = 1 second

enumerator currency

a currency amount. native unit depends on actual currency. For USD: one US dollar.

NOTE: multicurrency work not supported by xo-unit.

  • (1usd + 1eur) is well-defined.

  • (1sec + 1m) is not.

enumerator price

A screen price. The interpretation of prices is highly context dependent; expect useful to bucket separately from currenty amounts.

enumerator n_dim

not a dimension. comes last, counts entries

Constants

static constexpr std::size_t xo::qty::n_dim = static_cast<std::size_t>(dimension::n_dim)

number of built-in dimensions, convenient for array sizing

Functions

inline const char *xo::qty::dim2str(dimension x)

string value for a dimension enum