1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
#include <iostream>
#include <array>
template<long unsigned N> struct static_num{constexpr static auto val=N; };
template<class C,class... Ts>
struct sort{
sort(C& c) {std::cout<<"mysort3"<<std::endl;}
};
template<class T>
struct s{
s(T& cont) {sort{cont};}
};
template<> struct sort<std::array<int,0>>{
sort(std::array<int,0>&) {std::cout<<"my sort"<<std::endl;}};
template<typename T,typename N> struct sort<std::array<T,N::val>,T,N>{
sort(std::array<T,N::val>&) {std::cout<<"mysort2"<<std::endl;}};
template<long unsigned N>
sort(std::array<int,N>&) -> sort<std::array<int,N>,int,static_num<N>>;
sort(std::array<int,0>&) -> sort<std::array<int,0>>;
int main(...)
{
std::array<int,0> a;
s tmp{a};//output: "my sort"
sort{a}; //same
std::array<int,1> b;
s tmp2{b};//yields "mysort2"
}
| |