Populate An Array Using Constexpr at Compile-time

后端 未结 4 1783
[愿得一人]
[愿得一人] 2020-11-29 03:32

I would like to populate an array of enum using constexpr. The content of the array follows a certain pattern.

I have an enum separating ASCII character set into fou

4条回答
  •  死守一世寂寞
    2020-11-29 04:19

    Ignoring ALL the issues, indices to the rescue:

    template struct seq{};
    template
    struct gen_seq : gen_seq{};
    template
    struct gen_seq<0, Is...> : seq{};
    
    template
    constexpr Table MagicFunction(seq){
      return {{ whichCategory(Is)... }};
    }
    
    constexpr Table MagicFunction(){
      return MagicFunction(gen_seq<128>{});
    }
    

    Live example.

提交回复
热议问题