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

    +1

    1. 1
    https://www.google.com/search?q=%D0%B2%D0%BE%D1%80%D0%B5%D1%86%D0%B8%D0%B8

    Насрали так, что все ссылки ведут на говнокод.
    Как эта херомантия называется в науке?
    3.14159265359, это ты придумал слово "вореции"?

    3_dar, 12 Апреля 2016

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

    +3

    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
    #if defined(OSVR_WINDOWS)
        static const auto SEARCH_PATH_ENV = "PATH";
        static const auto SEARCH_PATH_SEP = ";";
    #else
        static const auto SEARCH_PATH_ENV = "LD_LIBRARY_PATH";
        static const auto SEARCH_PATH_SEP = ":";
    #endif
    
    
    void wrappedPutenv(std::string const &val) {
    #ifdef _MSC_VER
                _putenv_s(SEARCH_PATH_ENV, val.c_str());
    #else // not microsoft runtime specific
                auto newValue = SEARCH_PATH_ENV + "=" + val;
                // Have to allocate new string because it becomes part of the
                // environment.
                char *newString = static_cast<char *>(malloc(newValue.size() + 1));
                std::copy(begin(newValue), end(newValue), newString);
    #endif
    }

    Момент, когда я считаю, что C++-ный auto -- чистое зло(строка 14).
    Код из OSVR-Vive, плагина к OSVR, который работает с HTC Vive.

    a1batross, 08 Апреля 2016

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

    +4

    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
    constexpr Fraction operator+(const Fraction& fraction) const noexcept
        {
            const Fraction max_fraction_by_denominator{denominator > fraction.denominator ? *this : fraction};
            const Fraction min_fraction_by_denominator{denominator < fraction.denominator ? *this : fraction};
            const bool is_sim_denominator = max_fraction_by_denominator.denominator %
                                            min_fraction_by_denominator.denominator == 0;
            int sim_denominator = is_sim_denominator ?
                max_fraction_by_denominator.denominator : (max_fraction_by_denominator.denominator *
                min_fraction_by_denominator.denominator);
            const int nominator1 = is_sim_denominator ? (min_fraction_by_denominator.nominator *
                max_fraction_by_denominator.denominator / min_fraction_by_denominator.denominator) :
                min_fraction_by_denominator.nominator * max_fraction_by_denominator.denominator;
            const int nominator2 = is_sim_denominator ? max_fraction_by_denominator.nominator :
                max_fraction_by_denominator.nominator * min_fraction_by_denominator.denominator;
            int nominators_sum = nominator1 + nominator2;
            int while_parts_sum = while_part + fraction.while_part;
    
            while (nominators_sum >= sim_denominator)
            {
                nominators_sum -= sim_denominator;
                ++while_parts_sum;
            }
    
            if (!nominators_sum)
                sim_denominator = 0;
    
            return {while_parts_sum, nominators_sum, sim_denominator};
        }

    jangolare, 06 Апреля 2016

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

    +2

    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
    // TODO: Refactor to one call of 'refineIndexes'
      std::vector<float32_t> *refined_left_1_3 = rec.refineIndexes(LEFT_CHANNEL, std::get<1>(p_l1) * ATT_3dB, INTERP_LINEAR, CROSS_RISE);
      std::vector<float32_t> *refined_right_1_3 = rec.refineIndexes(RIGHT_CHANNEL, std::get<1>(p_r1) * ATT_3dB, INTERP_LINEAR, CROSS_RISE);
      std::vector<float32_t> *refined_left_1_6 = rec.refineIndexes(LEFT_CHANNEL, std::get<1>(p_l1) * ATT_6dB, INTERP_LINEAR, CROSS_FALL);
      std::vector<float32_t> *refined_right_1_6 = rec.refineIndexes(RIGHT_CHANNEL, std::get<1>(p_r1) * ATT_6dB, INTERP_LINEAR, CROSS_FALL);
      std::vector<float32_t> *refined_left_2_3 = rec.refineIndexes(LEFT_CHANNEL, std::get<1>(p_l2) * ATT_3dB, INTERP_PARABOLIC, CROSS_RISE);
      std::vector<float32_t> *refined_right_2_3 = rec.refineIndexes(RIGHT_CHANNEL, std::get<1>(p_r2) * ATT_3dB, INTERP_PARABOLIC, CROSS_RISE);
      std::vector<float32_t> *refined_left_2_6 = rec.refineIndexes(LEFT_CHANNEL, std::get<1>(p_l2) * ATT_6dB, INTERP_PARABOLIC, CROSS_FALL);
      std::vector<float32_t> *refined_right_2_6 = rec.refineIndexes(RIGHT_CHANNEL, std::get<1>(p_r2) * ATT_6dB, INTERP_PARABOLIC, CROSS_FALL);
      
      bool exists_att_3dB = refined_left_1_3->size() > 0 && refined_right_1_3->size() > 0 && refined_left_2_3->size() > 0 && refined_right_2_3->size() > 0;
      bool exists_att_6dB = refined_left_1_6->size() > 0 && refined_right_1_6->size() > 0 && refined_left_2_6->size() > 0 && refined_right_2_6->size() > 0;
    
      if (exists_att_3dB || exists_att_6dB)  {
        float32_t rdTOA_l_3, rdTOA_r_3, rdBW_3, rdSW_3, rdTOA_l_6, rdTOA_r_6, rdBW_6, rdSW_6;
        if (exists_att_3dB && !exists_att_6dB) {
          rdTOA_l_6 = rdTOA_l_3 = refined_left_2_3->back() - refined_left_1_3->front();
          rdTOA_r_6 = rdTOA_r_3 = refined_right_2_3->back() - refined_right_1_3->front();
          rdBW_6 = rdBW_3 = refined_left_2_3->back() - refined_right_2_3->back();
          rdSW_6 = rdSW_3 = refined_left_1_3->front() - refined_right_1_3->front();
        } 
        else if (!exists_att_3dB && exists_att_6dB) {
          rdTOA_l_6 = rdTOA_l_3 = refined_left_2_6->back() - refined_left_1_6->front();
          rdTOA_r_6 = rdTOA_r_3 = refined_right_2_6->back() - refined_right_1_6->front();
          rdBW_6 = rdBW_3 = refined_left_2_6->back() - refined_right_2_6->back();
          rdSW_6 = rdSW_3 = refined_left_1_6->front() - refined_right_1_6->front();
        }
        else {
          rdTOA_l_3 = refined_left_2_3->back() - refined_left_1_3->front();
          rdTOA_r_3 = refined_right_2_3->back() - refined_right_1_3->front();
          rdBW_3 = refined_left_2_3->back() - refined_right_2_3->back();
          rdSW_3 = refined_left_1_3->front() - refined_right_1_3->front();
          rdTOA_l_6 = refined_left_2_6->back() - refined_left_1_6->front();
          rdTOA_r_6 = refined_right_2_6->back() - refined_right_1_6->front();
          rdBW_6 = refined_left_2_6->back() - refined_right_2_6->back();
          rdSW_6 = refined_left_1_6->front() - refined_right_1_6->front();
        }
        float32_t rdTOA_l = (rdTOA_l_3 + rdTOA_l_6) / 2f;
        float32_t rdTOA_r =(rdTOA_r_3 + rdTOA_r_6) / 2f;
        float32_t rdBW = (rdBW_3 + rdBW_6) / 2f;
        float32_t rdSW = (rdSW_3 + rdSW_6) / 2f;
    
        //TODO: Watch for group delay compensation!
        float32_t rdeltaTOA = (rdTOA_l + rdTOA_r - 2 * groupDelay) / (2.0 * AUDIO_SAMPLE_RATE_EXACT);
        float32_t rdeltaBlastWave = rdBW / AUDIO_SAMPLE_RATE_EXACT;
        float32_t rdeltaShockWave = rdSW / AUDIO_SAMPLE_RATE_EXACT;
        //..................................................
      if (sd_init_status == SD_OK && current_settings.log) logFile.close();
    
      refined_left_1_3->clear();
      refined_right_1_3->clear();
      refined_left_2_3->clear();
      refined_right_2_3->clear();
      refined_left_1_6->clear();
      refined_right_1_6->clear();
      refined_left_2_6->clear();
      refined_right_2_6->clear();
    
      delete refined_left_1_3;
      delete refined_right_1_3;
      delete refined_left_2_3;
      delete refined_right_2_3;
      delete refined_left_1_6;
      delete refined_right_1_6;
      delete refined_left_2_6;
      delete refined_right_2_6;

    50 часов без сна... Чувствую я пожалею завтра о том, что сегодня это написал.

    FMB, 06 Апреля 2016

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

    +4

    1. 1
    2. 2
    3. 3
    typedef class foo_c{
    ...
    } foo_t;

    Почему мне хочется использовать такой синтаксис?

    mittorn, 04 Апреля 2016

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

    +4

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    class Panel
    {
    // ...
    friend class Panel;
    // ...
    }

    Нашёл такое в хедерах VGUI1 -- игрового тулкита от Valve для Gold Source.
    Объясните, умные люди, зачем?

    a1batross, 01 Апреля 2016

    Комментарии (8)
  7. 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)
  8. 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)
  9. 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)
  10. 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)