#include <cstddef>
#include <utility>
template<std::size_t X>
struct line_t { enum{value=X}; constexpr line_t(){} };
template<std::size_t line, char c>
constexpr std::integral_constant<bool, false> use_flag(
std::integral_constant<char,c>, line_t<line>
) { return {}; }
#define FLAG_USE( C ) \
constexpr std::integral_constant<bool, true> use_flag( \
std::integral_constant<char,C>, line_t<__LINE__> \
) { return {}; }
template<char c, std::size_t line>
constexpr std::size_t count_uses( line_t<line> from, line_t<1> length ){
return use_flag( std::integral_constant<char, c>{}, from )();
}
template<char c, std::size_t line>
constexpr std::size_t count_uses( line_t<line> from, line_t<0> length ){
return 0;
}
template<char c, std::size_t f, std::size_t l>
constexpr std::size_t count_uses(line_t<f> from, line_t<l> length ){
return count_uses<c>( from, line_t< l/2 >{} )+ count_uses<c>( line_t< f+l/2>{}, line_t<(l+1)/2>{} );
}
#define UNIQUE(C) \
FLAG_USE(C) \
static_assert( count_uses<C>( line_t<0>{}, line_t<__LINE__+1>{} )==1, "too many" )
UNIQUE('a');
UNIQUE('b');
UNIQUE('c');
UNIQUE('a');
int main() {}
I2luY2x1ZGUgPGNzdGRkZWY+CiNpbmNsdWRlIDx1dGlsaXR5PgoKCXRlbXBsYXRlPHN0ZDo6c2l6ZV90IFg+CglzdHJ1Y3QgbGluZV90IHsgZW51bXt2YWx1ZT1YfTsgY29uc3RleHByIGxpbmVfdCgpe30gfTsKCQoJdGVtcGxhdGU8c3RkOjpzaXplX3QgbGluZSwgY2hhciBjPgoJY29uc3RleHByIHN0ZDo6aW50ZWdyYWxfY29uc3RhbnQ8Ym9vbCwgZmFsc2U+IHVzZV9mbGFnKAoJICBzdGQ6OmludGVncmFsX2NvbnN0YW50PGNoYXIsYz4sIGxpbmVfdDxsaW5lPgoJKSB7IHJldHVybiB7fTsgfQoJCgkjZGVmaW5lIEZMQUdfVVNFKCBDICkgXAoJY29uc3RleHByIHN0ZDo6aW50ZWdyYWxfY29uc3RhbnQ8Ym9vbCwgdHJ1ZT4gdXNlX2ZsYWcoIFwKCSAg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ertion failed: too many
static_assert( count_uses<C>( line_t<0>{}, line_t<__LINE__+1>{} )==1, "too many" )
^
prog.cpp:38:1: note: in expansion of macro ‘UNIQUE’
UNIQUE('a');
^~~~~~