Skip to content

Instantly share code, notes, and snippets.

@wengxt
Created July 24, 2017 03:23
Show Gist options
  • Save wengxt/396f0ccec920ead68c98c7a63c8d81a0 to your computer and use it in GitHub Desktop.
Save wengxt/396f0ccec920ead68c98c7a63c8d81a0 to your computer and use it in GitHub Desktop.
#include <fcitx-utils/metastring.h>
#include <iostream>
template<int b>
class ItoA2 {
public:
using cur = typename ItoA2<b % 10>::type;
using remain = typename ItoA2<b / 10>::type;
using type = typename fcitx::ConcatMetaString<remain, cur>::type;
};
#define ITOA2_DEF(N) template<> class ItoA2<N> { public: using type = fcitx::MetaString<N + '0'>; };
ITOA2_DEF(0);
ITOA2_DEF(1);
ITOA2_DEF(2);
ITOA2_DEF(3);
ITOA2_DEF(4);
ITOA2_DEF(5);
ITOA2_DEF(6);
ITOA2_DEF(7);
ITOA2_DEF(8);
ITOA2_DEF(9);
int main() {
ItoA2<1234215>::type b;
std::cout << b.data() << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment