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 class Tag, typename T, typename F>
+ inline std::array()> int_to_string (const F& parFrom) {
+ using ArrayRetType = std::array()>;
+
+ ArrayRetType retval;
+ F div = 1;
+ for (std::size_t z = 0; z < Tag::count_digits(parFrom); ++z) {
+ retval[Tag::count_digits(parFrom) - z - 1] = static_cast((parFrom / div) % Tag::base);
+ div *= Tag::base;
+ }
+ std::fill(retval.begin() + Tag::count_digits(parFrom), retval.end(), 0xff);
+ return retval;
+ };
+
+ template class Tag, typename T, typename F>
+ inline T string_to_int (const F& parFrom) {
+ T retval(0);
+ T mul(1);
+ for (auto chara : boost::adaptors::reverse(parFrom)) {
+ retval += dinhelp::customize::char_to_int::make(chara) * mul;
+ mul *= Tag::base;
+ }
+ return retval;
+ };
+ } //namespace implem
+
+ namespace tags {
+ template
+ struct dec {
+ enum { base = 10 };
+
+ template
+ static std::size_t count_digits (
+ T parValue,
+ dinhelp::bt::index_seq = dinhelp::bt::index_range<0, dinhelp::implem::max_digits()>(),
+ dinhelp::bt::index_seq = dinhelp::bt::index_range<0, CHAR_BIT * sizeof(T)>()
+ ) a_pure;
+ };
+
+ template
+ struct hex {
+ enum { base = 16 };
+
+ static std::size_t count_digits ( T parValue ) a_pure;
+ };
+
+ //See: http://stackoverflow.com/questions/9721042/count-number-of-digits-which-method-is-most-efficient#9721113
+ template
+ template
+ std::size_t dec::count_digits (T parValue, dinhelp::bt::index_seq, dinhelp::bt::index_seq) {
+ static T powers[] = { 0, dinhelp::implem::power<10, Powers + 1>::value... };
+ static std::size_t maxdigits[] = { dinhelp::implem::maxdigits::value... };
+ const auto bits = sizeof(parValue) * CHAR_BIT - __builtin_clz(parValue);
+ return (parValue < powers[maxdigits[bits] - 1] ? maxdigits[bits] - 1 : maxdigits[bits]);
+ }
+
+ template
+ std::size_t hex::count_digits (T parValue) {
+ return std::max(((sizeof(parValue) * CHAR_BIT - __builtin_clz(parValue)) + (CHAR_BIT / 2 - 1)) / (CHAR_BIT / 2), 1);
+ }
+ } //namespace tags
+
+ namespace implem {
+ template class Tag>
+ struct lexical_cast {
+ template
+ static T convert ( const typename std::enable_if::value, F>::type& parFrom ) {
+ const auto indices = int_to_string(parFrom);
+ return dinhelp::customize::index_array_to_string::make(indices);
+ }
+
+ template
+ static typename std::enable_if::value, T>::type convert ( const F& parFrom ) {
+ return string_to_int(parFrom);
+ }
+ };
+ } //namespace implem
+
+ template class Tag=tags::dec, typename F=void>
+ inline T lexical_cast (const F& parFrom) {
+ return dinhelp::implem::lexical_cast::template convert(parFrom);
+ }
+
+ namespace customize {
+ template<>
+ struct index_array_to_string {
+ template
+ static std::string make (const std::array &parIndices) {
+ static const char symbols[] = {'0', '1', '2', '3', '4', '5',
+ '6', '7', '8', '9', 'A', 'B',
+ 'C', 'D', 'E', 'F'};
+ std::string retval(N, ' ');
+ for (std::size_t z = 0; z < N; ++z) {
+ retval[z] = symbols[parIndices[z]];
+ }
+ return retval;
+ }
+ };
+
+ template
+ struct char_to_int {
+ static T make (char parChar) {
+ if (parChar >= '0' and parChar <= '9')
+ return parChar - '0';
+ else if (parChar >= 'a' and parChar <= 'f')
+ return 10 + parChar - 'a';
+ else if (parChar >= 'A' and parChar <= 'F')
+ return 10 + parChar - 'A';
+ return 0;
+ }
+ };
+ } //namespace customize
+} //namespace dinhelp
+#endif