- 1
С ДНЕМ МУДАКОВ ЗАДРОТЫ АЗАЗАЗА
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+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();
}
+8
template<int ID> struct typeof_access
{
struct id2type; //not defined
};
template<class T, int ID> struct typeof_register : typeof_access
{
// define base's nested class here
struct typeof_access::id2type
{
typedef T type;
};
};
//Type registration function
typeof_register<T, compile-time-constant> register_type(const T&);
//Actually register type by instantiating typeof_register for the correct type
sizeof(register_type(some-type));
//Use the base class to access the type.
typedef typeof_access::id2type::type type;
Igor Chesnokov discovered a method that allows to implement typeof on the VC series of compilers. It uses a bug in the Microsoft compiler that allows a nested class of base to be defined in a class derived from base.
http://www.boost.org/doc/libs/1_54_0/doc/html/typeof/other.html
+14
struct Ziga : std::exception {};
throw Ziga();
Теперь вы знаете как кинуть зигу в C++ !!
−16
#include <iostream>
#include <string>
using namespace std;
/*
*/
int change_word(const int begin_pos, string &words, int k, char c)
{
int pos = begin_pos;
int char_count = 0;
bool replaced = false;
while(pos < words.length() && isalpha(words[pos]))
{
char_count++;
if(char_count == k && !replaced)
{
words[pos] = c;
replaced = true;
}
pos++;
}
return pos;
}
void change_words(string &words, int k, char c)
{
int i = 0;
while(i < words.length())
{
if(isalpha(words[i]))
{
i = change_word(i, words, k, c);
}
else
{
i++;
}
}
}
int main()
{
char c = '>';
int k = 0;
string words = "Length of the substring to be copied";
cout << "enter number:";
cin >> k;
change_words(words, k, c);
cout << "changed text: " << words << endl;
return 0;
}
лаба на с++, заменить в тексте к-тую букву на символ с.