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 <limits> 8 : 9 : #include "scipp/common/initialization.h" 10 : #include "scipp/common/overloaded.h" 11 : #include "scipp/core/eigen.h" 12 : #include "scipp/core/element/arg_list.h" 13 : #include "scipp/core/subbin_sizes.h" 14 : #include "scipp/core/transform_common.h" 15 : #include "scipp/units/unit.h" 16 : 17 : namespace scipp::core::element { 18 : 19 : constexpr auto special_like = 20 : overloaded{arg_list<double, float, int64_t, int32_t, bool, SubbinSizes, 21 : time_point, Eigen::Vector3d>, 22 : transform_flags::force_variance_broadcast, 23 41735 : [](const units::Unit &u) { return u; }}; 24 : 25 : constexpr auto zeros_not_bool_like = 26 1228814 : overloaded{special_like, [](const auto &x) { 27 : using T = std::decay_t<decltype(x)>; 28 : if constexpr (std::is_same_v<T, bool>) 29 899 : return int64_t{0}; 30 : else 31 1227915 : return zero_init<T>::value(); 32 : }}; 33 : 34 : template <class T, T Value> 35 : constexpr auto values_like = 36 1058 : overloaded{special_like, [](const auto &) { return Value; }}; 37 : 38 : template <class T> struct underlying { 39 : using type = T; 40 : }; 41 : template <class T> struct underlying<ValueAndVariance<T>> { 42 : using type = T; 43 : }; 44 : template <> struct underlying<time_point> { 45 : using type = decltype(std::declval<time_point>().time_since_epoch()); 46 : }; 47 : template <class T> using underlying_t = typename underlying<T>::type; 48 : 49 : constexpr auto numeric_limits_max_like = 50 11278 : overloaded{special_like, [](const auto &x) { 51 : using T = std::decay_t<decltype(x)>; 52 11278 : return T{std::numeric_limits<underlying_t<T>>::max()}; 53 : }}; 54 : 55 : constexpr auto numeric_limits_lowest_like = 56 11428 : overloaded{special_like, [](const auto &x) { 57 : using T = std::decay_t<decltype(x)>; 58 11428 : return T{std::numeric_limits<underlying_t<T>>::lowest()}; 59 : }}; 60 : 61 : } // namespace scipp::core::element