- 1
- 2
- 3
- 4
- 5
- 6
- 7
template<typename T>
T gcd(T a, T b) {
#pragma python(gcd)
while b != 0:
a, b = b, a % b
return a
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−1
template<typename T>
T gcd(T a, T b) {
#pragma python(gcd)
while b != 0:
a, b = b, a % b
return a
}
всех с праздником, посоны
http://codeforces.com/blog/entry/44124
+6
#ifdef _WIN32
...
#elif defined __linux__
std::string path;
char buff[PATH_MAX];
ssize_t len = ::readlink("/proc/self/exe", buff, sizeof(buff)-1);
if (len != -1)
{
buff[len] = '\0';
path = buff;
}
else
{
return -1;
}
int pos = path.rfind("/");
if (pos == std::string::npos)
return - 1;
path = path.substr(0, pos + 1);
path += "updater";
std::string sys_path = path;
boost::replace_all(sys_path, " ", "\\ ");
std::string rm = "rm -f ";
rm += sys_path;
system(rm.c_str());
_data.save_2_file(core::tools::from_utf8(path));
std::string chmod = "chmod 755 ";
chmod += sys_path;
system(chmod.c_str());
system(sys_path.c_str());
#endif //_WIN32
Как правильно обновлять #mailru/icqdesktop на Linux, если вы понимаете о чём я.
+8
template <size_t capacity, bool is_signed>
class fixed_int
{
// Описание ошибки компиляции в случае использования не поддерживаемой размерности
template <int x> struct unsupported_capacity { int i[1/(x-x)]; };
template <> struct unsupported_capacity<1> {};
template <> struct unsupported_capacity<2> {};
template <> struct unsupported_capacity<4> {};
template <> struct unsupported_capacity<8> {};
// Свойства базовых типов, необходимые для перебора
template<typename type> struct type_traits;
template<> struct type_traits <unsigned char> { typedef unsigned char current_type; typedef unsigned short next_type; };
template<> struct type_traits <unsigned short> { typedef unsigned short current_type; typedef unsigned int next_type; };
template<> struct type_traits <unsigned int> { typedef unsigned int current_type; typedef unsigned long next_type; };
template<> struct type_traits <unsigned long> { typedef unsigned long current_type; typedef unsigned long long next_type; };
template<> struct type_traits <unsigned long long int> { typedef unsigned long long int current_type; typedef unsupported_capacity<capacity> next_type; };
template<> struct type_traits <signed char> { typedef signed char current_type; typedef short next_type; };
template<> struct type_traits <short> { typedef short current_type; typedef int next_type; };
template<> struct type_traits <int> { typedef int current_type; typedef long next_type; };
template<> struct type_traits <long> { typedef long current_type; typedef long long next_type; };
template<> struct type_traits <long long int> { typedef long long int current_type; typedef unsupported_capacity<capacity> next_type;};
// Алгоритм выбора типа
template<typename type, bool>
struct type_choice
{
typedef typename type_traits<type>::current_type std_type;
};
template<typename type>
struct type_choice<type, false>
{
typedef typename type_traits<type>::next_type next_type;
typedef typename type_choice<next_type, sizeof(next_type) == capacity>::std_type std_type;
};
// Базовый тип для начала подбора
template <bool is_signed> struct base_type_selector { typedef signed char base_type; };
template <> struct base_type_selector<false> { typedef unsigned char base_type; };
public:
typedef typename type_choice< typename base_type_selector<is_signed>::base_type, sizeof(base_type_selector<is_signed>::base_type) == capacity >::std_type type;
};
"Зачем мне нужен stdint.h?
У меня нет времени, чтобы ебаться с ним!
Лучше я высру ещё десяток-другой шаблонов!"
https://habrahabr.ru/post/280542/
PS,
Пятая строка - вообще угар.
+1
template < typename CType >
void list < CType >::sorted_push(CType val, long int key)
{
if (head) {
// Создаём контейнер и помещаем в него полученное значение
container < CType > *new_cont;
container < CType > *tmp = head;
new_cont = new container < CType >;
new_cont->set_key(key);
new_cont->set_cargo(val);
while ((tmp != tail) && (key > (tmp->get_key())))
tmp = tmp->get_next();
if ((tmp == tail) && (key > (tmp->get_key()))) { // Если выполнились одновременно два условия в цикле
new_cont->set_next(tmp->get_next()); // Вставляем в самый конец
new_cont->set_past(tmp);
tmp->set_next(new_cont);
tail = new_cont;
} else {
new_cont->set_next(tmp);
new_cont->set_past(tmp->get_past());
if ((tmp->get_past()) != NULL)
tmp->get_past()->set_next(new_cont);
if (tmp == head)
head = new_cont;
tmp->set_past(new_cont);
}
if (empty) {
empty = false;
tail = head;
}
} else {
container < CType > *new_cont;
new_cont = new container < CType >;
new_cont->set_key(key);
new_cont->set_cargo(val);
new_cont->set_next(head);
tail = head = new_cont;
empty = false;
}
}
template < typename CType > CType queue < CType >::pop()
{
container < CType > *tmp = list<CType>::head;
if (tmp == NULL) {
std::cerr <<
"Стек пуст! Стек возвращает мусор! ";
list<CType>::empty = true;
} else {
CType tmpval = list<CType>::head->get_cargo();
// Переходим к следующему элементу
list<CType>::head = list<CType>::head->get_next();
if (list<CType>::head == NULL)
list<CType>::empty = true;
delete tmp;
return tmpval;
}
}
template < typename CType > CType stack < CType >::pop()
{
container < CType > *tmp = list<CType>::tail;
if (tmp == NULL) {
std::cerr <<
"Очередь пуста! Возвращается мусор! ";
list<CType>::empty = true;
} else {
CType tmpval = list<CType>::tail->get_cargo();
// Переходим к предыдущему элементу
if (list<CType>::tail != list<CType>::head)
list<CType>::tail = list<CType>::tail->get_past();
else
list<CType>::empty = true;
delete tmp;
return tmpval;
}
}
пострелял себе в ногу
+10
#define class KOKOKO
#include <sys/shutdown.h>
#undef class
/* внутри sys/shutdown.h:
typedef struct
{
uint64_t start_time;
pid_t pid;
int8_t class;
uint8_t padding[3];
char *name;
} ProcessInfo_t;
*/
перезагружаем qnx neutrino из крестового кода
+3
#include <vector>
template <typename T>
void FreeAll( T & t ) {
T tmp;
t.swap( tmp );
}
+2
/**
* @brief Макрос вызова функции изменения имени файла лога ПИМ
*
* @param FILE_NAME Имя файла лога
*
* @return Ничего
*/
#define LOG_PIM_SET_FILE_NAME(FILE_NAME) Soc::setLogFileName(FILE_NAME)
Самый нужный макрос в мире
0
#include <iostream>
using namespace std;
int main(){
int n = 60;
int a = 1 << n;
cout << a << endl;
n = 33;
a = 1 << n;
cout << a << endl;
unsigned m = 33;
unsigned b = 1u << m;
cout << b << endl;
// a = 1 << 32;
// cout << a << endl;
return 0;
}
Моар:
http://acm.math.spbu.ru/~kunyavskiy/cpp/sol02.cpp
+1
void g()
{
int sum;
auto rec = [&sum](int i) -> int
{
static int (*inner)(int&, int) = [](int& _sum, int i)->int
{
_sum += i;
return i>0 ? inner(_sum, i-1)*i : 1;
};
return inner(sum, i);
};
}
0
QMutableListIterator<AISObjectQML *> it(m_visibleList);
if (it.hasNext()) {
AISObjectQML *v = it.next();
if (v) { // здесь должен быть while, но, признаться, на это уже посрать
delete v;
}
}
m_visibleList.clear();
Есть люди, которые придумали концепцию итераторов для реализации generic алгоритмов. А есть люди, которые любят итераторы, но не любят generic алгоритмы. Ведь с ними код не внушает ужаса и рвотных позывов