Skip to content

Instantly share code, notes, and snippets.

@wengxt
Created July 24, 2017 03:23
Show Gist options
  • Select an option

  • Save wengxt/396f0ccec920ead68c98c7a63c8d81a0 to your computer and use it in GitHub Desktop.

Select an option

Save wengxt/396f0ccec920ead68c98c7a63c8d81a0 to your computer and use it in GitHub Desktop.

Revisions

  1. wengxt renamed this gist Jul 24, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. wengxt created this gist Jul 24, 2017.
    28 changes: 28 additions & 0 deletions i to a
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    #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;
    }