Created
March 8, 2017 08:10
-
-
Save anonymous/e9a7eafbbddf3cc8289f7346329126ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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()); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment