parse: use views over explit begin/end pairs

This commit is contained in:
Danny Robson 2017-12-18 14:50:10 +11:00
parent 60a7670326
commit 2ead13a063
2 changed files with 8 additions and 8 deletions

View File

@ -69,9 +69,9 @@ c_fparse (const char *first, const char *last)
#define C_PARSE(T, KLASS) \ #define C_PARSE(T, KLASS) \
template <> \ template <> \
T \ T \
util::parse<T> (const char *first, const char *last) \ util::parse<T> (util::view<const char *> str) \
{ \ { \
return c_ ## KLASS ## parse<T> (first, last); \ return c_ ## KLASS ## parse<T> (std::cbegin (str), std::cend (str)); \
} }

View File

@ -17,6 +17,8 @@
#ifndef CRUFT_UTIL_PARSE_HPP #ifndef CRUFT_UTIL_PARSE_HPP
#define CRUFT_UTIL_PARSE_HPP #define CRUFT_UTIL_PARSE_HPP
#include "view.hpp"
#include <cstring> #include <cstring>
#include <string> #include <string>
#include <iterator> #include <iterator>
@ -28,16 +30,14 @@ namespace util {
/// ///
/// throws std::invalid_argument when the type cannot be parsed. /// throws std::invalid_argument when the type cannot be parsed.
template <typename T> template <typename T>
T T parse (util::view<const char *>);
parse (const char *first, const char *last);
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
template <typename T> template <typename T>
T T parse (const char *str)
parse (const char *str)
{ {
return parse<T> (str, str + strlen (str)); return parse<T> (make_view (str));
} }
@ -46,7 +46,7 @@ namespace util {
T T
parse (const std::string &str) parse (const std::string &str)
{ {
return parse<T> (std::cbegin (str), std::cend (str)); return parse<T> (make_view (str));
} }
} }