Skip to content

Instantly share code, notes, and snippets.

Created March 8, 2017 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/b3987d1514fe64dc9a4cd13c7cfd9f09 to your computer and use it in GitHub Desktop.
Save anonymous/b3987d1514fe64dc9a4cd13c7cfd9f09 to your computer and use it in GitHub Desktop.
#include <cstddef>
#include <cstdio>
#include <string>
#include <utility>
#include <boost/lexical_cast.hpp>
#include <boost/spirit/include/karma.hpp>
static const int max_i2s = 80000000;
inline bool karma_int_to_string(int value, std::string& str)
{
using namespace boost::spirit;
using boost::spirit::karma::generate;
char buffer[16];
char* x = buffer;
if (!generate(x, int_, value))
return false;
str.assign(buffer, std::distance(buffer,x));
return true;
}
int main()
{
for (int i = (-max_i2s / 2); i < (max_i2s / 2); ++i)
{
std::string s1;
karma_int_to_string(i,s1);
std::string s2 = boost::lexical_cast<std::string>(i);
if (s1 != s2)
{
//printf("ERROR s1:%s\ts2:%s\n",s1.c_str(),s2.c_str());
std::cout << "Mismatch: i=" << i << " s1=" << s1 << " s2=" << s2 << "\n";
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment