From ba01794d0bf6096d5f8c2842167507878cf12a12 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Sat, 2 Feb 2019 13:45:34 +1100 Subject: [PATCH] parse: style --- parse.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/parse.cpp b/parse.cpp index ef2bfdbd..8d66b7fd 100644 --- a/parse.cpp +++ b/parse.cpp @@ -35,14 +35,14 @@ template <> struct parse_traits { static constexpr auto value = str template <> struct parse_traits { static constexpr auto value = strtold; }; -//----------------------------------------------------------------------------- -template -T +/////////////////////////////////////////////////////////////////////////////// +template +ValueT c_iparse (cruft::view &data) { auto head = const_cast (data.begin ()); auto tail = head; - auto val = parse_traits::value (head, &tail, 0); + auto val = parse_traits::value (head, &tail, 0); if (tail == head) throw std::invalid_argument ("unable to parse integer"); @@ -53,13 +53,13 @@ c_iparse (cruft::view &data) //----------------------------------------------------------------------------- -template -T +template +ValueT c_fparse (cruft::view &data) { auto head = const_cast (data.begin ()); auto tail = head; - auto val = parse_traits::value (head, &tail); + auto val = parse_traits::value (head, &tail); if (tail == head) throw std::invalid_argument ("unable to parse float"); @@ -69,8 +69,6 @@ c_fparse (cruft::view &data) } - - /////////////////////////////////////////////////////////////////////////////// /// Specialise cruft::parse for the type KLASS and dispatch the actual parsing /// to safe template wrappers around the C parsing functions. @@ -124,6 +122,7 @@ cruft::parse (cruft::view &str) { \ return cruft::cast::narrow (res); \ } + C_PARSE_WITH_CAST(short, long) C_PARSE_WITH_CAST(int, long) C_PARSE_WITH_CAST(unsigned short, unsigned long)