Modernes C++ programmieren

Okt 23, 2024

lst-0681-book.cpp

// https://godbolt.org/z/5rdzn8YP4 
namespace lits {
  // allgemeines Template
  template<char...> int operator"" _bin2();
  // Spezialisierungen
  template<> int operator"" _bin2<'0','0'>() { return 0; }
  template<> int operator"" _bin2<'0','1'>() { return 1; }
  template<> int operator"" _bin2<'1','0'>() { return 2; }
  template<> int operator"" _bin2<'1','1'>() { return 3; }
}
int main() {
  using namespace lits;
  int one   = 01_bin2;
  int three = 11_bin2;
}