- 1
bool ok = (state == 0) ? false : true;
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−43
bool ok = (state == 0) ? false : true;
И это пишет человек, пишущий на плюсах уже много лет...
−34
int ConditionsTuple(const bool Condition1, const bool Condition2)
{
return (Condition1<<1) + Condition2;
}
template <bool Condition1, bool Condition2>
struct TConditionsTuple
{
enum {Result = (Condition1<<1) + Condition2};
};
float SignedIf(const bool Condition)
{
return Condition ? -1 : 1;
}
switch (ConditionsTuple(
bExpr1,
bExpr2
))
{
case TConditionsTuple<1, 1>::Result:
return PArc(new TArc(
CouplePointAtPrimitive1,
CouplePointAtPrimitive2,
ArcCoupleCenter,
Abs(arcCoupleRadius)
));
case TConditionsTuple<0, 1>::Result:
throw TPrimitive1HalfLengthExpiredException();
case TConditionsTuple<1, 0>::Result:
throw TPrimitive2HalfLengthExpiredException();
case TConditionsTuple<0, 0>::Result:
throw TAllPrimitivesHalfLengthExpiredException();
}
−35
bool EvtDecay::isCharm(EvtId xid){
EvtId d0 = EvtPDL::getId(std::string("D0"));
EvtId d0bar = EvtPDL::getId(std::string("anti-D0"));
EvtId dp = EvtPDL::getId(std::string("D+"));
EvtId dm = EvtPDL::getId(std::string("D-"));
EvtId d0h = EvtPDL::getId(std::string("D0H"));
EvtId d0l = EvtPDL::getId(std::string("D0L"));
EvtId dstp = EvtPDL::getId(std::string("D*+"));
EvtId dstm = EvtPDL::getId(std::string("D*-"));
EvtId ds0 = EvtPDL::getId(std::string("D*0"));
EvtId ds0bar = EvtPDL::getId(std::string("anti-D*0"));
EvtId dsp = EvtPDL::getId(std::string("D_s+"));
EvtId dsm = EvtPDL::getId(std::string("D_s-"));
EvtId dsstp = EvtPDL::getId(std::string("D_s*+"));
EvtId dsstm = EvtPDL::getId(std::string("D_s*-"));
EvtId ds0stp = EvtPDL::getId(std::string("D_s0*+"));
EvtId ds0stm = EvtPDL::getId(std::string("D_s0*-"));
std::vector<EvtId> Vid; Vid.clear();
Vid.push_back(d0);
Vid.push_back(d0bar);
Vid.push_back(dp);
Vid.push_back(dm);
Vid.push_back(d0h);
Vid.push_back(d0l);
Vid.push_back(dstp);
Vid.push_back(dstm);
Vid.push_back(ds0);
Vid.push_back(ds0bar );
Vid.push_back(dsp );
Vid.push_back(dsm );
Vid.push_back(dsstp );
Vid.push_back(dsstm );
Vid.push_back(ds0stp );
Vid.push_back(ds0stm );
bool flag=true;
for(int i=0;i<Vid.size();i++){ if(xid == Vid[i]) return flag;}
return false;
}
физика высоких энергий, китайский говнокод
−29
template<class TValueChanger>
NContour::NPrimitives::PArc ChangePrimitive(NContour::NPrimitives::PArc Arc, const TValueChanger& ValueChanger)
{
return ValueChanger(Arc);
}
template<class TValueChanger>
NContour::NPrimitives::PLine ChangePrimitive(NContour::NPrimitives::PLine Line, const TValueChanger& ValueChanger)
{
return ValueChanger(Line);
}
template<class TValueChanger1, class TValueChanger2>
NContour::NPrimitives::PArc ChangePrimitive(NContour::NPrimitives::PArc Arc, const TValueChanger1& ValueChanger1, const TValueChanger2& ValueChanger2)
{
return ValueChanger2(ValueChanger1(Arc));
}
template<class TValueChanger1, class TValueChanger2>
NContour::NPrimitives::PLine ChangePrimitive(NContour::NPrimitives::PLine Line, const TValueChanger1& ValueChanger1, const TValueChanger2& ValueChanger2)
{
return ValueChanger2(ValueChanger1(Line));
}
//...
template<class TValueChanger1, class TValueChanger2, class TValueChanger3, class TValueChanger4, class TValueChanger5, class TValueChanger6>
NContour::NPrimitives::PArc ChangePrimitive(NContour::NPrimitives::PArc Arc, const TValueChanger1& ValueChanger1, const TValueChanger2& ValueChanger2, const TValueChanger3& ValueChanger3, const TValueChanger4& ValueChanger4, const TValueChanger5& ValueChanger5, const TValueChanger6& ValueChanger6)
{
return ValueChanger6(ValueChanger5(ValueChanger4(ValueChanger3(ValueChanger2(ValueChanger1(Arc))))));
}
template<class TValueChanger1, class TValueChanger2, class TValueChanger3, class TValueChanger4, class TValueChanger5, class TValueChanger6>
NContour::NPrimitives::PLine ChangePrimitive(NContour::NPrimitives::PLine Line, const TValueChanger1& ValueChanger1, const TValueChanger2& ValueChanger2, const TValueChanger3& ValueChanger3, const TValueChanger4& ValueChanger4, const TValueChanger4& ValueChanger5, const TValueChanger6& ValueChanger6)
{
return ValueChanger6(ValueChanger5(ValueChanger4(ValueChanger3(ValueChanger2(ValueChanger1(Line))))));
}
−28
command = QString("sh -c \"echo \"nameserver %1\" > /etc/resolv.conf\"")
.arg(nameserver.toString());
QProcess process;
process.start(command);
−30
#include <iostream>
#include <conio.h>
using namespace std;
char* find(char* str)
{
int i = 0, mlen=0;
char* minword = new char[100];
char* curword = new char[100];
while(str[i]==' ') i++;
mlen = i;
while((str[mlen]!=' ')&&(str[mlen])) mlen++;
mlen -= i;
strncpy(minword, str+i, mlen);
minword[mlen] = '\0';
i += mlen;
while(str[i])
{
while(str[i]==' ') i++;
mlen = i;
while((str[mlen]!=' ')&&(str[mlen])) mlen++;
mlen -= i;
strncpy(curword, str+i, mlen);
curword[mlen] = '\0';
i += mlen;
if(strcmp(minword, curword) > 0)
{
strcpy(minword, curword);
}
}
return minword;
}
void del(char*& str, char* str2)
{
int i = 0, j =0, st=0;
char* nstr = new char[200];
while(str[i])
{
j = 0;
while(str[i]==str2[j])
{
i++; j++;
}
if(j==strlen(str2))
{
strncpy(nstr, str+st, i-j);
nstr[i-j] = '\0';
st = i;
break;
}
i++;
}
strcat(nstr, str+st);
str = nstr;
}
void sort(char*& str)
{
int len = strlen(str);
char* nstr = new char[200];
char* buf = new char[200];
buf = find(str);
strcpy(nstr, buf);
del(str, buf);
while(strlen(nstr) != len)
{
buf = find(str);
strcat(nstr, " ");
strcat(nstr, buf);
del(str, buf);
}
nstr[len] = '\0';
str = nstr;
}
void main()
{
char* str = new char[200];
str = "my little pony";
sort(str);
cout<<str;
}
Из вузовского компьютера.
−52
/// Get the x-axis
b2Vec2 GetXAxis() const
{
return b2Vec2(c, s);
}
/// Get the u-axis
b2Vec2 GetYAxis() const
{
return b2Vec2(-s, c);
}
Box2D, говнокомментарий
−43
int eger;
−32
#pragma once
#include <vector>
#include <assert.h>
class Obj
{
public:
virtual ~Obj(void) { }
};
class Sig
{
typedef void (Obj::*slot_t)(void*);
mutable std::vector<std::pair<Obj*, Sig::slot_t>> m_connSlots;
public:
void operator()(void* arg) const
{
std::vector< std::pair<Obj *, slot_t> >::const_iterator iter = m_connSlots.cbegin();
while(iter != m_connSlots.cend())
{
Obj * object = iter->first;
slot_t slot = iter->second;
(object->*slot)(arg);
iter++;
}
}
template<class obj_T> void connect(obj_T* object, void (obj_T::*slot)(void*)) const
{
assert(dynamic_cast<Obj*>(object)!=0);
m_connSlots.push_back(std::make_pair(reinterpret_cast<Obj*>(object),
reinterpret_cast<Sig::slot_t>(slot)));
}
};
QBicycle
−32
//
// std::string wrapper
//
namespace priv {
class string {
std::string &m_s;
std::string &(std::string::*m_pAssign1)( const char *, std::string::size_type );
std::string &(std::string::*m_pAssign2)( const char * );
public:
string( std::string &str ): m_s(str),
m_pAssign1(&std::string::assign), m_pAssign2(&std::string::assign) {}
string &assign( const char *s, std::string::size_type n )
{
(m_s.*m_pAssign1)( s, n ); return *this;
}
string &assign( const char *s )
{
(m_s.*m_pAssign2)( s ); return *this;
}
};
}
сегодня ассимилирую старый хлам на работе (проекты VC6) в студию с нормальными свойствами проектов, конфигурациями, неабсолютными путями и т.д.
наткнулся в одной из либ на вот это