- 1
- 2
- 3
- 4
- 5
- 6
Point ReadPoint ()
{
Fixed x = ReadFixed();
Fixed y = ReadFixed();
return Point(x,y);
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−11
Point ReadPoint ()
{
Fixed x = ReadFixed();
Fixed y = ReadFixed();
return Point(x,y);
}
Как же меня бесит отсутствие чётко определённого стандартом порядка вычисления аргументов!!!!!!!
+11
AbstractMessageFrame * DataLength = create_frame(
make_condition_reader(this,
fnc_ext::bind(
fnc_ext::compose1(
fnc_ext::compose2(std::logical_or<bool>(),
std::bind2nd(std::equal_to<byte>(), PC5000FlashFeatures::MARKER_SYMBOL),
std::bind2nd(std::equal_to<byte>(), PC5000FlashFeatures::SPACE_SYMBOL)),
fnc_ext::mem_fun<const ByteBuffer, const byte&>(&ByteBuffer::back) ),
&_receivedBuffer),
fnc_ext::bind(
fnc_ext::compose2(std::logical_or<bool>(),
fnc_ext::compose1(std::bind2nd(std::greater<WORD>(),
PC5000FlashFeatures::LENGTH_HEADER +
_maxCommandFieldLength +
PC5000FlashFeatures::LENGTH_MARKER +
PC5000FlashFeatures::LENGTH_OF_LENGTH),
fnc_ext::mem_fun(&ByteBuffer::length)),
fnc_ext::compose1(fnc_ext::compose2(std::logical_and<bool>(),
std::not1(std::ptr_fun<const char, bool>((SymbolCheckFunc)isDigit)),
std::not1(std::ptr_fun<const char, bool>((SymbolCheckFunc)isEnglishLetter))),
fnc_ext::mem_fun<const abstractBuffer<unsigned char>, const byte&>(&ByteBuffer::back)) ),
&_receivedBuffer) ),
fnc_ext::bind(std::mem_fun(&ThisClass::setDataLength), this),
"Data Length");
Композиции, частичные применения, функторы? Больше тотальной функциональщины! Вложенность продолжает расти с развитием проекта.
−4
// please don't change this
#define NUM_INVISIBLE_TYPES 1
Выдержка из исходников civilization 5.
Да, да, прекрасно, усложняйте моддинг
+69
С ДНЕМ МУДАКОВ ЗАДРОТЫ АЗАЗАЗА
13 СИНТЯБРЯ ДЕНЬ ЛАХОВ И ЗАДРОТАВ
p.s. мне всево 7 лет и у миня есть ifon 5
+3
#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <stdio.h>
#include <conio.h>
using namespace std;
class pop
{
public:
char groupp[10];
char alb[10];
char name[10];
pop vvod()
{
pop v;
cin » v.groupp;
cin » v.alb;
cin » v.name;
return v;
}
void vivod(pop v)
{
cout « v.groupp, "\n";
cout « v.alb, "\n";
cout « v.name, "\n";
}
};
void main()
{
char a;
int b=1;
pop v;
while(b!=0)
{
cout « "vvodite";
cin »a;
switch ( a )
{
case '1':
{
v=v.vvod();
b=1;
break;
}
case '2':
{
v.vivod(v);
b=1;
break;
}
default :
{
system("cls");
b=0;
}
}
}
}
+14
constexpr const char str1[] = "Anna";
constexpr const char str2[] = "Denis";
constexpr const char str3[] = "Vladimir";
constexpr const char str4[] = "Alexey";
constexpr const char *arr[] = { str1, str2, str3, str4 };
#define GetMaxLenght(array) \
constexpr unsigned char str_len(const char* const str) \
{\
return *str ? (1 + str_len(str + 1)) : 0;\
}\
\
template <int index> \
struct MaxLenght\
{\
static const int prev_size = MaxLenght<index-1>::max_size;\
static const int cur_size = str_len(array[index]);\
static const int max_size = cur_size > prev_size ? cur_size : prev_size;\
};\
\
template <>\
struct MaxLenght<-1>\
{\
static const int max_size = 0;\
};\
static const int AmountStr = sizeof(array) / sizeof(array[0]);\
static const int array##_max_size = MaxLenght<AmountStr-1>::max_size;
GetMaxLenght(arr);
// в *.cpp
// static_assert((arr_max_size == 8), "Error");
http://habrahabr.ru/post/192736/
+2
double vvod (double a1, double a2, double a3) {
// a1=a a2=b a3=c
cout<<"Введите значение коэфицента a: ";
cin>>a1;
cout<<endl;
cout<<"Введите значение коэфицента b: ";
cin>>a2;
cout<<endl;
cout<<"Введите значение коэфицента c: ";
cin>>a3;
cout<<endl;
return (a1);
return (a2);
return (a3);
}
Оказывается в С++ можно возвращать 3 значения из функции
http://ideone.com/tGWRpl - полная версия.
−1
#include <iostream>
using namespace std;
struct NG
{
template<class T>
struct get
{
typedef typename T::f type;
};
};
template <typename T, typename NameGetter>
struct has_member_impl
{
typedef char matched_return_type;
typedef long unmatched_return_type;
template <typename C>
static matched_return_type f(typename NameGetter::template get<C>*);
template <typename C>
static unmatched_return_type f(...);
public:
static const bool value = (sizeof(f<T>(0)) == sizeof(matched_return_type));
};
template <typename T, typename NameGetter>
struct has_member{
enum { value = has_member_impl<T, NameGetter>::value };
};
class T{};
int main() {
cout<<has_member<T, NG>::value;
return 0;
}
http://ideone.com/4LDGhZ
+13
TAbstractMessageFrame * SwitchIfNeedReceivePackets = create_switch(
fnc_ext::bind(this,
fnc_ext::compose2(std::greater<WORD>(),
fnc_ext::get_mem(&TThisClass::_totalDataLength),
fnc_ext::compose1(std::bind1st(std::minus<WORD>(), static_cast<WORD>(TByteBuffer::MaxCapacity)),
fnc_ext::compose1(fnc_ext::get_mem_func_ref(&TThisClass::TByteBuffer::length),
fnc_ext::get_mem(&TThisClass::_receivedBuffer))))),
// fnc_ext::get_mem_func(&TThisClass::FreeBufferSpace))),
DataByPackets, DataByLength, "Switch If Need Receive Packets" );
+13
void User::AddFriend(User& newFriend)
{
friends_.push_back(&newFriend);
pDB_->AddFriend(GetName(), newFriend.GetName());
}
//...VS...
void User::AddFriend(User& newFriend)
{
friends_.push_back(&newFriend);
try
{
pDB_->AddFriend(GetName(), newFriend.GetName());
}
catch (...)
{
friends_.pop_back();
throw;
}
}
//...VS...
class VectorInserter//Глобальный безопасный вектороВставлятель.
{
public:
VectorInserter(std::vector<User*>& v, User& u)
: container_(v), commit_(false)
{
container_.push_back(&u);
}
void Commit() throw()
{
commit_ = true;
}
~VectorInserter()
{
if (!commit_) container_.pop_back();
}
private:
std::vector<User*>& container_;
bool commit_;
};
void User::AddFriend(User& newFriend)
{
VectorInserter ins(friends_, &newFriend);
pDB_->AddFriend(GetName(), newFriend.GetName());
// Everything went fine, commit the vector insertion
ins.Commit();
}