Line data Source code
1 : // SPDX-License-Identifier: BSD-3-Clause 2 : // Copyright (c) 2023 Scipp contributors (https://github.com/scipp) 3 : /// @file 4 : /// @author Simon Heybrock 5 : #pragma once 6 : 7 : #include "scipp-variable_export.h" 8 : #include "scipp/variable/generated_arithmetic.h" 9 : #include "scipp/variable/variable.h" 10 : 11 : namespace scipp::variable { 12 : 13 : [[nodiscard]] SCIPP_VARIABLE_EXPORT Variable operator+(const Variable &a, 14 : const Variable &b); 15 : [[nodiscard]] SCIPP_VARIABLE_EXPORT Variable operator-(const Variable &a, 16 : const Variable &b); 17 : [[nodiscard]] SCIPP_VARIABLE_EXPORT Variable operator*(const Variable &a, 18 : const Variable &b); 19 : [[nodiscard]] SCIPP_VARIABLE_EXPORT Variable operator/(const Variable &a, 20 : const Variable &b); 21 : 22 : SCIPP_VARIABLE_EXPORT Variable &operator+=(Variable &a, const Variable &b); 23 : SCIPP_VARIABLE_EXPORT Variable &operator-=(Variable &a, const Variable &b); 24 : SCIPP_VARIABLE_EXPORT Variable &operator*=(Variable &a, const Variable &b); 25 : SCIPP_VARIABLE_EXPORT Variable &operator/=(Variable &a, const Variable &b); 26 : SCIPP_VARIABLE_EXPORT Variable &floor_divide_equals(Variable &a, 27 : const Variable &b); 28 : 29 : SCIPP_VARIABLE_EXPORT Variable operator+=(Variable &&a, const Variable &b); 30 : SCIPP_VARIABLE_EXPORT Variable operator-=(Variable &&a, const Variable &b); 31 : SCIPP_VARIABLE_EXPORT Variable operator*=(Variable &&a, const Variable &b); 32 : SCIPP_VARIABLE_EXPORT Variable operator/=(Variable &&a, const Variable &b); 33 : SCIPP_VARIABLE_EXPORT Variable floor_divide_equals(Variable &&a, 34 : const Variable &b); 35 : 36 : } // namespace scipp::variable 37 : 38 : namespace scipp::units { 39 : template <typename T> 40 : std::enable_if_t<std::is_arithmetic_v<T> || 41 : std::is_same_v<T, scipp::core::time_point>, 42 : Variable> 43 598362 : operator*(T v, const units::Unit &unit) { 44 1196724 : return makeVariable<T>(units::Unit{unit}, Values{v}); 45 : } 46 : 47 : template <typename T> 48 : std::enable_if_t<std::is_arithmetic_v<T> || 49 : std::is_same_v<T, scipp::core::time_point>, 50 : Variable> 51 : operator/(T v, const units::Unit &unit) { 52 : return makeVariable<T>(units::one / unit, Values{v}); 53 : } 54 : } // namespace scipp::units