From aa536751435135cef7045dec4dd82b5f8cd5890d Mon Sep 17 00:00:00 2001 From: "Alexander J. Pfleger" <70842573+AJPfleger@users.noreply.github.com> Date: Tue, 1 Oct 2024 12:33:23 +0200 Subject: [PATCH] refactor: modernise type traits (#3655) --- .../include/Acts/EventData/TrackStateType.hpp | 5 +++-- Core/include/Acts/Propagator/Propagator.ipp | 15 ++++++------- .../detail/CylindricalSpacePointGrid.ipp | 12 +++++----- .../Acts/Surfaces/ConvexPolygonBounds.hpp | 2 ++ .../Acts/Surfaces/ConvexPolygonBounds.ipp | 5 ++--- .../CombinatorialKalmanFilter.hpp | 6 ++--- .../TrackFitting/GlobalChiSquareFitter.hpp | 3 ++- .../Acts/TrackFitting/KalmanFitter.hpp | 3 ++- Core/include/Acts/Utilities/Concepts.hpp | 3 +-- .../Acts/Utilities/FiniteStateMachine.hpp | 3 +-- Core/include/Acts/Utilities/GridBinFinder.ipp | 22 +++++++++---------- .../include/Acts/Utilities/TransformRange.hpp | 6 ++--- .../Utilities/detail/interpolation_impl.hpp | 16 +++++++------- .../ActsExamples/Io/Csv/CsvInputOutput.hpp | 10 ++++----- .../GeometryHierarchyMapJsonConverter.hpp | 2 +- .../EventData/TrackStatePropMaskTests.cpp | 2 +- .../Core/Utilities/ExtendableTests.cpp | 2 +- Tests/UnitTests/Core/Utilities/GridTests.cpp | 6 ++--- 18 files changed, 60 insertions(+), 63 deletions(-) diff --git a/Core/include/Acts/EventData/TrackStateType.hpp b/Core/include/Acts/EventData/TrackStateType.hpp index 3901eb7852c..7fc25466738 100644 --- a/Core/include/Acts/EventData/TrackStateType.hpp +++ b/Core/include/Acts/EventData/TrackStateType.hpp @@ -14,6 +14,7 @@ #include #include #include +#include namespace Acts { @@ -38,7 +39,7 @@ class TrackStateType { public: using raw_type = std::uint64_t; static constexpr std::size_t kRawBits = - std::numeric_limits::type>::digits; + std::numeric_limits>::digits; // Delete default constructor TrackStateType() = delete; @@ -106,7 +107,7 @@ class ConstTrackStateType { public: using raw_type = std::uint64_t; static constexpr std::size_t kRawBits = - std::numeric_limits::type>::digits; + std::numeric_limits>::digits; // Delete default constructor ConstTrackStateType() = delete; diff --git a/Core/include/Acts/Propagator/Propagator.ipp b/Core/include/Acts/Propagator/Propagator.ipp index 54e752075f6..4a0e553978a 100644 --- a/Core/include/Acts/Propagator/Propagator.ipp +++ b/Core/include/Acts/Propagator/Propagator.ipp @@ -1,6 +1,6 @@ // This file is part of the Acts project. // -// Copyright (C) 2019 CERN for the benefit of the Acts project +// Copyright (C) 2019-2024 CERN for the benefit of the Acts project // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -13,7 +13,7 @@ #include "Acts/Propagator/StandardAborters.hpp" #include "Acts/Propagator/detail/LoopProtection.hpp" -#include +#include namespace Acts::detail { template @@ -113,9 +113,8 @@ auto Acts::Propagator::propagate(const parameters_t& start, -> Result< actor_list_t_result_t> { - static_assert( - std::is_copy_constructible::value, - "return track parameter type must be copy-constructible"); + static_assert(std::copy_constructible, + "return track parameter type must be copy-constructible"); auto state = makeState(start, options); @@ -158,7 +157,7 @@ auto Acts::Propagator::makeState( // Type of track parameters produced by the propagation using ReturnParameterType = StepperCurvilinearTrackParameters; - static_assert(std::is_copy_constructible::value, + static_assert(std::copy_constructible, "return track parameter type must be copy-constructible"); // Expand the abort list with a path aborter @@ -246,7 +245,7 @@ auto Acts::Propagator::makeResult(propagator_state_t state, // Type of track parameters produced by the propagation using ReturnParameterType = StepperCurvilinearTrackParameters; - static_assert(std::is_copy_constructible::value, + static_assert(std::copy_constructible, "return track parameter type must be copy-constructible"); // Type of the full propagation result, including output from actors @@ -291,7 +290,7 @@ auto Acts::Propagator::makeResult( // Type of track parameters produced at the end of the propagation using ReturnParameterType = StepperBoundTrackParameters; - static_assert(std::is_copy_constructible::value, + static_assert(std::copy_constructible, "return track parameter type must be copy-constructible"); // Type of the full propagation result, including output from actors diff --git a/Core/include/Acts/Seeding/detail/CylindricalSpacePointGrid.ipp b/Core/include/Acts/Seeding/detail/CylindricalSpacePointGrid.ipp index ab3ae4af1b9..879b130c6e1 100644 --- a/Core/include/Acts/Seeding/detail/CylindricalSpacePointGrid.ipp +++ b/Core/include/Acts/Seeding/detail/CylindricalSpacePointGrid.ipp @@ -6,6 +6,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. +#include + template Acts::CylindricalSpacePointGrid Acts::CylindricalSpacePointGridCreator::createGrid( @@ -142,12 +144,12 @@ void Acts::CylindricalSpacePointGridCreator::fillGrid( external_spacepoint_iterator_t spBegin, external_spacepoint_iterator_t spEnd, Acts::Extent& rRangeSPExtent) { using iterated_value_t = - typename std::iterator_traits::value_type; - using iterated_t = typename std::remove_const< - typename std::remove_pointer::type>::type; - static_assert(!std::is_pointer::value, + typename std::iter_value_t; + using iterated_t = typename std::remove_const_t< + typename std::remove_pointer_t>; + static_assert(!std::is_pointer_v, "Iterator must contain pointers to space points"); - static_assert(std::is_same::value, + static_assert(std::same_as, "Iterator does not contain type this class was templated with"); if (!config.isInInternalUnits) { diff --git a/Core/include/Acts/Surfaces/ConvexPolygonBounds.hpp b/Core/include/Acts/Surfaces/ConvexPolygonBounds.hpp index 96aa0b33bc3..3537f6e9c7a 100644 --- a/Core/include/Acts/Surfaces/ConvexPolygonBounds.hpp +++ b/Core/include/Acts/Surfaces/ConvexPolygonBounds.hpp @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -54,6 +55,7 @@ class ConvexPolygonBoundsBase : public PlanarBounds { /// @param vertices A collection of vertices. /// throws a logic error if this is not the case template + requires std::same_as static void convex_impl(const coll_t& vertices) noexcept(false); }; diff --git a/Core/include/Acts/Surfaces/ConvexPolygonBounds.ipp b/Core/include/Acts/Surfaces/ConvexPolygonBounds.ipp index 88ddbe8db10..fa1c34cf662 100644 --- a/Core/include/Acts/Surfaces/ConvexPolygonBounds.ipp +++ b/Core/include/Acts/Surfaces/ConvexPolygonBounds.ipp @@ -10,14 +10,13 @@ #include "Acts/Surfaces/detail/BoundaryCheckHelper.hpp" #include "Acts/Utilities/ThrowAssert.hpp" +#include #include template + requires std::same_as void Acts::ConvexPolygonBoundsBase::convex_impl( const coll_t& vertices) noexcept(false) { - static_assert(std::is_same::value, - "Must be collection of Vector2"); - const std::size_t N = vertices.size(); for (std::size_t i = 0; i < N; i++) { std::size_t j = (i + 1) % N; diff --git a/Core/include/Acts/TrackFinding/CombinatorialKalmanFilter.hpp b/Core/include/Acts/TrackFinding/CombinatorialKalmanFilter.hpp index 40555986ce4..10043abc39b 100644 --- a/Core/include/Acts/TrackFinding/CombinatorialKalmanFilter.hpp +++ b/Core/include/Acts/TrackFinding/CombinatorialKalmanFilter.hpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -357,10 +358,7 @@ class CombinatorialKalmanFilter { const auto& [boundParams, jacobian, pathLength] = boundState; trackStateCandidates.clear(); - if constexpr (std::is_same_v< - typename std::iterator_traits< - source_link_iterator_t>::iterator_category, - std::random_access_iterator_tag>) { + if constexpr (std::ranges::random_access_range) { trackStateCandidates.reserve(std::distance(slBegin, slEnd)); } diff --git a/Core/include/Acts/TrackFitting/GlobalChiSquareFitter.hpp b/Core/include/Acts/TrackFitting/GlobalChiSquareFitter.hpp index 9cd8e44325e..fecf8a498f5 100644 --- a/Core/include/Acts/TrackFitting/GlobalChiSquareFitter.hpp +++ b/Core/include/Acts/TrackFitting/GlobalChiSquareFitter.hpp @@ -45,6 +45,7 @@ #include #include #include +#include #include namespace Acts::Experimental { @@ -513,7 +514,7 @@ class Gx2Fitter { /// The navigator has DirectNavigator type or not static constexpr bool isDirectNavigator = - std::is_same::value; + std::is_same_v; public: Gx2Fitter(propagator_t pPropagator, diff --git a/Core/include/Acts/TrackFitting/KalmanFitter.hpp b/Core/include/Acts/TrackFitting/KalmanFitter.hpp index c6cd9b01976..24966c71568 100644 --- a/Core/include/Acts/TrackFitting/KalmanFitter.hpp +++ b/Core/include/Acts/TrackFitting/KalmanFitter.hpp @@ -37,6 +37,7 @@ #include #include #include +#include namespace Acts { @@ -264,7 +265,7 @@ class KalmanFitter { /// The navigator has DirectNavigator type or not static constexpr bool isDirectNavigator = - std::is_same::value; + std::is_same_v; public: KalmanFitter(propagator_t pPropagator, diff --git a/Core/include/Acts/Utilities/Concepts.hpp b/Core/include/Acts/Utilities/Concepts.hpp index 8ccebff4cc6..bcd0f597981 100644 --- a/Core/include/Acts/Utilities/Concepts.hpp +++ b/Core/include/Acts/Utilities/Concepts.hpp @@ -20,8 +20,7 @@ concept same_as_any_of = (std::same_as || ...); /// @brief Concept that is equivalent to `is_nothrow_move_constructible`. /// @todo Convert this to a "real" concept. template -concept nothrow_move_constructible = - std::is_nothrow_move_constructible::value; +concept nothrow_move_constructible = std::is_nothrow_move_constructible_v; /// @brief Concept that is true if T is an arithmetic type. template diff --git a/Core/include/Acts/Utilities/FiniteStateMachine.hpp b/Core/include/Acts/Utilities/FiniteStateMachine.hpp index 3a06b9bed3a..4691edc9bab 100644 --- a/Core/include/Acts/Utilities/FiniteStateMachine.hpp +++ b/Core/include/Acts/Utilities/FiniteStateMachine.hpp @@ -119,8 +119,7 @@ class FiniteStateMachine { /// Default constructor. The default state is taken to be the first in the /// `States` template arguments FiniteStateMachine() - : m_state(typename std::tuple_element<0, std::tuple>::type{}) { - } + : m_state(typename std::tuple_element_t<0, std::tuple>{}) {} /// Constructor from an explicit state. The FSM is initialized to this state. /// @param state Initial state for the FSM. diff --git a/Core/include/Acts/Utilities/GridBinFinder.ipp b/Core/include/Acts/Utilities/GridBinFinder.ipp index 344ef07137c..d138242fd40 100644 --- a/Core/include/Acts/Utilities/GridBinFinder.ipp +++ b/Core/include/Acts/Utilities/GridBinFinder.ipp @@ -6,6 +6,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. +#include + template template void Acts::GridBinFinder::storeValue(first_value_t&& fv, @@ -13,13 +15,12 @@ void Acts::GridBinFinder::storeValue(first_value_t&& fv, constexpr std::size_t N = sizeof...(vals); static_assert(N < DIM); /// Check the fist value is reasonable - using decayed_value_t = typename std::decay::type; - if constexpr (std::is_same::value) { + using decayed_value_t = typename std::decay_t; + if constexpr (std::is_same_v) { /// if int -> value is positive assert(fv >= 0); m_values[DIM - N - 1ul] = fv; - } else if constexpr (std::is_same, - decayed_value_t>::value) { + } else if constexpr (std::is_same_v, decayed_value_t>) { m_values[DIM - N - 1ul] = fv; } else { /// If vector of pairs -> also allow for empty vectors @@ -41,12 +42,11 @@ std::array, DIM> Acts::GridBinFinder::getSizePerAxis( for (std::size_t i(0ul); i < DIM; ++i) { output[i] = std::visit( [&locPosition, i](const auto& val) -> std::pair { - using value_t = typename std::decay::type; - if constexpr (std::is_same::value) { + using value_t = typename std::decay_t; + if constexpr (std::is_same_v) { assert(val >= 0); return std::make_pair(-val, val); - } else if constexpr (std::is_same, - value_t>::value) { + } else if constexpr (std::is_same_v, value_t>) { return std::make_pair(-val.first, val.second); } else { assert(locPosition.size() > i); @@ -82,9 +82,9 @@ bool Acts::GridBinFinder::isGridCompatible( std::size_t nBins = nLocBins[i]; bool isCompabile = std::visit( [nBins](const auto& val) -> bool { - using value_t = typename std::decay::type; - if constexpr (std::is_same::value || - std::is_same, value_t>::value) { + using value_t = typename std::decay_t; + if constexpr (std::is_same_v || + std::is_same_v, value_t>) { return true; } else { return val.size() == nBins; diff --git a/Core/include/Acts/Utilities/TransformRange.hpp b/Core/include/Acts/Utilities/TransformRange.hpp index fc435e58567..a3ef3296e30 100644 --- a/Core/include/Acts/Utilities/TransformRange.hpp +++ b/Core/include/Acts/Utilities/TransformRange.hpp @@ -148,8 +148,7 @@ struct TransformRange { template struct TransformRangeIterator { private: - using internal_value_type = - typename std::iterator_traits::value_type; + using internal_value_type = typename std::iter_value_t; using raw_value_type = std::remove_reference_t()))>; @@ -162,8 +161,7 @@ struct TransformRangeIterator { std::conditional_t, raw_value_type>; - using difference_type = - typename std::iterator_traits::difference_type; + using difference_type = typename std::iter_difference_t; using pointer = std::remove_reference_t*; using reference = value_type&; using iterator_category = std::forward_iterator_tag; diff --git a/Core/include/Acts/Utilities/detail/interpolation_impl.hpp b/Core/include/Acts/Utilities/detail/interpolation_impl.hpp index dfab7305ab9..36464c9105d 100644 --- a/Core/include/Acts/Utilities/detail/interpolation_impl.hpp +++ b/Core/include/Acts/Utilities/detail/interpolation_impl.hpp @@ -46,14 +46,14 @@ struct can_interpolate { static std::false_type point_type_test(...); static const bool value = - std::is_same(nullptr))>::value && - std::is_same(nullptr))>::value && - std::is_same(nullptr))>::value && - std::is_same(nullptr))>::value; + std::is_same_v(nullptr))> && + std::is_same_v(nullptr))> && + std::is_same_v(nullptr))> && + std::is_same_v(nullptr))>; }; /// @brief concept equivalent to `can_interpolate` diff --git a/Examples/Io/Csv/include/ActsExamples/Io/Csv/CsvInputOutput.hpp b/Examples/Io/Csv/include/ActsExamples/Io/Csv/CsvInputOutput.hpp index 3006f498cc6..97b14ba91bf 100644 --- a/Examples/Io/Csv/include/ActsExamples/Io/Csv/CsvInputOutput.hpp +++ b/Examples/Io/Csv/include/ActsExamples/Io/Csv/CsvInputOutput.hpp @@ -273,9 +273,8 @@ class NamedTupleDsvWriter { /// Append a record to the file. void append(const NamedTuple& record) { - append_impl(record, - std::make_index_sequence< - std::tuple_size::value>{}); + append_impl(record, std::make_index_sequence< + std::tuple_size_v>{}); } private: @@ -548,8 +547,7 @@ inline bool NamedTupleDsvReader::read( std::to_string(m_reader.num_lines())); } // convert to tuple - parse_record(record, - std::make_index_sequence::value>{}); + parse_record(record, std::make_index_sequence>{}); return true; } @@ -572,7 +570,7 @@ inline bool NamedTupleDsvReader::read( template inline void NamedTupleDsvReader::use_default_columns() { // assume row content is identical in content and order to the tuple - m_num_columns = std::tuple_size::value; + m_num_columns = std::tuple_size_v; for (std::size_t i = 0; i < m_tuple_column_map.size(); ++i) { m_tuple_column_map[i] = i; } diff --git a/Plugins/Json/include/Acts/Plugins/Json/GeometryHierarchyMapJsonConverter.hpp b/Plugins/Json/include/Acts/Plugins/Json/GeometryHierarchyMapJsonConverter.hpp index eaef0aa8e0f..80419aab1e3 100644 --- a/Plugins/Json/include/Acts/Plugins/Json/GeometryHierarchyMapJsonConverter.hpp +++ b/Plugins/Json/include/Acts/Plugins/Json/GeometryHierarchyMapJsonConverter.hpp @@ -155,7 +155,7 @@ nlohmann::json GeometryHierarchyMapJsonConverter::toJson( for (std::size_t i = 0; i < container.size(); ++i) { auto entry = encodeIdentifier(container.idAt(i)); auto value_json = nlohmann::json(container.valueAt(i)); - if constexpr (!std::is_same::value) { + if constexpr (!std::is_same_v) { decorateJson(decorator, container.valueAt(i), value_json); } entry["value"] = std::move(value_json); diff --git a/Tests/UnitTests/Core/EventData/TrackStatePropMaskTests.cpp b/Tests/UnitTests/Core/EventData/TrackStatePropMaskTests.cpp index 3b5fabce6db..fd4dfda60e7 100644 --- a/Tests/UnitTests/Core/EventData/TrackStatePropMaskTests.cpp +++ b/Tests/UnitTests/Core/EventData/TrackStatePropMaskTests.cpp @@ -49,7 +49,7 @@ BOOST_AUTO_TEST_CASE(BitmaskOperators) { BOOST_CHECK(!ACTS_CHECK_BIT(bs4, PM::Filtered)); auto cnv = [](auto a) -> std::bitset<8> { - return static_cast::type>(a); + return static_cast>(a); }; BOOST_CHECK(cnv(PM::All).all()); // all ones diff --git a/Tests/UnitTests/Core/Utilities/ExtendableTests.cpp b/Tests/UnitTests/Core/Utilities/ExtendableTests.cpp index 92d68fae1c9..94196975a2d 100644 --- a/Tests/UnitTests/Core/Utilities/ExtendableTests.cpp +++ b/Tests/UnitTests/Core/Utilities/ExtendableTests.cpp @@ -33,7 +33,7 @@ BOOST_AUTO_TEST_CASE(Extendable_) { // Test the empty list detail::Extendable<> nullist{}; (void)nullist; - BOOST_CHECK_EQUAL(std::tuple_size>::value, 0u); + BOOST_CHECK_EQUAL(std::tuple_size_v>, 0u); detail::Extendable alist; auto& a0_object = alist.get(); diff --git a/Tests/UnitTests/Core/Utilities/GridTests.cpp b/Tests/UnitTests/Core/Utilities/GridTests.cpp index ffe28592630..8d626f74695 100644 --- a/Tests/UnitTests/Core/Utilities/GridTests.cpp +++ b/Tests/UnitTests/Core/Utilities/GridTests.cpp @@ -17,11 +17,11 @@ #include #include +#include #include #include #include #include -#include #include #include @@ -1308,10 +1308,10 @@ BOOST_AUTO_TEST_CASE(grid_type_conversion) { Grid g2(Type, std::move(a), std::move(b)); decltype(g2) g2Copy(g2.axesTuple()); - static_assert(std::is_same::value); + static_assert(std::same_as); auto g2ConvertedInt = g2Copy.convertType(); - static_assert(std::is_same::value); + static_assert(std::same_as); } BOOST_AUTO_TEST_CASE(grid_full_conversion) {