- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
void TMainForm::MakeScreenPrint()
{
MainForm->Print();
}
void __fastcall TMainForm::N18Click(TObject *Sender)
{
MakeScreenPrint();
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−2
void TMainForm::MakeScreenPrint()
{
MainForm->Print();
}
void __fastcall TMainForm::N18Click(TObject *Sender)
{
MakeScreenPrint();
}
Обертка
−1
template <typename T>
void doSomething(const T& i_field, unsigned int i_offset)
{
...
}
template <>
void doSomething<Boo>(const Boo& i_field, unsigned int i_offset)
{
doSomething(i_field.aaa, i_offset + offsetof(Boo, aaa));
doSomething(i_field.bbb, i_offset + offsetof(Boo, bbb));
doSomething(i_field.ccc, i_offset + offsetof(Boo, ccc));
}
...
template <class T, typename S>
void addSomething(S T::* i_pField)
{
const T* pR = 0;
const unsigned int offset = (unsigned int)&(pR->*i_pField);
doSomething(pR->*i_pField, offset);
}
Увидел вот такой код (рабочий!) в одном довольно крупном проекте.
+3
const char _LETTERS[] =
"000000000000000000000000000000000000000000000000000000000000000001111111111<...>";
const char _DIGITS[] =
"000000000000000000000000000000000000000000000000111111111100000000000000000<...>";
const char _CONTROL_CHARS[] =
"111111111111111111111111111111110000000000000000000000000000000000000000000<...>";
const char _PUNCT_CHARS[] =
"000000000000000000000000000000000111011111101111000000000011000110000000000<...>";
const char _SEP_CHARS[] =
"000000000000000000000000000000001000000000000000000000000000000000000000000<...>";
const char _SYM_CHARS[] =
"000000000000000000000000000000000000100000010000000000000000111000000000000<...>";
#define min(i,l,I) (((i) < (l)) ? (((i) < (I)) ? (i) : (I)) : (((l) < (I)) ? (l) : (I)))
bool CharIsLetter(wchar_t c) {
return _LETTERS[c] != L'0';
}
bool CharIsDigit(wchar_t c) {
return _DIGITS[c] != L'0';
}
bool CharIsControl(wchar_t c) {
return _CONTROL_CHARS[c] != L'0';
}
bool CharIsPunctuation(wchar_t c) {
return _PUNCT_CHARS[c] != L'0';
}
bool CharIsSeparator(wchar_t c) {
return _SEP_CHARS[c] != L'0';
}
bool CharIsSymbol(wchar_t c) {
return _SYM_CHARS[c] != L'0';
}
Лёшенька Кондратьев учится оптимизации
0
// channel.h
#pragma once
namespace AMQP {
class Channel
{
private:
std::shared_ptr<ChannelImpl> _implementation;
public:
Channel(Connection *connection) : _implementation(new ChannelImpl())
{
// attach the connection to the channel
_implementation->attach(connection);
}
Channel(const Channel &channel) = delete;
virtual ~Channel()
{
// close the channel (this will eventually destruct the channel)
_implementation->close();
}
//...
};
// ---------------------------------------------------------
// amqpcpp.h
/**
* AMQP.h
*
* Starting point for all includes of the Copernica AMQP library
*
* @documentation public
*/
#pragma once
// base C++ include files
#include <vector>
#include <string>
#include <memory>
#include <map>
//...
// base C include files
#include <stdint.h>
#include <math.h>
// forward declarations
#include <amqpcpp/classes.h>
// utility classes
#include <amqpcpp/endian.h>
#include <amqpcpp/buffer.h>
#include <amqpcpp/bytebuffer.h>
//...
// amqp types
#include <amqpcpp/field.h>
#include <amqpcpp/numericfield.h>
#include <amqpcpp/decimalfield.h>
#include <amqpcpp/stringfield.h>
//...
// envelope for publishing and consuming
#include <amqpcpp/metadata.h>
#include <amqpcpp/envelope.h>
#include <amqpcpp/message.h>
// mid level includes
#include <amqpcpp/exchangetype.h>
#include <amqpcpp/flags.h>
#include <amqpcpp/callbacks.h>
#include <amqpcpp/deferred.h>
#include <amqpcpp/deferredconsumer.h>
#include <amqpcpp/deferredqueue.h>
#include <amqpcpp/deferreddelete.h>
#include <amqpcpp/deferredcancel.h>
#include <amqpcpp/deferredget.h>
#include <amqpcpp/channelimpl.h>
#include <amqpcpp/channel.h>
//...
https://github.com/CopernicaMarketingSoftware/AMQP-CPP
−1
#define GUIDSTR(s) __uuidof(class DECLSPEC_UUID(s) __guid_##__COUNTER__)
Может можно покороче?
0
if( sync_ip_index < 0 && result() ) {
QString tmp = tr(", нет синхронизации");
addResultMessage( false, p->dev(), tmp);
p->dev()->setState( CDiagramObject::e_Warning );
setResult( false );
}
else if ( sources_from_xml.indexOf( sources_from_ntpq[ sync_ip_index ] ) < 0) {
// ( ( (sync_ip_index >= 0) ? ( sources_from_xml.indexOf( sources_from_ntpq[ sync_ip_index ] ) < 0 ) : false ) ) {
// (p1 ( p2 ) ( p3 ( f1 ) )
// p1..3 - predicates
// Check sync_ip_index >= 0 (p2)
// true, then
// find sync source ip in list filled from xml config , and if there is finded, (p3) are true, else (p3) are false, and then (p1) will be false
// false, then
// (p1) will be false
// This construction for one string check syncronized source ip for host, if host not synchronized
QString tmp = tr(", хост синхронизирован с источником не указанным в схеме");
addResultMessage( false, p->dev(), tmp);
p->dev()->setState( CDiagramObject::e_Warning );
setResult( false );
}
Под конец рабочего дня уже поехала крыша, см. комментарии.
+2
auto id = qobject_cast<QStandardItemModel *>(ui->cbxDevice->model())
->item(ui->cbxDevice->currentIndex(),
RemoteDev::Constants::DEV_ID_COLUMN)
->data(RemoteDev::Constants::DEV_ID_ROLE);
Q(Styled)ItemDelegate::setModelData, достаем данные из модели комбобокса: другая колонка, кастомная роль. Жиза :(
+1
void CDiagram::readDomElement( const QDomElement & de )
{
// ...
QString sstratum = de.attribute( "stratum", "1" );
bool ok = false;
int istratum = sstratum.toInt( &ok );
setStratum( ok ? istratum : CTSWConfig::m_SyncStratum );
// ...
}
Парсинг xml конфигов, код не мой, но надо переделывать.
+3
try{
throw Exception();
}
Мне в сонном бреду пришла мысль, а нахера обязательный catch?
finally везде необязательно.
try{ //исключения не пройдут
}
//вполне по крестоблядски
0
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <stdio.h>
std::vector<int> A, B, C;
void build(const std::vector<int> A, int k, int razmer){
int n = razmer;
B.resize(n);
C.resize(n);
B.front() = A.front();
C.back() = A.back();
k--;
for(int i1(1), i2(n - 2); i1 < n; i1++, i2--){
B[i1] = (i1 % k) ? std::max(A[i1], B[i1 - 1]) : A[i1];
C[i2] = ((i2 + 1) % k) ? std::max(A[i2], C[i2 + 1]) : A[i2];
}
}
int main(){
int m, count;
A.resize(100001);
scanf("%d", &m);
count = 0;
while(true){
scanf("%d", &A[count]);
if(A[count] == -1) break;
count++;
}
build(A, m, count);
int l = 0;
while(count - 1 >= m){
printf("%d\n", std::max(C[l], B[l + m - 1]));
l++;
}
return 0;
}
Код, реализующий поиск максимума по подотрезках последовательности чисел. Если непонятно, то тут строится дерево отрезков, и потом с ним происходит какая-то ебола. Красивое решение получается при использовании стандартного алгоритма поиска максимума в очереди за O(1) при помощи двух стеков.