Проблема с расширением вариативного шаблона в Visual Studio - PullRequest
3 голосов
/ 06 мая 2019

Этот код прекрасно работает с gcc:

#include <iostream>
#include <type_traits>
#include <utility>

template <bool... Bs>
struct bool_sequence {};

template <bool... Bs>
using bool_and = std::is_same<
                            bool_sequence<Bs...>,
                            bool_sequence<(Bs || true)...>
                            >;
template <bool... Bs>
using bool_or = std::integral_constant<bool, !bool_and<!Bs...>::value>;

int main(int argc, char* argv[])
{
    std::cout << bool_or<true>::value << std::endl;
    std::cout << bool_or<true, true>::value << std::endl;
    std::cout << bool_or<true, true, true>::value << std::endl;
}

Ожидаемый результат: 1 1 1. Вот живой пример

Но VS 2017 выводит: 0 0 0.Это ошибка в VS или я что-то здесь упускаю?

Редактировать: VS 2017, v141, кл: 19.16.27030.1

Спасибо

1 Ответ

0 голосов
/ 08 мая 2019

Это не дает прямого ответа на мой вопрос, но это просто обходной путь (на самом деле это не обходной путь, а гораздо более чистое решение для реального кода по сравнению с MVCE, приведенным выше) с использованием std:: conunction / disjunction, предложенный @Frank в комментарии., в случае, если кто-то еще приземлится здесь по той же причине.

Это работает на VS, как и ожидалось:

#include <iostream>
#include <type_traits>
#include <utility>

template <bool... Bs>
using bool_and =
    std::conjunction<std::integral_constant<bool, Bs>...>;

template <bool... Bs>
using bool_or =
    std::disjunction<std::integral_constant<bool, Bs>...>;

int main()
{
    std::cout << bool_or<true>::value << std::endl;
    std::cout << bool_or<true, true>::value << std::endl;
    std::cout << bool_or<true, true, true>::value << std::endl;
}

, а также live

...