- 1
- 2
#define FOR_INCLUSION (iostream) (studio.h) (stdlib.h) (boost/phoenix.hpp) (my_drugs_library.h)
#include <include_and_disable_some_warnings>
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+8
#define FOR_INCLUSION (iostream) (studio.h) (stdlib.h) (boost/phoenix.hpp) (my_drugs_library.h)
#include <include_and_disable_some_warnings>
+5
#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
+6
const int cx = 5;
int main() {
auto lam = [cx]() mutable {cx=40;};
return 0;
}
Will it compile or not? Why?
http://ideone.com/gtlXKb
+3
#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;\
};\
//
Ну тут как бы все просто и понятно. Но зачем заканчивают макрос кодом
\
//
?
+5
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;
}
Меня попросили ответить что выведет на экран.
+11
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.
+12
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. Отстойно не правда-ли?
+5
//Так я легко "девушку" найду
If(user.usingOS =="linux" && user.female=true){
user.Подкатить();
}
Решил выпендриться, и сам наговнокодил
+16
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).
ЗЫ жаль что весь проект запостить нельзя. Он весь достоин.
+17
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'ов в случайном порядке.