// -*- mode: c++ -*-
#ifndef __IMP_CONVERT__63784703
#define __IMP_CONVERT__63784703

#include <cstdlib>
#include <string>
#include "Types"
#include "StringView"

namespace imp {
  template <class T>
  T from_string(StringView);

  template <>
  inline std::string from_string<std::string>(StringView str)
  { return str.to_string(); }

  template <>
  inline int32 from_string<int32>(StringView str)
  {
    return atoi(str.data());
  }

  template <>
  inline bool from_string<bool>(StringView str)
  { return std::atoi(str.data()) > 0; }

  template <>
  inline int64 from_string<int64>(StringView str)
  { return std::atoll(str.data()); }

  template <>
  inline float from_string<float>(StringView str)
  { return std::strtof(str.data(), nullptr); }

  template <>
  inline double from_string<double>(StringView str)
  { return std::strtod(str.data(), nullptr); }
}

#endif //__IMP_CONVERT__63784703
