Временное решение GCC 5.5 ошибка инициализации кортежа - PullRequest
0 голосов
/ 18 мая 2018

Рассмотрим этот код:

  std::vector<
          std::tuple<std::vector<std::size_t>,
                     std::vector<std::size_t>,
                     std::vector<std::size_t>>
        > foo = {
        {{2, 1, 2, 3},   {1, 2},  {2, 3}},
        {{2, 3, 4, 0},   {3},     {2, 3, 4}},
        {{2, 3, 4, 0},   {0},     {3, 4, 0}},
      };

В Clang и GCC 6 или новее он компилируется нормально.В GCC 5.5 выдает эту ошибку:

 In function 'int main()':

:16:4: error: converting to
          'std::tuple<std::vector<long unsigned int, std::allocator<long unsigned int> >,
                      std::vector<long unsigned int, std::allocator<long unsigned int> >,
                      std::vector<long unsigned int, std::allocator<long unsigned int> > >'
      from initializer list would use explicit constructor
          'constexpr std::tuple< <template-parameter-1-1> >::tuple(const _Elements& ...)
     [with _Elements = {
           std::vector<long unsigned int, std::allocator<long unsigned int> >, std::vector<long unsigned int, std::allocator<long unsigned int> >, std::vector<long unsigned int, std::allocator<long unsigned int> >}]'

    };

    ^

Почему это так и как я могу обойти это?

1 Ответ

0 голосов
/ 18 мая 2018

Один из возможных обходных путей - явный вызов конструктора tuple:

using bar = std::tuple<std::vector<std::size_t>,
                       std::vector<std::size_t>,
                       std::vector<std::size_t>>;
std::vector<bar> foo = {
    bar{{2, 1, 2, 3},   {1, 2},  {2, 3}},
    bar{{2, 3, 4, 0},   {3},     {2, 3, 4}},
    bar{{2, 3, 4, 0},   {0},     {3, 4, 0}},
};

(живая демонстрация)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...