• Docs >
  • Program Listing for File dim.hpp
Shortcuts

Program Listing for File dim.hpp

Return to documentation for file (include/ripple/utility/dim.hpp)

#ifndef RIPPLE_UTILITY_DIM_HPP
#define RIPPLE_UTILITY_DIM_HPP

#include "portability.hpp"

namespace ripple {

template <size_t Value>
struct Dimension {
  static constexpr size_t value = Value;

  ripple_all constexpr operator size_t() const {
    return static_cast<size_t>(Value);
  }
};

namespace detail {

template <typename T>
struct IsDimension {
  static constexpr bool value = false;
};

template <size_t Value>
struct IsDimension<Dimension<Value>> {
  static constexpr bool value = true;
};

} // namespace detail

/*==--- [aliases] ----------------------------------------------------------==*/

using DimX = Dimension<0>;
using DimY = Dimension<1>;
using DimZ = Dimension<2>;

/*==--- [constants] --------------------------------------------------------==*/

static constexpr inline DimX dimx() {
  return DimX{};
}

static constexpr inline DimY dimy() {
  return DimY{};
}

static constexpr inline DimZ dimz() {
  return DimZ{};
}

template <typename T>
static constexpr size_t is_dimension_v =
  detail::IsDimension<std::decay_t<T>>::value;

template <size_t Dims>
using dim_type_from_dims_t = std::
  conditional_t<Dims == 1, DimX, std::conditional_t<Dims == 2, DimY, DimZ>>;

template <typename T>
using dim_enable_t = std::enable_if_t<is_dimension_v<T>, int>;

template <typename T>
using non_dim_enable_t = std::enable_if_t<!is_dimension_v<T>, int>;

} // namespace ripple

#endif // RIPPLE_UTILITY_DIM_HPP

Docs

Access comprehensive developer documentation for Ripple

View Docs

Tutorials

Get tutorials to help with understand all features

View Tutorials

Examples

Find examples to help get started

View Examples