{
                  
                  
                  public:
                  
                  
                      struct KV {
                  
                  
                          Key   key;
                  
                  
                          Value value;
                  
                  
                      };
                  
                  
                  
                  
                  
                      constexpr Value  operator[] (Key key) const
                  
                  
                      {
                  
                  
                          return Get (key);
                  
                  
                      }
                  
                  
                  
                  
                  
                  private:
                  
                  
                      constexpr Value  Get (Key key, int i = 0) const
                  
                  
                      {
                  
                  
                          return i == N ?
                  
                  
                                 KeyNotFound () :
                  
                  
                                 pairs[i].key == key ? pairs[i].value : Get (key, i + 1);
                  
                  
                      }
                  
                  
                  
                  
                  
                      static Value KeyNotFound ()     // not constexpr
                  
                  
                      {
                  
                  
                          return {};
                  
                  
                      }
                  
                  
                  
                  
                  
                  public:
                  
                  
                      KV  pairs[N];
                  
                  
                  };
                  
                  
                  
                  
                  
                  
                  
                  
                  constexpr CTMap<int, int, 3>  ctMap {{ { 10, 20 }, { 11, 21 }, { 23, 7 } }};
                  
                  
                  
                  
                  
                  
                  
                  
                  static_assert (ctMap[10] == 20, "Error.");
                  
                  
                  static_assert (ctMap[11] == 21, "Error.");
                  
                  
                  static_assert (ctMap[23] ==  7, "Error.");
                  
                  
                  
                  
                  
                  // constexpr auto compilationError = ctMap[404];
                  
                  
                  насколько это решение валидно?
                  
                  
                
А можно такое не в чат, а в годболт какой-нибудь?
Да норм вроде.
Обсуждают сегодня