Skip to content

Instantly share code, notes, and snippets.

@aruslan
Created February 9, 2012 03:32
Show Gist options
  • Save aruslan/1777049 to your computer and use it in GitHub Desktop.
Save aruslan/1777049 to your computer and use it in GitHub Desktop.
MSVC template-as-text-substitution round 4...
#include <stdio.h> // Any parser should survive the standard i/o
struct t0 { typedef int a; };
struct t1 : virtual t0
{
static const int a = 42;
int result(int b) const { return (a)-(b); }
};
struct t2 : virtual t0
{
typedef int a;
int result(int b) const { return (a)-(b); }
};
template<typename T>
struct t3 : T, virtual t0
{
int result(int b) const { return (a)-(b); }
};
template<bool b> struct t4;
template<> struct t4<true> : t3<t1> {};
template<> struct t4<false> : t3<t2> {};
struct t5 : t4<true> {};
struct t6 : t4<false> {};
int a = 42;
struct t7
{
int result(int b) const { return (a)-(b); }
typedef int a;
};
int main()
{
printf("t1=%d\n", t1().result(42));
printf("t2=%d\n", t2().result(42));
printf("t5=%d\n", t5().result(42));
printf("t6=%d\n", t6().result(42));
printf("t7=%d\n", t7().result(42));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment