From 7db82f83d96ffb51a6fb0c586245acffc2ac2584 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Wed, 15 Jun 2016 14:54:24 +0100 Subject: [PATCH] Add custom lexical_cast function that can handle hex values and string_ref. Negative values are not supported. --- include/helpers/casts.hpp | 181 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 include/helpers/casts.hpp diff --git a/include/helpers/casts.hpp b/include/helpers/casts.hpp new file mode 100644 index 0000000..1055933 --- /dev/null +++ b/include/helpers/casts.hpp @@ -0,0 +1,181 @@ +/* Copyright 2015, 2016, Michele Santullo + * This file is part of "dindexer". + * + * "dindexer" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * "dindexer" is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with "dindexer". If not, see . + */ + +#ifndef id942A6B5AB2AF443C82D4321775BFC9E8 +#define id942A6B5AB2AF443C82D4321775BFC9E8 + +#include "compatibility.h" +#include "helpers/sequence_bt.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace dinhelp { + namespace customize { + template + struct index_array_to_string; + + template + struct char_to_int; + } //namespace customize + + namespace implem { + template + inline constexpr std::size_t max_digits() { + return static_cast(::log(std::numeric_limits::max())); + } + + template + struct power { + enum { value = Base * power::value }; + }; + template + struct power { + enum { value = 1 }; + }; + + constexpr std::size_t count_digits_10_compiletime (std::size_t parNum) { + return (parNum == 0 ? 0 : static_cast(::log10(parNum))) + 1; + } + + template + struct maxdigits { + enum { value = count_digits_10_compiletime(static_cast(::pow(2.0, static_cast(N)))) }; + }; + + template