From ce699c4ff01349da00e5fa6a13dfdc2b38144b7e Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 15 Apr 2022 17:30:25 +0100 Subject: constexpr preprocessor component counts --- slicer/test/preprocessor.cpp | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/slicer/test/preprocessor.cpp b/slicer/test/preprocessor.cpp index 7f9fefd..e85a42a 100644 --- a/slicer/test/preprocessor.cpp +++ b/slicer/test/preprocessor.cpp @@ -8,25 +8,22 @@ #include #include #include +#include #include #include #include -using ComponentsCount = std::map; -ComponentsCount COMPONENTS_IN_TEST_ICE = {{"classtype.ice", 2}, {"classes.ice", 3}, {"collections.ice", 5}, - {"enums.ice", 2}, {"inheritance.ice", 12}, {"interfaces.ice", 0}, {"json.ice", 2}, {"locals.ice", 7}, - {"optionals.ice", 2}, {"structs.ice", 5}, {"types.ice", 4}, {"xml.ice", 5}}; - -unsigned int -total() -{ - const auto t = std::accumulate( - COMPONENTS_IN_TEST_ICE.begin(), COMPONENTS_IN_TEST_ICE.end(), 0U, [](const auto & t, const auto & c) { - return t + c.second; - }); - BOOST_CHECK_EQUAL(49, t); - return t; -} +constexpr std::array, 12> COMPONENTS_IN_TEST_ICE_ARRAY { + {{"classtype.ice", 2}, {"classes.ice", 3}, {"collections.ice", 5}, {"enums.ice", 2}, {"inheritance.ice", 12}, + {"interfaces.ice", 0}, {"json.ice", 2}, {"locals.ice", 7}, {"optionals.ice", 2}, {"structs.ice", 5}, + {"types.ice", 4}, {"xml.ice", 5}}}; +using ComponentsCount = decltype(COMPONENTS_IN_TEST_ICE_ARRAY); +constexpr std::span COMPONENTS_IN_TEST_ICE {COMPONENTS_IN_TEST_ICE_ARRAY}; +constexpr auto COMPONENTS_IN_TEST_ICE_COUNT = std::accumulate( + COMPONENTS_IN_TEST_ICE.begin(), COMPONENTS_IN_TEST_ICE.end(), 0U, [](const auto & t, const auto & c) { + return t + c.second; + }); +static_assert(COMPONENTS_IN_TEST_ICE_COUNT == 49); void process(Slicer::Slicer & s, const ComponentsCount::value_type & c) @@ -48,7 +45,7 @@ processAll(Slicer::Slicer & s) process(s, c); } } - BOOST_REQUIRE_EQUAL(total(), s.Components()); + BOOST_REQUIRE_EQUAL(COMPONENTS_IN_TEST_ICE_COUNT, s.Components()); } BOOST_AUTO_TEST_CASE(slicer_metadata_split_empty, *boost::unit_test::timeout(5)) -- cgit v1.2.3