Created
November 18, 2011 18:46
-
-
Save wesen/1377361 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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