language: C++11 (gcc-4.7.2)
date: 847 days 18 hours ago
link:
visibility: public
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
template< int Index, class T, T... Args > struct LookupAtIndex;
 
template< int Index, class T, T First, T... Rest >
struct LookupAtIndex< Index, T, First, Rest... > {
  static constexpr T result() {
    return LookupAtIndex< Index - 1, T, Rest... > ::result();
  }
};
 
template< class T, T First, T... Rest >
struct LookupAtIndex< 0, T, First, Rest... > {
  static constexpr T result() { return First; }
};
 
#include <iostream>
using namespace std;
 
int f( int ) { return 0; }
int g( int ) { return 0; }
int h( int ) { return 0; }
 
int main()
{
  cout<< (LookupAtIndex< 0, int(*)(int), &f, &g, &h >::result() == &f) <<endl;
  cout<< (LookupAtIndex< 1, int(*)(int), &f, &g, &h >::result() == &g) <<endl;
  cout<< (LookupAtIndex< 2, int(*)(int), &f, &g, &h >::result() == &h) <<endl;
}