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

    +10

    1. 1
    2. 2
    ... std::bind(&decltype(x)::bar, foo, _1);
    ... std::bind(&decltype(*foo.operator->())::bar, foo.operator->(), _1);

    С сайта, имя которого можно не называть.

    LispGovno, 02 Июля 2013

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

    +25

    1. 1
    2. 2
    while(_right=_right->_right)
    				delete _right;

    All right.

    LispGovno, 01 Июля 2013

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

    +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
    #include "stdafx.h"
    int otv;
    int main()
    {
    	int l[10]={1,1,1,1,1,1,1,1,1,1};
    	start://старт
    	std::cout<<"Enter the number of variables < 10\n";
    	int g;
    	std::cin>>g;
            if(g>=10||g<=0) goto start;
    	std::cout<<"please enter "<<g<<" your numbers\n";
    	for(int y=0;y<g;y++){int z;std::cin>>z;l[y]=z;}
    	for(int y=0;y<g;y++){std::cout<<l[y]<<", ";}
    	otv=l[0]*l[1]*l[2]*l[3]*l[4]*l[5]*l[6]*l[7]*l[8]*l[9];
    	std::cout<<"answer is "<< otv <<'\n';
    	return 0;}

    Кальцо еще то.

    govnor, 29 Июня 2013

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

    +8

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    int wordLen(const char* word) 
    { 
        int i=-1; 
        while(word[++i]!='\0'&&word[i]!='\n'); 
        return i; 
    }

    Типичная лаба, но как же смешно это увидеть спустя некоторое время

    iofjuupasli, 29 Июня 2013

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

    +29

    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
    //thirteen
            Cluster cl;
            Cluster empty;
            I--;
            if(distances.size()){
                for (int i = 0; i < (Lmax < distances.size() ? Lmax : distances.size()); ++i){
                    cl.X(( clusters.at(distances.at(i).first.first).X()*clusters.at(distances.at(i).first.first).Points().size() + clusters.at(distances.at(i).first.second).X()*clusters.at(distances.at(i).first.second).Points().size())/(clusters.at(distances.at(i).first.first).Points().size() + clusters.at(distances.at(i).first.second).Points().size()));
                    cl.Y(( clusters.at(distances.at(i).first.first).Y()*clusters.at(distances.at(i).first.first).Points().size() + clusters.at(distances.at(i).first.second).Y()*clusters.at(distances.at(i).first.second).Points().size())/(clusters.at(distances.at(i).first.first).Points().size() + clusters.at(distances.at(i).first.second).Points().size()));
                    if(clusters.at(distances.at(i).first.second).Number() != -1 && clusters.at(distances.at(i).first.first).Number() != -2){
                        cl.Points() = clusters.at(distances.at(i).first.second).Points();
                        clusters.at(distances.at(i).first.second) = cl;
                        clusters.at(distances.at(i).first.second).Number(-1);
                        for (std::vector<Point>::iterator j = clusters.at(distances.at(i).first.first).Points().begin(); j != clusters.at(distances.at(i).first.first).Points().end(); ++j)
                        {
                        	clusters.at(distances.at(i).first.second).Points().push_back(*j);
                        }
                        clusters.at(distances.at(i).first.first) = empty;
                        n_c--;
                    }
                }
                for (std::vector<Cluster>::iterator i = clusters.begin(); i != clusters.end(); ++i){
                    if(i->Number() == -2){
                        i = clusters.erase(i);
                    }
                    i->Number(i - clusters.begin());
                    if(I)i->Points().clear();
                    if(i == clusters.end())break;
                }
            }
            //fourteen

    Кусок алгоритма isodata

    Abbath, 28 Июня 2013

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

    +24

    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
    any<
        mpl::vector<
            copy_constructible<>,
            typeid_<>,
            incrementable<>,
            ostreamable<>
        >
    > x(10);
    ++x;
    std::cout << x << std::endl; // prints 11
    
    
    
    The library provides concepts for most C++ operators, but this obviously won't cover all use cases; we often need to define our own requirements. Let's take the push_back member, defined by several STL containers.
    BOOST_TYPE_ERASURE_MEMBER((has_push_back), push_back, 1)
    
    void append_many(any<has_push_back<void(int)>, _self&> container) {
        for(int i = 0; i < 10; ++i)
            container.push_back(i);
    }

    Я ждал этого! В С++ добавили dynamic из сишарпика.

    LispGovno, 27 Июня 2013

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

    +34

    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
    class A
    {
    public:
        unsigned int m_value;
    
        inline bool operator != ( const A & value )
        {
            unsigned int temp;
            temp = 0 != ( m_value != value.m_value );
            return 0 == temp;
        }
    
        inline bool operator == ( const A & value )
        {
            unsigned int temp;
            temp = 0 != ( m_value == value.m_value );
            return 0 != temp;
        }
    };

    Фрагмент кода одной коммерческой библиотеки. Имя класса изменено, 100500 прочих методов вырезано, но они похожи на эти.
    Я не буду акцентировать внимание на том, что операторы невозможно использовать для константных объектов, даже не буду говорить о странном способе сравнения целых чисел... Но я упомяну о том, что 'operator !=' работает немножко не так, как руссо-индусы ожидали.

    Little-Horny, 24 Июня 2013

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

    +14

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    int error = (unsigned)-1;
    
    int x, y, w, h;
    x = y = w = h = error;
    
    stream >> x >> y >> w >> h;
    
    if(x == error || y == error || w == error || h == error)
       ...

    Не нашёл, как по-другому обрабатывать ошибки текстовых командах.

    an0nym, 24 Июня 2013

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

    +16

    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
    // Lock the write mutex, to provide consistency of data                                                                                            
    #define LOCK                                                                   \                                                                   
        if (_ugb) {                                                                \                                                                   
            if (pthread_mutex_lock(&_write_mutex) == EINVAL)                       \                                                                   
                ASSERT(0);                                                         \                                                                   
        }                                                                                                                                              
    // Unlock write mutex when data sent                                                                                                               
    #define UNLOCK                                                                 \                                                                   
        if (_ugb) {                                                                \                                                                   
            if (pthread_mutex_unlock(&_write_mutex) == EINVAL)                     \                                                                   
                ASSERT(0);                                                         \                                                                   
        } 
    
    // Пример использования
    
    void socket::add_var(uint16_t code, const void *buffer, uint32_t length)                                                                          
    {                                                                                                                                                  
        LOCK
        try                                                                                                                                       
        {                                                                                                                                              
            DEBUG_I(Vblock, "Sending code 0x%X of size 0x%X\n", code, length);                                                                         
            send(&code, sizeof(code));                                                                                                                 
            send(&length, sizeof(length));                                                                                                             
            send(buffer, length);                                                                                                                      
        }                                                                                                                                              
        catch (const error & ve)                                                                                                                       
        {                                                                                                                                              
            UNLOCK                                                                                                                                     
            DEBUG_E(Vblock, "Caught an exception!\n");                                                                                                 
            throw;                                                                                                                                     
        }                                                                                                                                              
        catch (...)                                                                                                                                    
        {                                                                                                                                              
            UNLOCK                                                                                                                                     
        }                                                                                                                                              
        UNLOCK                                                                                                                                         
    }

    OK_BOOST_LOCK_A_MUTEX

    roman-kashitsyn, 21 Июня 2013

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

    +16

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    for(int i=0;i<World::size;i++)
    {
        for(int u=0;u<World::size;u++)
        {
                    //Задаётся зерно для генерации случайных чисел
            srand(GetTickCount()*i*u);                           
                    //Задаются случайные значения всем точкам от 0*0.1-10, до 100*0.1-10
            World::data[i][u]=(rand()%100)*0.1f-10.0f;                            
        }
    }

    http://habrahabr.ru/post/183986/

    Abbath, 20 Июня 2013

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