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

    +8

    1. 1
    2. 2
    #define FOR_INCLUSION (iostream) (studio.h) (stdlib.h) (boost/phoenix.hpp) (my_drugs_library.h)
    #include <include_and_disable_some_warnings>

    laMer007, 01 Июня 2014

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

    +5

    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
    #include <iostream>
    using namespace std;
    struct ko{
    	int r;
    } f;
    const ko& taras=f;
    int main() {
    	cout<<
    	is_same<decltype(taras.r), int>::value
    	<<" "<<
    	is_same<decltype((taras.r)), const int &>::value
    	<<endl;
    	return 0;
    }

    What is output you expect? You should answer without looking at ideone link and without using compiler.
    http://ideone.com/5O9vtZ

    LispGovno, 30 Мая 2014

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

    +6

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    const int cx = 5;
    int main() {
    	auto lam = [cx]() mutable {cx=40;};
    	return 0;
    }

    Will it compile or not? Why?
    http://ideone.com/gtlXKb

    LispGovno, 30 Мая 2014

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

    +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
    #define BOOST_INTRUSIVE_INTERNAL_STATIC_BOOL_IS_TRUE(TRAITS_PREFIX, TYPEDEF_TO_FIND) \
    template <class T>\
    struct TRAITS_PREFIX##_bool\
    {\
       template<bool Add>\
       struct two_or_three {one _[2 + Add];};\
       template <class U> static one test(...);\
       template <class U> static two_or_three<U::TYPEDEF_TO_FIND> test (int);\
       static const std::size_t value = sizeof(test<T>(0));\
    };\
    \
    template <class T>\
    struct TRAITS_PREFIX##_bool_is_true\
    {\
       static const bool value = TRAITS_PREFIX##_bool<T>::value > sizeof(one)*2;\
    };\
    //

    Ну тут как бы все просто и понятно. Но зачем заканчивают макрос кодом

    \
    //
    ?

    laMer007, 29 Мая 2014

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

    +5

    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
    struct A {
      int a;
      virtual ~A() {}
    };
    struct B: public A {
      int b;
      B(int _b):b(_b){}
      virtual ~B() {}
    };
    A func(){return A();}
     
    int main(int argc, char* argv[])
    {
      A* a = new B(2);  
      *a = func();
      a->a = 5;
      B *b = dynamic_cast<B*>(a);
      std::cout << b->b << "\t" << b->a;
      return 0;
    }

    Меня попросили ответить что выведет на экран.

    laMer007, 29 Мая 2014

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

    +11

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    for (_i = 1;_i <= int(strlen(Query10->FieldValue("pattern").c_str()));_i++) {
        // ...
    }
    
    if (strlen(Query10->FieldValue("pattern_before").c_str()) == strlen(Query10->FieldValue("pattern_short").c_str())) {
        // ...
    }

    Nuff said.

    bormand, 29 Мая 2014

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

    +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
    template<typename T, typename T1>
    	class TSwitch
    	{
    		private:
    			std::function<T1(T)> _functionSwitch;
    			std::function<void(T)> _defaultFunction;
    			std::map<T1, std::function<void(T)> > _map;
    		private:
    			IActorPtr _protocol;
    			IActorPtr _port;
    			IActorPtr _listParam;
    			IActorPtr _managerData;
    
    		public:
    		TSwitch(std::function<T1(T)> functionSwitch,std::map<T1, std::function<void(T)> > mapSwitch):_functionSwitch(functionSwitch)
    																									,_defaultFunction([](T value){std::cout<<"no way";})
    																									,_map(mapSwitch){}
    		TSwitch(std::function<T1(T)> functionSwitch, std::function<void(T)> defaultValue,std::map<T1, std::function<void(T)> > mapSwitch):_functionSwitch(functionSwitch)
    																																		,_defaultFunction(defaultValue)																																,_map(mapSwitch){}
    		virtual ~TSwitch(){}
    		public:
    			void switches(T value)
    			{
    				auto it=_map.find(_functionSwitch(value));
    				if (it==_map.end()) {_defaultFunction(value); return;}
    				it->second(value);
    			}
    	};

    Вот такая замена switch. Отстойно не правда-ли?

    IKing, 29 Мая 2014

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

    +5

    1. 1
    2. 2
    3. 3
    4. 4
    //Так я легко "девушку" найду
    If(user.usingOS =="linux" && user.female=true){
    user.Подкатить();
    }

    Решил выпендриться, и сам наговнокодил

    joker, 28 Мая 2014

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

    +16

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    std::string response;
    ...
    char* result = new char[response.size() + 1];
    memcpy(&result[0], &response.c_str()[0], response.size());
    result[response.size()] = 0;
    return result;

    Сам метод возвращает char * (при этом никто не запрещал использовать непосредственно std::string).

    ЗЫ жаль что весь проект запостить нельзя. Он весь достоин.

    h4tr3d, 27 Мая 2014

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

    +17

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    io_service::strand strand_one(service), strand_two(service);
    for (int i = 0; i < 5; ++i)
        service.post(strand_one.wrap(boost::bind(func, i)));
    for (int i = 5; i < 10; ++i)
        service.post(strand_two.wrap(boost::bind(func, i)));

    Пример из книги Boost.Asio C++ Network Programming.

    In the preceding code, we made sure that the first five and the last five were serialized namely, "func called, i = 0" is called before "func called, i = 1", which is called before "func called, i = 2", and so on. The same goes for "func called, i = 5", which is called before "func called, i = 6", and "func called, i = 6" is called before "func called, i = 7", and so on.

    "А вот хуй тебе!", - сказал четырёхъядерный процессор, и выполнил коллбеки внутри strand'ов в случайном порядке.

    bormand, 25 Мая 2014

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