Skip to content

Add example illustrating that adding quantities with different units it not possible  #143

Description

@vil02

Add an example showing that it is not possible to add two quantities of different units.

The code like:

#include "../../CtUnits/CtUnits.hpp"
#include <iostream>
#include <type_traits>

int main()
{
    struct Meter
    {
    };
    struct Inch
    {
    };

    using value_type = double;
    using DistanceInMeters =
        ctu::Quantity<value_type, ctu::UdMap<ctu::UnitDimension<Meter, 1>>>;

    using DistanceInInches =
        ctu::Quantity<value_type, ctu::UdMap<ctu::UnitDimension<Inch, 1>>>;

    const auto dist_a = DistanceInInches(123.0);
    const auto dist_b = DistanceInMeters(321.0);
    std::cout << (dist_a + dist_b).get_value() << '\n';
    return 0;
}

will not compile, because it tries to add meters to inches.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions