#include <iostream>

    template <unsigned SIZE>
    struct offset_size {
        typedef typename offset_size<SIZE - 1>::type type;
    };

    template <>
    struct offset_size<0> {
        typedef unsigned char type;
    };

    template <>
    struct offset_size<257> {
        typedef unsigned int type;
    };

    template<unsigned SIZE>
    class circular_buffer {
    public: // Added this line so we can inspect the sizes from main()
       unsigned char buffer[SIZE];
       typename offset_size<SIZE>::type head; // index
       typename offset_size<SIZE>::type tail; // index
    };
    
int main() {
    std::cout << sizeof(circular_buffer<256>().head) << std::endl;
    std::cout << sizeof(circular_buffer<257>().head) << std::endl;
}