From c42db23e3da40c9d3463f616ed8b8e4f7e3a3c9b Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 6 May 2024 21:00:45 +0200 Subject: [PATCH] Use explicitly sized std::array instead of C array and ptr arithmetic --- include/guidance/turn_instruction.hpp | 31 ++++++++++++--------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/include/guidance/turn_instruction.hpp b/include/guidance/turn_instruction.hpp index 45ab1f5df..cc70f387e 100644 --- a/include/guidance/turn_instruction.hpp +++ b/include/guidance/turn_instruction.hpp @@ -154,24 +154,21 @@ inline bool operator==(const TurnInstruction lhs, const TurnInstruction rhs) inline bool hasRoundaboutType(const TurnInstruction instruction) { using namespace guidance::TurnType; - const constexpr TurnType::Enum valid_types[] = {TurnType::EnterRoundabout, - TurnType::EnterAndExitRoundabout, - TurnType::EnterRotary, - TurnType::EnterAndExitRotary, - TurnType::EnterRoundaboutIntersection, - TurnType::EnterAndExitRoundaboutIntersection, - TurnType::EnterRoundaboutAtExit, - TurnType::ExitRoundabout, - TurnType::EnterRotaryAtExit, - TurnType::ExitRotary, - TurnType::EnterRoundaboutIntersectionAtExit, - TurnType::ExitRoundaboutIntersection, - TurnType::StayOnRoundabout}; + const constexpr std::array valid_types = {TurnType::EnterRoundabout, + TurnType::EnterAndExitRoundabout, + TurnType::EnterRotary, + TurnType::EnterAndExitRotary, + TurnType::EnterRoundaboutIntersection, + TurnType::EnterAndExitRoundaboutIntersection, + TurnType::EnterRoundaboutAtExit, + TurnType::ExitRoundabout, + TurnType::EnterRotaryAtExit, + TurnType::ExitRotary, + TurnType::EnterRoundaboutIntersectionAtExit, + TurnType::ExitRoundaboutIntersection, + TurnType::StayOnRoundabout}; - const auto *first = valid_types; - const auto *last = first + sizeof(valid_types) / sizeof(valid_types[0]); - - return std::find(first, last, instruction.type) != last; + return std::find(valid_types.cbegin(), valid_types.cend(), instruction.type); } inline bool entersRoundabout(const guidance::TurnInstruction instruction)