- 1
- 2
- 3
class ... {
void enable(bool enabled = false);
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+3
class ... {
void enable(bool enabled = false);
}
−1
std::function<CPlayer*> pickedUp = nullptr;
+1
void Table::draw() {
SetConsoleCursorPosition(consOutput, { 0,0 });
for (int i = 0; i < lY*(lengthOfCageY + 1) + 1; i++) {
for (int j = 0; j < lX*(lengthOfCageX + 1) + 1; j++) {
if (i == 0 && j == 0)
cout << (char)201;
else if (i == 0 && j == lX*(lengthOfCageX + 1))
cout << (char)187;
else if (i == lY*(lengthOfCageY + 1) && j == 0)
cout << (char)200;
else
if (i == lY*(lengthOfCageY + 1) && j == lX*(lengthOfCageX + 1))
cout << (char)188;
else
if (i == 0)
if (j % (lengthOfCageX + 1) == 0)
cout << (char)203;
else
cout << (char)205;
else
if (i == lY*(lengthOfCageY + 1))
if (j % (lengthOfCageX + 1) == 0)
cout << (char)202;
else
cout << (char)205;
else
if (j == 0)
if (i % (lengthOfCageY + 1) == 0)
cout << (char)204;
else
cout << (char)186;
else
if (j == lX*(lengthOfCageX + 1))
if (i % (lengthOfCageY + 1) == 0)
cout << (char)185;
else
cout << (char)186;
else
if (i % (lengthOfCageY + 1) == 0 && j % (lengthOfCageX + 1) == 0)
cout << (char)206;
else
if (i % (lengthOfCageY + 1) == 0)
cout << (char)205;
else
if (j % (lengthOfCageX + 1) == 0)
cout << (char)186;
else
cout << " ";
}
cout << endl;
}
}
И прекрасно и ужасно. Плохой но хороший код для вывода красивой таблицы в консоль
0
// Tools.cpp
class SleepQClass : public QThread
{
public:
static void Sleep( int ms )
{
msleep(ms); // static msleep is protected
}
};
void SleepQ( int ms )
{
SleepQClass::Sleep(ms);
}
Паблик Морозов. Делаем глобальную функцию Sleep, чтобы можно было вызывать из любого места и потока. А что, реализация все равно тот же Sleep(DWORD dwMilliseconds) вызывает.
0
void Foo::singleShot()
{
QTime delay = QTime::currentTime().addMSecs(50);
while(QTime::currentTime() < delay ) {
QCoreApplication::processEvents(QEventLoop::AllEvents, 5;
}
// do something
}
Вот такой бриллиант инженерной мысли, написанный с использованием фреймворка Qt.
Товарисч ещё спрашивал, чем его реализация хуже чем QTimer::singleShot() :D
+3
using namespace std;
#include <typeinfo>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <math.h>
#include <stdarg.h>
template <unsigned FRA,unsigned EXP>
struct F {
union{
float f;
unsigned ui;
unsigned ef : FRA+EXP;
struct
{
unsigned f : FRA;
unsigned e : EXP;
unsigned s : 1;
} s;
};
F (double x){f=x;}
F operator =(const double x) {
f=x; return *this;
}
#define NOOP ;
#define UN(OP,BODY, RET) float operator OP( ) { BODY; return RET;}
#define BIN(OP,BODY, RET) F operator OP(F other ) { BODY; return RET;}
#define BINF(OP,BODY,RET) F operator OP(const float other) { BODY; } BIN(OP,BODY,RET)
#define CMP(OP) bool operator OP(const F& other)
UN ( - , s.s^=1 , (f) )
BIN( += , f+=other.f , ( *this ) )
BIN( + , NOOP , { f+other.f} )
BIN( - ,++other.s.s , {*this+other} )
BIN( * , NOOP , fmul(f,{other}) )
BIN( / , div(other), ( *this ) )
BINF(*=, ui=fmul(*this ,{other}).ui, ( *this ) )
BINF(/=, ui=fmul(*this,rcp(other)).ui, ( *this ) )
CMP(==){
return other.ui==ui;
}
F out(string s) const{
printf("> %s%f\n",s.c_str(),f);
}
F plus(F other)
{
f+=other.f;
return *this;
}
F div(F other)
{
ui=fmul(rcp(other),{f}).ui;
return *this;
}
F sqrt()
{
s.e-=127;
ui>>=1;
s.f-=(s.f>>4);
s.e+=127;
return *this;
}
F pow(int n)
{
s.e-=127;
ui*=n;
ef+=(ef>>4);
ef-=(ef>>9);
s.e+=127;
return *this;
}
private:
static F rcp(F f) {
f.s.e=(~f.s.e-2);
f.s.f=(~f.s.f-2);
return f;
}
static F fmul(F r,F b)
{
r.s.s ^= b.s.s;
r.ef += ((r.s.f&b.s.f)>>4);
r.ef += b.ef ;
r.s.e+= 129;
return r;
}
};
using F32 = F<23,8>;
static F32 of32(float x)
Царь был прав. Во всём.
Патамучто это плавающий питух, который априори говно. И чем вы быстрее это поймёте, чем будет лучше.
В соответствии со своим пониманием сделал мммаксимально простую реализацию плавающих питухов произвольного размера.
Строго на интах.
Пример здесь:
uhttps://ideone.com/dDrj7s
0
https://github.com/dotnet/coreclr/blob/a589e3926a1780256fdb52376f8681fe047daf54/src/vm/i386/cgenx86.cpp#L1551-L1553
PAL_TRY(Param *, pParam, ¶m)
{
unsigned char buffer[16];
DWORD* dwBuffer = NULL;
DWORD maxCpuId = getcpuid(0, buffer);
if (maxCpuId < 1)
goto lDone;
dwBuffer = (DWORD*)buffer;
if (dwBuffer[1] == 'uneG') {
if (dwBuffer[3] == 'Ieni') {
if (dwBuffer[2] == 'letn') { // get SMT/multicore enumeration for Intel EM64T
С каких пор в одинарные кавычки можно писать больше одного символа? Это какое-то MSVC или что?
−1
// https://github.com/dotnet/coreclr/blob/a589e3926a1780256fdb52376f8681fe047daf54/src/vm/binder.cpp#L503-L511
const MscorlibBinder::OffsetAndSizeCheck MscorlibBinder::OffsetsAndSizes[] =
{
#define DEFINE_CLASS_U(nameSpace, stringName, unmanagedType) \
{ PTR_CSTR((TADDR) g_ ## nameSpace ## NS ), PTR_CUTF8((TADDR) # stringName), sizeof(unmanagedType), 0, 0, 0 },
#define DEFINE_FIELD_U(stringName, unmanagedContainingType, unmanagedOffset) \
{ 0, 0, 0, PTR_CUTF8((TADDR) # stringName), offsetof(unmanagedContainingType, unmanagedOffset), sizeof(((unmanagedContainingType*)1)->unmanagedOffset) },
#include "mscorlib.h"
};
Дух старой школы всё еще живет в майкрософт
−1
j123123, ты вообще пишешь полезный код или занимаешься
только тем, что постишь на говнокод советы космического масштаба
и комической же глупости о том, как всё оптимизировать?
+2
struct Bar {};
class Foo {
public:
Bar& bar() const { return *bp; }
private:
Bar b;
Bar * const bp = &b;
};
https://wandbox.org/permlink/7JPzrvslrUwbvREb
Как называется данный говнопаттерн?