我正在尝试使用if-constexpr来检查某些东西,但是我遇到了如下错误
预期“(”在“警察”之前) “否则”而没有先前的“如果”“
到目前为止,我检查我的密码没有任何问题。
我的编译标志是g++ -std=c++17 main.cpp
#include <iostream>
template<typename T, typename Comp = std::less<T> >
struct Facility
{
template<T ... list>
struct List
{
static void print()
{
std::cout<<"\""<<"Empty List"<<"\""<<"\n";
}
};
template<T head,T ... list>
struct List<head,list...>
{
static void print()
{
std::cout<<"\"" << head;
((std::cout << " " << list), ...);
std::cout<<"\""<<"\n";
}
};
template<unsigned N,typename AA>
struct RemoveFirst{};
template<unsigned N,T head,T ... Rest>
struct RemoveFirst<N,List<head,Rest...>>
{
struct result
{
static void print()
{
if constexpr (N == head)
{
std::cout<<"";
}
else
{
std::cout<<"\""<<head;
((std::cout << " " << Rest), ...);
std::cout<<"\""<<"\n";
}
}
};
};
};
template<int ... intlist>
using IntList = typename Facility<int>::List<intlist...>;
int main()
{
using IntFacility = Facility<int>;
using List = IntList<2, 8, 2, 3, 5, 10, 8, 5>;
}发布于 2018-07-11 18:36:32
GCC的旧版本(最多6.x)不支持C++17的最终版本,这将导致该错误,因为它们将constexpr识别为关键字,但不理解constexpr if结构。确保你的GCC是第7版或更高版本。
https://stackoverflow.com/questions/51291617
复制相似问题