fork download
  1. #include <cstddef>
  2. #include <utility>
  3.  
  4. template<std::size_t X>
  5. struct line_t { enum{value=X}; constexpr line_t(){} };
  6.  
  7. template<std::size_t line, char c>
  8. constexpr std::integral_constant<bool, false> use_flag(
  9. std::integral_constant<char,c>, line_t<line>
  10. ) { return {}; }
  11.  
  12. #define FLAG_USE( C ) \
  13. constexpr std::integral_constant<bool, true> use_flag( \
  14. std::integral_constant<char,C>, line_t<__LINE__> \
  15. ) { return {}; }
  16.  
  17. template<char c, std::size_t line>
  18. constexpr std::size_t count_uses( line_t<line> from, line_t<1> length ){
  19. return use_flag( std::integral_constant<char, c>{}, from )();
  20. }
  21. template<char c, std::size_t line>
  22. constexpr std::size_t count_uses( line_t<line> from, line_t<0> length ){
  23. return 0;
  24. }
  25.  
  26. template<char c, std::size_t f, std::size_t l>
  27. constexpr std::size_t count_uses(line_t<f> from, line_t<l> length ){
  28. return count_uses<c>( from, line_t< l/2 >{} )+ count_uses<c>( line_t< f+l/2>{}, line_t<(l+1)/2>{} );
  29. }
  30.  
  31. #define UNIQUE(C) \
  32. FLAG_USE(C) \
  33. static_assert( count_uses<C>( line_t<0>{}, line_t<__LINE__+1>{} )==1, "too many" )
  34.  
  35. UNIQUE('a');
  36. UNIQUE('b');
  37. UNIQUE('c');
  38. UNIQUE('a');
  39.  
  40. int main() {}
Compilation error #stdin compilation error #stdout 0s 15240KB
stdin
Standard input is empty
compilation info
prog.cpp:33:4: error: static assertion 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');
 ^~~~~~
stdout
Standard output is empty