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

    −1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    template<typename T>
    T gcd(T a, T b) {
    #pragma python(gcd)
        while b != 0:
            a, b = b, a % b
        return a
    }

    всех с праздником, посоны
    http://codeforces.com/blog/entry/44124

    3_dar, 01 Апреля 2016

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

    +6

    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
    #ifdef _WIN32
    ...
    #elif defined __linux__
                std::string path;
                char buff[PATH_MAX];
                ssize_t len = ::readlink("/proc/self/exe", buff, sizeof(buff)-1);
                if (len != -1)
                {
                  buff[len] = '\0';
                  path = buff;
                }
                else
                {
                    return -1;
                }
    
                int pos = path.rfind("/");
                if (pos == std::string::npos)
                    return - 1;
    
                path = path.substr(0, pos + 1);
                path += "updater";
                std::string sys_path = path;
                boost::replace_all(sys_path, " ", "\\ ");
                std::string rm = "rm -f ";
                rm += sys_path;
                system(rm.c_str());
                _data.save_2_file(core::tools::from_utf8(path));
                std::string chmod = "chmod 755 ";
                chmod += sys_path;
                system(chmod.c_str());
                system(sys_path.c_str());
    #endif //_WIN32

    Как правильно обновлять #mailru/icqdesktop на Linux, если вы понимаете о чём я.

    gmmephisto, 31 Марта 2016

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

    +8

    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
    template <size_t capacity, bool is_signed>
    class fixed_int
    {	
        // Описание ошибки компиляции в случае использования не поддерживаемой размерности 
        template <int x> struct unsupported_capacity { int i[1/(x-x)]; };
        template <> struct unsupported_capacity<1> {};
        template <> struct unsupported_capacity<2> {};
        template <> struct unsupported_capacity<4> {};
        template <> struct unsupported_capacity<8> {};
    
        // Свойства базовых типов, необходимые для перебора
        template<typename type> struct type_traits;
        template<> struct type_traits <unsigned char> { typedef unsigned char current_type; typedef unsigned short next_type; };
        template<> struct type_traits <unsigned short> { typedef unsigned short current_type; typedef unsigned int next_type; };
        template<> struct type_traits <unsigned int> { typedef unsigned int current_type; typedef unsigned long next_type; };
        template<> struct type_traits <unsigned long> {	typedef unsigned long current_type; typedef unsigned long long next_type; };
        template<> struct type_traits <unsigned long long int> { typedef unsigned long long int current_type;  typedef unsupported_capacity<capacity> next_type; };
        template<> struct type_traits <signed char> { typedef signed char current_type; typedef short next_type; };
        template<> struct type_traits <short> { typedef short current_type; typedef int next_type; };
        template<> struct type_traits <int> { typedef int current_type; typedef long next_type; };
        template<> struct type_traits <long> { typedef long current_type; typedef long long next_type; };
        template<> struct type_traits <long long int> { typedef long long int current_type;  typedef unsupported_capacity<capacity> next_type;};
    
        // Алгоритм выбора типа
        template<typename type, bool> 
        struct type_choice 
        { 
            typedef typename type_traits<type>::current_type std_type; 
        };
        template<typename type> 
        struct type_choice<type, false> 
        { 
            typedef typename type_traits<type>::next_type next_type; 
            typedef typename type_choice<next_type, sizeof(next_type) == capacity>::std_type std_type; 
        };
    
        // Базовый тип для начала подбора
        template <bool is_signed> struct base_type_selector { typedef signed char base_type; };
        template <> struct base_type_selector<false> { typedef unsigned char base_type; };
    
    public:
    
        typedef typename type_choice< typename base_type_selector<is_signed>::base_type, sizeof(base_type_selector<is_signed>::base_type) == capacity >::std_type type;
    
    };

    "Зачем мне нужен stdint.h?
    У меня нет времени, чтобы ебаться с ним!
    Лучше я высру ещё десяток-другой шаблонов!"
    https://habrahabr.ru/post/280542/

    PS,
    Пятая строка - вообще угар.

    gost, 31 Марта 2016

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

    +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
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    template < typename CType >
        void list < CType >::sorted_push(CType val, long int key)
    {
    	if (head) {
    		// Создаём контейнер и помещаем в него полученное значение
    		container < CType > *new_cont;
    		container < CType > *tmp = head;
    
    		new_cont = new container < CType >;
    		new_cont->set_key(key);
    		new_cont->set_cargo(val);
    
    		while ((tmp != tail) && (key > (tmp->get_key())))
    			tmp = tmp->get_next();
    
    		if ((tmp == tail) && (key > (tmp->get_key()))) {	// Если выполнились одновременно два условия в цикле
    			new_cont->set_next(tmp->get_next());	// Вставляем в самый конец
    			new_cont->set_past(tmp);
    			tmp->set_next(new_cont);
    			tail = new_cont;
    		} else {
    			new_cont->set_next(tmp);
    			new_cont->set_past(tmp->get_past());
    			if ((tmp->get_past()) != NULL)
    				tmp->get_past()->set_next(new_cont);
    			if (tmp == head)
    				head = new_cont;
    			tmp->set_past(new_cont);
    		}
    
    		if (empty) {
    			empty = false;
    			tail = head;
    		}
    	} else {
    		container < CType > *new_cont;
    
    		new_cont = new container < CType >;
    		new_cont->set_key(key);
    		new_cont->set_cargo(val);
    
    		new_cont->set_next(head);
    		tail = head = new_cont;
    		empty = false;
    	}
    }
    
    template < typename CType > CType queue < CType >::pop()
    {
    	container < CType > *tmp = list<CType>::head;
    
    	if (tmp == NULL) {
    		std::cerr <<
    		    "Стек пуст! Стек возвращает мусор! ";
    		list<CType>::empty = true;
    	} else {
    		CType tmpval = list<CType>::head->get_cargo();
    		// Переходим к следующему элементу
    		list<CType>::head = list<CType>::head->get_next();
    		if (list<CType>::head == NULL)
    			list<CType>::empty = true;
    		delete tmp;
    		return tmpval;
    	}
    }
    
    template < typename CType > CType stack < CType >::pop()
    {
    	container < CType > *tmp = list<CType>::tail;
    
    	if (tmp == NULL) {
    		std::cerr <<
    		    "Очередь пуста! Возвращается мусор! ";
    		list<CType>::empty = true;
    	} else {
    		CType tmpval = list<CType>::tail->get_cargo();
    
    		// Переходим к предыдущему элементу
    
    		if (list<CType>::tail != list<CType>::head)
    			list<CType>::tail = list<CType>::tail->get_past();
    		else
    			list<CType>::empty = true;
    		delete tmp;
    		return tmpval;
    	}
    }

    пострелял себе в ногу

    viktorokh96, 25 Марта 2016

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

    +10

    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
    #define class KOKOKO
    #include <sys/shutdown.h>
    #undef class
    
    /* внутри sys/shutdown.h:
    
    typedef struct
    {
        uint64_t start_time;
        pid_t pid;
        int8_t class;
        uint8_t padding[3];
        char *name;
    } ProcessInfo_t;
    */

    перезагружаем qnx neutrino из крестового кода

    Xom94ok, 22 Марта 2016

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

    +3

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    #include <vector>
    
    template <typename T>
    void FreeAll( T & t ) {
        T tmp;
        t.swap( tmp );
    }

    3_dar, 20 Марта 2016

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

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    /**
      * @brief Макрос вызова функции изменения имени файла лога ПИМ
      *
      * @param FILE_NAME  Имя файла лога
      *
      * @return Ничего
      */
    #define LOG_PIM_SET_FILE_NAME(FILE_NAME)  Soc::setLogFileName(FILE_NAME)

    Самый нужный макрос в мире

    cpp_best_practo, 17 Марта 2016

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

    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
    #include <iostream>
    
    using namespace std;
    
    int main(){
        int n = 60;
        int a = 1 << n;
        cout << a << endl;
        n = 33;
        a = 1 << n;
        cout << a << endl;
        unsigned m = 33;
        unsigned b = 1u << m;
        cout << b << endl;
        // a = 1 << 32;
        // cout << a << endl;
        return 0;
    }

    Моар:
    http://acm.math.spbu.ru/~kunyavskiy/cpp/sol02.cpp

    UltimateDelighter, 16 Марта 2016

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

    +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
    void g()
    {
        int sum;
        auto rec = [&sum](int i) -> int
        {
            static int (*inner)(int&, int) = [](int& _sum, int i)->int 
            {
                _sum += i;
                return i>0 ? inner(_sum, i-1)*i : 1; 
            };
            return inner(sum, i);
        };
    }

    LispGovno, 15 Марта 2016

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    QMutableListIterator<AISObjectQML *> it(m_visibleList);
    if (it.hasNext()) {
        AISObjectQML *v = it.next();
        if (v) { // здесь должен быть while, но, признаться, на это уже посрать
            delete v;
        }
    }
    m_visibleList.clear();

    Есть люди, которые придумали концепцию итераторов для реализации generic алгоритмов. А есть люди, которые любят итераторы, но не любят generic алгоритмы. Ведь с ними код не внушает ужаса и рвотных позывов

    Antervis, 15 Марта 2016

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