fork(1) download
  1. #include <iostream>
  2.  
  3. constexpr size_t to_bin(const char* str, size_t i) //i is last index of string
  4. {
  5. return i == 0 ? str[i] - '0' : str[i] - '0' + to_bin(str, i - 1) * 2;
  6. }
  7.  
  8. constexpr size_t operator "" _bin(const char* str, size_t len)
  9. {
  10. return to_bin(str, len - 1);
  11. }
  12.  
  13. int main()
  14. {
  15. std::cout << "101"_bin << std::endl;
  16. }
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
5