Files
mp-units/test/static/iec_test.cpp
T
Mateusz Pusz 619b99df56 feat(quantity_character): split character into orthogonal order and field axes
Introduce a two-axis `quantity_character`: a `quantity_tensor_order` (scalar, vector,
tensor) and a `quantity_field` (real, complex), replacing the flat enum. The pre-2.6.0
flat spelling (`quantity_character::real_scalar`, `::complex_scalar`, `::vector`,
`::tensor`) stays available through `quantity_character_legacy` plus implicit conversions,
so existing user code keeps compiling. The only casualty is `using enum quantity_character`
(a struct cannot be `using enum`-ed); users switch to `using enum quantity_character_legacy`.

- `quantity_character` is a struct `{order, field}` with `consteval` constructors and a
  defaulted `<=>`. The lexicographic ordering reproduces the previous character ordering
  (`real_scalar < complex_scalar < vector < tensor`) used by the `max`-based combination,
  and the generated `==` allows use as a non-type template argument.
- `quantity_spec` accepts the legacy enum or bare `quantity_tensor_order` / `quantity_field`
  template args; each axis overrides independently (inheriting the other from the quantity
  equation). This also makes complex-vector and complex-tensor characters expressible (they
  are declarable now but not usable until the representation concepts are refactored).
- `RepresentationOf` accepts any character value via the new `detail::QuantityCharacter`
  concept (the two-axis struct, the legacy enum, or either bare axis).

Behavior is unchanged and all tests pass. The library's internal source still uses the
legacy spelling (migrated in a follow-up), after which the legacy enum will be deprecated.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-24 23:17:23 +02:00

61 lines
3.0 KiB
C++

// The MIT License (MIT)
//
// Copyright (c) 2018 Mateusz Pusz
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include <mp-units/systems/iec.h>
#include <mp-units/systems/isq.h>
#include <mp-units/systems/si.h>
/* ************** DERIVED DIMENSIONS THAT INCLUDE UNITS WITH SPECIAL NAMES **************** */
namespace {
using namespace mp_units;
using namespace mp_units::iec::unit_symbols;
using namespace mp_units::si::unit_symbols;
// unit conversions
static_assert(isq::storage_capacity(1 * B) == isq::storage_capacity(8 * bit));
static_assert(isq::storage_capacity(1024 * bit) == isq::storage_capacity(1 * Kibit));
static_assert(isq::storage_capacity(1024 * B) == isq::storage_capacity(1 * KiB));
static_assert(isq::storage_capacity(8 * 1024 * bit) == isq::storage_capacity(1 * KiB));
static_assert(isq::storage_capacity(8 * Kibit) == isq::storage_capacity(1 * KiB));
static_assert(isq::storage_capacity(1 * kbit) == isq::storage_capacity(1000 * bit));
static_assert(isq::storage_capacity(2000 * Mibit) == isq::storage_capacity(2'097'152 * kbit));
static_assert(isq::storage_capacity(1 * Kibit) == isq::storage_capacity(1024 * bit));
static_assert(isq::storage_capacity(1 * Mibit) == isq::storage_capacity(1024 * Kibit));
static_assert(isq::storage_capacity(1 * Gibit) == isq::storage_capacity(1024 * Mibit));
static_assert(isq::storage_capacity(1 * Tibit) == isq::storage_capacity(1024 * Gibit));
static_assert(isq::storage_capacity(1 * Pibit) == isq::storage_capacity(1024 * Tibit));
static_assert(isq::storage_capacity(1 * Eibit) == isq::storage_capacity(1024 * Pibit));
// transfer rate
static_assert(isq::storage_capacity(16 * B) / isq::duration(2 * s) == isq::transfer_rate(8 * B / s));
static_assert(isq::storage_capacity(120 * kB) / isq::duration(2 * min) == isq::transfer_rate(1000 * B / s));
// modulation rate
static_assert(12 / isq::duration(2 * s) == isq::modulation_rate(6 * Bd));
static_assert(6000 / isq::duration(3 * s) == isq::modulation_rate(2 * kBd));
} // namespace