Я хочу создать программу, которая имеет массив с жесткими элементами L (например: 1,2,3,3) и использовать аргументы переменных шаблона для проверки сортировки элементов, если они не отсортированы, она не сможет скомпилироваться в static_assert , но теперь программа вообще не может скомпилироваться:
#include <stdio.h>
#include <vector>
template<int first,int second,int... args>
struct s{
enum{e=first<=second && s<second,args...>::e};
};
template<int first,int second>
struct s{
enum{e=first<=second};
};
#define L 1,2,3,3
//static_assert(s<L>::e!=0,"");
int a[]={L};
int main(){
printf("%d\n",s<L>::e);
return 0;
}
ошибка компиляции говорит:
abc.cpp:5:29: error: too few template arguments for class template 's'
enum{e=first<=second && s<second,args...>::e};
^
abc.cpp:5:29: note: in instantiation of template class 's<3, 3>' requested here
enum{e=first<=second && s<second,args...>::e};
^
abc.cpp:5:29: note: in instantiation of template class 's<2, 3, 3>' requested here
enum{e=first<=second && s<second,args...>::e};
^
abc.cpp:16:19: note: in instantiation of template class 's<1, 2, 3, 3>' requested here
printf("%d\n",s<L>::e);
^
abc.cpp:4:8: note: template is declared here
struct s{
какова причина? Это просто синтаксическая ошибка в шаблоне? или эта идея невозможна? Если это невозможно, есть ли другие способы проверить, отсортирован ли массив во время компиляции?