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

    +14

    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
    Node<maxCnt>   n[sizeY][sizeX], on;
    //...
    auto EachConvex = [](auto f, Body& b) 
    {
      for (auto g : b.g)
      {
        auto cp = Body::ConvexPtr(&b, g);
        auto bounds = cp.bounds();
        auto max = Rect(0, 0, sizeX - 1, sizeY - 1);
        auto out = max.intersect(bounds);
        auto b = max & bounds;
        for (auto x = b.left; x < b.right; ++i)
          for (auto y = b.top; x < b.bottom; ++i)
            f(n[y][x], cp);
        if (out)
          f(on, cp);      
      }
      return true;
    }

    LispGovno, 03 Декабря 2013

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

    +13

    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
    typedef std::queue<Msg> Queue;    
        
    
    struct SharedQueue
    {
        private:
            Queue m_queue;
            boost::mutex m_mux;
            boost::condition_variable m_condvar;    
        private:
            struct is_empty
            {
                Queue& queue;
                is_empty( Queue& q):
                    queue(q)
                {
                }
    
                bool operator()() const
                {
                    return !queue.empty();
                }
            };
        public:
            void push(const Msg& msg)
            {
                boost::mutex::scoped_lock lock(m_mux);
                m_queue.push( msg);
                m_condvar.notify_one();
            }
    
            bool try_pop( Msg& msg, Kind kind)
            {
                boost::system_time const timeout=boost::get_system_time()+ boost::posix_time::milliseconds( 30000);
                boost::mutex::scoped_lock lock( m_mux);
                if ( m_condvar.timed_wait( lock, timeout, is_empty( m_queue)))
                {
                    if( !m_queue.empty() && m_queue.front().kind == kind)
                    {
                        msg = m_queue.front();
                        m_queue.pop();
                        return true;
                    }
                }
                return false;
            }
    };

    Это ж пипец, дорогие товарищи...

    blackhearted, 29 Ноября 2013

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

    +69

    1. 1
    2. 2
    #define BYTEMAX 0xFF 
    #define BYTEOVERFLOW (BYTEMAX+1)

    C++ вокруг. Интересует насколько это вменяемая практика?

    LispGovno, 26 Ноября 2013

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

    +13

    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
    //Сегодня QuestionGovno.
    //Допустим есть код:
    #include <iostream>
    using namespace std;
    class T{};
    struct M{M(T){}};
    struct G{G(T){}};
    
    int f(M){return 0;}
    bool f(G){return 0;}
    
    int main() {
    	bool a(f(T()));
    	return 0;
    }

    Казалось бы должна быть неоднозначность при компиляции, так как компилятор не знает какую перегрузку f бы выбрать.
    И как бы так оно и есть:
    http://ideone.com/o21NDg
    Логично? Логично.
    Но стандарт считает по другому:
    http://en.cppreference.com/w/cpp/language/overload_resolution
    Смотрите пункт:
    Best viable function
    F1 is determined to be a better function than F2 if implicit conversions for all arguments of F1 are not worse than the implicit conversions for all arguments of F2, and
    ...
    2) or. if not that, (only in context of non-class initialization by conversion), the standard conversion sequence from the return type of F1 to the type being initialized is better than the standard conversion sequence from the return type of F2

    Как мне повторить поведение, которое указано в стандарте?

    LispGovno, 22 Ноября 2013

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

    +18

    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
    class figure
    {
    //...
    };
    
    class triugolnik: public figure
    {
    //...
    };
    
    class kvadrat: public figure
    {
    //...
    };
    
    #define PAIR(f0, f1) std::make_tuple(std::type_index(typeid(f0)), std::type_index(typeid(f1)))
    
    int PloshadTrehFigur(const figure& f0, const figure& f1, const figure& f2);//forward declaration
    int PloshadDvuhFigur(const figure& f0, const figure& f1)
    {
      static const std::unordered_map<
        std::tuple<std::type_index, std::type_index>, std::function<int(const figure&, const figure&)> 
      > caller 
        {
           {PAIR(triugolnik, kvadrat), ploshadTriugolnikIKvadrat},
           {PAIR(kvadrat, triugolnik), lispGovno::flip(ploshadTriugolnikIKvadrat)},
           {PAIR(kvadrat, kvadrat), ploshadKvadratIKvadrat},
           {PAIR(triugolnik, triugolnik), ploshadTriugolnikITriugolnik}
        };
        const auto& f = caller.find(PAIR(f0, f1));
        assert(f!=caller.end());
        f(f0, f1);
    }
    
    #undef PAIR

    Наш ответ Чемберлену:
    http://govnokod.ru/13933
    lispGovno::flip - flip такой же как в хаскель из моей особой мегабиблиотеки победителя каждый день.
    Шах и мат господа присяжные засидатели. Мультиметоды в крестах есть и реализуются за 5 минут.
    В сишке аналогично. Все анскилябры залезли под кровати.
    Визитары размазанные по коду сосут и трудно поддерживаются.

    LispGovno, 20 Ноября 2013

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

    +12

    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>
    
    class base
    {
    	virtual void on_create() { }
    public:
    	int value;
    	float another_value;
    
    	void create()
    	{
    		static base test;
    		if(*reinterpret_cast<unsigned int *>(this) != *reinterpret_cast<unsigned int *>(&test))
    		{
    			std::cout << "please, do not override on_create()\n";
    		}
    		on_create();
    	}
    };
    
    class derived : public base
    {
    	virtual void on_create(){}
    };
    
    int main(int argc, char * argv[])
    {
    	std::cout << "base\n";
    	base b;
    	b.create();
    
    	std::cout << "derived\n";
    	derived d;
    	d.create();
    }

    Родилось в попытке ограничить переопределение виртуального метода.
    Работает, цуко.
    http://ideone.com/gUN9OA

    Xom94ok, 20 Ноября 2013

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

    +11

    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
    void run(std::map<QString, QString> params,QTextStream &os) const
    	{
    
    		static int ko=0;
    			ko++;
    			//r->method_="GET";
    			srand(time(0));// без этого числа будут одинаковые
    			QString  randomData="["+ (QString::number(ko))+" , "+ (QString::number(rand()%100))+ "]";
    			//int index= params["idChpu"].toInt();
    			std::list<QString> idsparams=getIdsDataRequest(params["dataRequestIds"]);
    			QString dataInIds="";
    			//for (auto idParam=idsparams.begin();idParam!=idsparams.end();idParam++)
    			for (const auto &idParam : idsparams)
    			{
    				qDebug()<<idParam;
    				auto kokoFunction=[](const std::function<QString()> & function){QString date; for(auto i=0 ;i<10;i++){date+= function()+QString(" , ");} ; return date;};
    				if (idParam==QString("id0"))
    				{dataInIds=dataInIds+QString("\"")+(idParam)+QString("\"")+QString(":[")+kokoFunction([](){return QString::number((ko++));})+QString::number((ko++))+QString("],");}
    				else
    				{dataInIds=dataInIds+QString("\"")+(idParam)+QString("\"")+QString(":[")+kokoFunction([](){return QString::number(rand()%100);})+QString::number(rand()%100)+QString("],");}
    			};
    			QString jsonData=QString("{")+
    						QString("\"idLastKey\":\"10\",")+dataInIds+QString("}");
    
    		qDebug()<<"TgetDataOnRequest run</h1>";
    		os << "HTTP/1.0 200 Ok\r\n"
    				"Content-Type: text/html; charset=\"windows-1251\"\r\n"
    				"\r\n"<<jsonData<<//randomData<<
    				"\n";
    
    //				  << QDateTime::currentDateTime().toString() << connectionSettings.getUrl()<<"\r\n"<<connectionSettings.getViewRequest()<<"\n";
    	}

    Надеюсь это временный код, но очень сомневаюсь.

    laMer007, 20 Ноября 2013

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

    +16

    1. 1
    2. 2
    const TReferenceToConstantStringSlice TFileTransfer::Beginer="<HTML><HEAD><FONT SIZE=6><A HREF='/'>Конфиденциально</A></FONT SIZE></HEAD><BODY><BR>";
    const TReferenceToConstantStringSlice TFileTransfer::Ender="</BODY></HTML>";

    Конфиденциально - это я сейчас стер.

    laMer007, 20 Ноября 2013

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

    +10

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    void operator()()
    	{
    		for (std::list<SmartPointer<FunctorTriggerParent > >::iterator it = _listFunctorOnTrigger.begin(); it != _listFunctorOnTrigger.end(); ++it)
    		{
    			(*it)->operator ()();
    		}
    	};

    laMer007, 18 Ноября 2013

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

    +80

    1. 1
    new

    TarasB, 13 Ноября 2013

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