Кресты / Говнокод #28158 Ссылка на оригинал

0

  1. 1
#define $(x) [&](void)->auto{try{return (x);}catch(...){return decltype(x){};}}()

Собачка

Запостил: kcalbCube kcalbCube, (Updated )

Комментарии (9) RSS

  • Твой доллар глючный.

    https://ideone.com/vILTv5
    #include <stdio.h>
    
    #define $(x) [&](void)->auto{try{return (x);}catch(...){return decltype(x){};}}()
    
    int foo() {
        int a[1];
        return a[10005000];
    }
    
    int main() {
        $(printf("Hello, kcalb\n"));
        $(printf("%d\n", foo()));
        $(printf("Hello, kcalb\n"));
    }
    Ответить
  • Так же не работает $(cout << 42 << endl), проверь.
    Ответить
    • #include <type_traits>
      
      template<typename T>
          requires (!std::is_reference_v<std::invoke_result_t<T>>)
      auto $impl(const T& f) -> decltype(f())
      {
          try
          {
              return f();
          }
          catch(...)
          {
              return decltype(f())();
          }
      }
      template<typename T>
          requires std::is_reference_v<std::invoke_result_t<T>>
      void $impl(const T& f)
      {
          try
          {
              f();
          }
          catch(...){}
      }
      
      #define $(x) $impl([&](void) -> decltype(x) {return x;})
      
      int main(void)
      {
          auto a = [](void) -> int
          {
              throw 1;
              return 1;
          };
      
          $(std::cout << 1);
          return $(a());
      }


      работает проверяй
      Ответить

Добавить комментарий

Из-за тебя ушел bormand, guest!

    А не использовать ли нам bbcode?


    8