Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Visual Studio中可变模板扩展的问题_C++_Visual Studio_Templates_C++14_C++17 - Fatal编程技术网

C++ Visual Studio中可变模板扩展的问题

C++ Visual Studio中可变模板扩展的问题,c++,visual-studio,templates,c++14,c++17,C++,Visual Studio,Templates,C++14,C++17,这段代码与gcc配合得很好: #include <iostream> #include <type_traits> #include <utility> template <bool... Bs> struct bool_sequence {}; template <bool... Bs> using bool_and = std::is_same< bool_seque

这段代码与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;
}
#包括
#包括
#包括
模板
结构布尔_序列{};
模板
使用bool_和=std::是否相同<
布尔_序列,
布尔_序列
>;
模板
使用bool_或=std::integral_常数;
int main(int argc,char*argv[])
{

std::cout这并没有直接回答我的问题,但只是一个解决方案(实际上不是真正的解决方案,但与上面的MVCE相比,对于真正的代码来说更干净),使用@Frank在评论中提出的std::连接/分离,以防其他人出于同样的原因来到这里

这在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;
}
#包括
#包括
#包括
模板
使用bool_和=
std::连词;
模板
使用bool_或=
析取;
int main()
{
为什么不使用c++17:

#包括
#包括
模板
使用bool_和=std::bool_常量;
模板
使用bool_或=std::bool_常量;
int main()
{

std::你能提供关于你的编译器版本的更多信息吗?我在vs 2017上的测试没有再现这种行为。@StoryTeller:vs 2017 Profefessional,v141,cl:19.16.27030.1Aha。考虑到它在19.14中工作,我想说你确实遇到了回归。仅供参考,以防这是你试图编译的实际代码,而不是MVCE:
std::disconction
std::conjunction
执行这些相同的操作,并且在所有这些编译器版本下都能正常工作。@弗兰克:是的,std::conjunction和std::disconjunction的工作非常困难。但这只是MVCE,问题是为什么VS不能正确编译它。有趣的是,VS中的智能感知被显示出来了正确地编译扩展,但编译器做得不对。
#include <iostream>
#include <type_traits>

template <bool... Bs>
using bool_and = std::bool_constant<(Bs && ...)>;

template <bool... Bs>
using bool_or = std::bool_constant<(Bs || ...)>;

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