From d6db735e9d654d94e9e691a39902be612d996688 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Mon, 25 Feb 2019 06:19:18 +0300 Subject: [PATCH] Simplifications --- libs/libcommon/include/common/itoa.h | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/libs/libcommon/include/common/itoa.h b/libs/libcommon/include/common/itoa.h index e34d76f8437..1811ce0080c 100644 --- a/libs/libcommon/include/common/itoa.h +++ b/libs/libcommon/include/common/itoa.h @@ -72,38 +72,36 @@ struct Division }; /// Select a type with appropriate number of bytes from the list of types. -/// First parameter is the number of bytes requested. Second parameter is the number of bytes in the first type in the list. -/// The list goes in increasing order: subsequent type is 2x large than the previous. -/// Example: SelectType<4, 2, uint16_t, uint32_t, uint64_t> will select uint32_t. -template -struct SelectType; - -/// When size matches, select the first type from the list. +/// First parameter is the number of bytes requested. Then goes a list of types with 1, 2, 4, ... number of bytes. +/// Example: SelectType<4, uint8_t, uint16_t, uint32_t, uint64_t> will select uint32_t. template -struct SelectType { using Result = T; }; +struct SelectType +{ + using Result = typename SelectType::Result; +}; + +template +struct SelectType<1, T, Ts...> +{ + using Result = T; +}; -/// Shift the list and proceed recursively. -template -struct SelectType { using Result = typename SelectType::Result; }; /// Division by 10^N where N is the size of the type. template using DivisionBy10PowN = typename SelectType < N, - 1, Division, /// divide by 10 Division, /// divide by 100 Division, /// divide by 10000 - Division, /// divide by 100000000 - Division + Division /// divide by 100000000 >::Result; template using UnsignedOfSize = typename SelectType < N, - 1, uint8_t, uint16_t, uint32_t,