1. C++ / Говнокод #28158

    0

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

    Собачка

    kcalbCube, 09 Мая 2022

    Комментарии (9)
  2. C++ / Говнокод #28153

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    #include <iostream>
    #include <vector>
    #include <string>
    
    int main()
    {
        int n = 6;
        std::vector<int> vec;
    
        for (int i = 0; i < n; i++)
        {
            if ((i % 2) == 0)
            {
                std::reverse(vec.begin(), vec.end());
            }
    
            vec.push_back(i);
    
            if ((i % 2) != 0)
            {
                std::reverse(vec.begin(), vec.end());
            }
    
            for (int j = 0; j < vec.size(); j++)
            {
                std::cout << vec[j] + 1;
                if (j != vec.size() - 1)
                {
                    std::cout << "-";
                }
            }
            std::cout << "\n";
    
        }
    }

    Цель напечатать на экране следующее:
    1
    2-1
    1-2-3
    4-3-2-1
    1-2-3-4-5
    6-5-4-3-2-1

    насколько это говнокод от 0 до 10?

    pistael, 05 Мая 2022

    Комментарии (28)
  3. C++ / Говнокод #28148

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    // Ручной режим
        if (!botMode) {
            cout << "Manual mode activated\n";
            Sleep(1000);
    
            while (1) {                                             // Основной цикл
    
                MAP = modMap(pos, MAP, PVM);
                auto moveField =  moveMapField(MAP);
                auto TVM = waveViewCheck(pos, MAP);                 // Вызов функции проверки видимости элементов
                PVM = refreshMap(PVM, TVM);
    
                system("cls");                                      // Очистка поля с каждой итерацией
                coutMAP(pos, MAP);                                  // Вывод всей карты
                cout << endl;
                coutMAP(pos, PVM);                                  // Вывод видимой карты
    
                if (MAP[pos.y][pos.x] == END) {
                    cout << endl << "Level Complete!\n";
                    Sleep(3000);
                    return 0;
                }
    
                int k = getch();
                if (k == 113 || k == 81) break;                     // Press Q - exit
                if (k == 224) k = getch();
                switch (k) {                                // Перемещение стрелочками
                    case 72:                                // Вверх
                        if ((moveField[pos.y-1][pos.x] == BLANK || (moveField[pos.y-1][pos.x] > 0 && MAP[pos.y-1][pos.x] % 2 == 1)) && pos.y > 0) {
                            pos.y -= 1;
                        }
                        break;
                    case 75:                                // Влево
                        if ((moveField[pos.y][pos.x-1] != WALL || (moveField[pos.y][pos.x-1] > 0 && MAP[pos.y][pos.x-1] % 2 == 1)) && pos.y > 0) {
                            pos.x -= 1;
                        }
                        break;
                    case 77:                                // Вправо
                        if ((moveField[pos.y][pos.x+1] != WALL || (moveField[pos.y][pos.x+1] > 0 && MAP[pos.y][pos.x+1] % 2 == 1)) && pos.y > 0) {
                            pos.x += 1;
                        }
                        break;
                    case 80:                                // Вниз
                        if ((moveField[pos.y+1][pos.x] != WALL || (moveField[pos.y+1][pos.x] > 0 && MAP[pos.y+1][pos.x] % 2 == 1)) && pos.y > 0) {
                            pos.y += 1;
                        }
                        break;
                }
            }
        }

    kcalbCube, 01 Мая 2022

    Комментарии (32)
  4. C++ / Говнокод #28140

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    #include <iostream>
    #include <string_view>
    #include <source_location>
     
    void log(const std::string_view message,
             const std::source_location location = 
                   std::source_location::current())
    {
        std::cout << "file: "
                  << location.file_name() << "("
                  << location.line() << ":"
                  << location.column() << ") `"
                  << location.function_name() << "`: "
                  << message << '\n';
    }
     
    template <typename T> void fun(T x)
    {
        log(x);
    }
     
    int main(int, char*[])
    {
        log("Hello world!");
        fun("Hello C++20!");
    }
    
    file: main.cpp(23:8) `int main(int, char**)`: Hello world!
    file: main.cpp(18:8) `void fun(T) [with T = const char*]`: Hello C++20!

    Previously, functions that desire to obtain this information about the call site (for logging, testing, or debugging purposes) must use macros so that predefined macros like __LINE__ and __FILE__ are expanded in the context of the caller. The source_location class provides a better alternative.

    kcalbCube, 27 Апреля 2022

    Комментарии (5)
  5. C++ / Говнокод #28139

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    #include <iostream>
    #include <vector>
    #include <thread>
    int f()
    {
        static int i = 0;
        synchronized { // begin synchronized block
            std::cout << i << " -> ";
            ++i;       // each call to f() obtains a unique value of i
            std::cout << i << '\n';
            return i; // end synchronized block
        }
    }
    int main()
    {
        std::vector<std::thread> v(10);
        for(auto& t: v)
            t = std::thread([]{ for(int n = 0; n < 10; ++n) f(); });
        for(auto& t: v)
            t.join();
    }
    
    0 -> 1
    1 -> 2
    2 -> 3
    ...
    99 -> 100

    https://en.cppreference.com/w/cpp/language/transactional_memory

    kcalbCube, 27 Апреля 2022

    Комментарии (26)
  6. C++ / Говнокод #28137

    −1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    #include "property.hpp"
    
    class person {
    public:
       person() = default;
       ~person() = default;
    
       SETTER_PRIM(int, id);
       SETTER_FLAG(bool, merried);
       SETTER_ENUM(human, type);
    
       SETTER_PTR(int, next);
       SETTER_ARR(std::string, address, 3);
    
       SETTER_OBJ_LR(std::string,  name);
       SETTER_OBJ_CLR(std::string, name);
       SETTER_OBJ_RR(std::string,  name);
    
       GETTER_PRIM(int, id);
       GETTER_FLAG(bool, merried);
       GETTER_ENUM(human, type);
    
       GETTER_OBJ_LR(std::string,  name);
       GETTER_OBJ_CLR(std::string, name);
    
       GETTER_PTR(int, next);
       GETTER_ARR(std::string, address);
    
    private:
       int id;
       human type;
    
       std::string name;
       std::string address[5];
    
       bool merried;
       int* next;
    };

    https://habr.com/ru/post/459212/

    kcalbCube, 26 Апреля 2022

    Комментарии (76)
  7. C++ / Говнокод #28134

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    template<typename Event>
    void bindEvent(auto function)
    {
        connectionGuards.emplace_back(
            std::make_unique<event::EventConnectionGuard<Event>>(
                std::forward(event::emitter().on<Event>(boost::bind(          
                    boost::mem_fn(function), static_cast<T*>(this), _1))                             
                )
            )
        );
    }

    kcalbCube, 23 Апреля 2022

    Комментарии (13)
  8. C++ / Говнокод #28131

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    #ifndef EXCHANGECLIENTBINANCE_H
    #define EXCHANGECLIENTBINANCE_H
    
    #include "exchangeclient.h"
    
    #include <QScopedPointer>
    #include <QString>
    
    class ExchangeClientBinancePrivate;
    class ExchangeClientBinance : public ExchangeClient<ExchangeClientBinance>
    {
        QScopedPointer<ExchangeClientBinancePrivate> d_ptr;
    public:
        ExchangeClientBinance() noexcept;
        ~ExchangeClientBinance();
        void connect(const ConnectionCredentials& credentials) noexcept;
    };
    
    template<>
    struct ExchangeClient<ExchangeClientBinance>::ConnectionCredentials
    {
        QString apiKey;
        QString secretKey;
    };
    
    #endif // EXCHANGECLIENTBINANCE_H

    jangolare, 22 Апреля 2022

    Комментарии (3)
  9. C++ / Говнокод #28125

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    void remove_spaces(string data)
    { int i=0,j=0;
        while(i<data.length())
        {
            if (isalpha(data[i]))
            {
            data[i]=data[i];
            i++;
            }
            else
                {
                data.erase(i,1);}
        }
        cout<<data;
    }

    kcalbCube, 19 Апреля 2022

    Комментарии (4)
  10. C++ / Говнокод #28124

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    auto&& rv = elements | std::ranges::views::values | std::ranges::views::transform([](auto&& a) -> auto 
    		{
    			StatisticsElementMultiple n = std::move(a);
    			n.nanosec /= n.count;
    			return n;
    		});
    		std::vector<StatisticsElementMultiple> el(std::begin(rv), std::end(rv));
    		std::ranges::sort(el, [](auto&& a, auto&& b) -> bool {return a.nanosec > b.nanosec; });
    		for(auto&& [nanosec, name, prefixes, count] : el)
    		{
    			printf("%-10d %04X %12s %6d\n", count, prefixes, name.c_str(), nanosec);
    		}

    kcalbCube, 18 Апреля 2022

    Комментарии (42)