#include <stdio.h>

/* 1. a type */
template <class T>
T max_of(T a, T b)
{
    return a > b ? a : b;
}

/* 2. an integer value */
template <int size>
struct Buffer {
    char data[size];
    int Size() const { return size; }
};

/* 3. an address: of a global variable ... */
template <int *counter>
void count()
{
    ++*counter;
}

/* ... or of a function */
template <void (*report)(const char *)>
void check(bool ok, const char *msg)
{
    if (!ok)
        report(msg);
}

int errors = 0, warnings = 0;

void complain(const char *msg) { printf("problem: %s\n", msg); }

int main()
{
    Buffer<16> small;
    Buffer<4096> big;
    printf("%d %g\n", max_of<int>(3, 7), max_of<double>(2.5, 1.5));
    printf("%d %d\n", small.Size(), big.Size());
    printf("%lu %lu\n", (unsigned long) sizeof(small),
           (unsigned long) sizeof(big));
    count<&errors>();
    count<&errors>();
    count<&warnings>();
    printf("%d %d\n", errors, warnings);
    check<complain>(1 + 1 == 3, "arithmetic");
    return 0;
}
