How do I convert a C string to a int at compile time?
I want to be able to pass an integer or a double (or a string) as a template argument and in some instances convert the result to an integer and use it as a template argument for a type in the class. Here's what I've tried: template <typename MPLString> class A { // the following works fine int fun() { // this function should return the int in the boost mpl type passed to it // (e.g. it might be of the form "123") return std::stoi(boost::mpl::c_str<MPLString>::value); } // the following breaks because std::stoi is not constexpr std::array<int, std::stoi(boost::mpl::c_str<MPLString>::value)>