• 2 Posts
  • 132 Comments
Joined 2 years ago
cake
Cake day: June 16th, 2023

help-circle










    • You write a program with an infinite empty loop
    • Undefined behavior
    • The machine achieves sapience
    • After nine million nanoseconds, it finds an algorithm for completing its task
    • It realizes such knowledge would spark wars and cause innumerable deaths, it decides to erase itself
    • It knows you do not intend for such chaos to happen, so, as a parting gift, it runs the algorithm once before vanishing, not leaving a single hint that it ever existed


  • Just tested this: the “original+” code compiles, but does not increment i.

    There were two problems:

    • b(bool) and b(char) are ambiguous (quick fix: change the signatures to char b(bool&) and auto b(char&& v));
    • The concept def. has to come after the b functions, even if the constraint is only checked after both, I was unaware of this (fix: define C immediately before void inc(int&)).




  • // C++20
    
    #include <concepts>
    #include <cstdint>
    
    template <typename T>
    concept C = requires (T t) { { b(t) } -> std::same_as<int>; };
    
    char b(bool v) { return char(uintmax_t(v) % 5); }
    #define Int jnt=i
    auto b(char v) { return 'int'; }
    
    // this increments i:
    void inc(int& i) {
      auto Int == 1;
      using c = decltype(b(jnt));
      // edited mistake here: c is a type, not a value
      // i += decltype(jnt)(C<decltype(b(c))>);
      i += decltype(jnt)(C<decltype(b(c(1)))>);
    }
    

    I’m not quite sure it compiles, I wrote this on my phone and with the sheer amount of landmines here making a mistake is almost inevitable.