Skip to content

Instantly share code, notes, and snippets.

@wesen
Created November 18, 2011 18:46
Show Gist options
  • Select an option

  • Save wesen/1377361 to your computer and use it in GitHub Desktop.

Select an option

Save wesen/1377361 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <inttypes.h>
template<bool C, typename Ta, typename Tb>
class IfThenElse;
template <typename Ta, typename Tb>
class IfThenElse<true, Ta, Tb> {
public:
typedef Ta ResultT;
};
template <typename Ta, typename Tb>
class IfThenElse<false, Ta, Tb> {
public:
typedef Tb ResultT;
};
template <std::size_t S>
class Foobar {
typedef typename IfThenElse<(S < 256),
uint8_t,
typename IfThenElse<(S < 65536),
uint16_t,
void>::ResultT >::ResultT indexT;
indexT index;
public:
Foobar() {
std::cout << "size of index " << sizeof(index) << "\n";
}
};
int main(void) {
Foobar<12> f1;
Foobar<300> f2;
Foobar<1000000> f3;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment