- 1
- 2
- 3
CoolIntf::GetInstance().DoSomething();
CoolIntf::GetInstance().DoSomethingElse();
CoolIntf::GetInstance().DoAnything()
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+1
CoolIntf::GetInstance().DoSomething();
CoolIntf::GetInstance().DoSomethingElse();
CoolIntf::GetInstance().DoAnything()
для случая когда GetInstance() не инлайнится, кто-нибудь в крестах какое решение (без ручного введения временной переменной) для такого кода придумал?
единственное что нашел это вот это: https://stackoverflow.com/a/2279253 .
потому что "with" слишком общее слово которое в ж не гуглится.
+2
#include <iostream>
#include <stdexcept>
using namespace std;
class Exception : std::runtime_error
{
public:
Exception( std::string const & what ) : std::runtime_error(what)
{
}
};
int main( )
{
try
{
throw Exception("Exception");
}
catch ( std::exception const & e )
{
std::cerr << e.what() << std::endl;
}
catch(...)
{
std::cerr << "..." << std::endl;
}
return 0;
}
+5
//Сегодня у меня вопрос по говнокоду.
//Как у нас на говнокодике реализовано сколько непросмотренных комментариев в каждом треде?
//Неужели на каждого юзера заводится счётчик и инкрементится при добавлении в каждой теме?
//Неужели на каждого юзера на каждый комментарий заводится флаг, сообщающий какой комментарий прочитан, а какой нет?
−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
+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,
Пятая строка - вообще угар.
+2
const int MOD = 1000000007;
int pow(int a, int b) {
if (!b) return 1;
if (b & 1) return (pow(a, b - 1) * 1LL * a) % MOD;
return pow((a * 1LL * a) % MOD, b / 2);
}
http://ideone.com/JlfNxZ
Там ещё куча всякого говна есть
http://acm.math.spbu.ru/~kunyavskiy/cpp/
+76
.global shit
.type shit, @function
shit:
/* prologue: function */
/* frame size = 0 */
/* stack size = 0 */
.L__stack_usage = 0
mov r30,r24
mov r31,r25
ldd r18,Z+1
ldd r22,Z+2
mov r24,r22
ldi r25,0
ldi r26,0
ldi r27,0
mov r26,r24
mov r27,r25
clr r25
clr r24
or r25,r18
ld r18,Z
or r24,r18
ldd r18,Z+3
mov r22,r24
mov r23,r25
mov r24,r26
mov r25,r27
or r25,r18
ret
.size shit, .-shit
Вот такое ГЛОБАЛЬНОЕ ГОВНО мне делает GCC под AVR
Код разворота байтиков:
unsigned long int shit(unsigned char *a)
{
return
( unsigned long int)a[0] << 0 |
((unsigned long int)a[1] << 8 ) |
((unsigned long int)a[2] << 16) |
((unsigned long int)a[3] << 24);
}
#if defined (L_bswapsi2)
;; swap bytes
;; r25:r22 = bswap32 (r25:r22)
DEFUN __bswapsi2
bswap r22, r25
bswap r23, r24
ret
ENDF __bswapsi2
#endif /* defined (L_bswapsi2) */
+145
int main () {
constexpr int a = f ();
constexpr int b = f ();
static_assert (a != b, "fail");
}
Можно ли это успешно скомпилировать?
http://b.atch.se/posts/non-constant-constant-expressions/
Можно, лал.
+133
#include <stdio.h>
int main () {
char c;
int result=0;
while(scanf("%c",&c) ) {
if( (c<'0') || (c > '1') ) break;
result«=1;
result+=c-'0';
};
printf("%d",result);
return 0;
}
Этот код переводит число из двоичной системы в десятичную. Зачем-то основано на работе с символами.
+155
<?php
function load ($file) {
static $files = null;
$files or $files = [];
if (!isset($files[$file])) {
require($file);
$files[$file] = true;
}
}
$times = 1000000;
$time1 = microtime(true);
for ($i = 0; $i < $times; $i ++) {
require_once('inc.php');
}
$end1 = microtime(true) - $time1;
$time2 = microtime(true);
for ($i = 0; $i < $times; $i ++) {
load('inc.php');
}
$end2 = microtime(true) - $time2;
echo "require_once = $end1 vs \nload = $end2";
Вот это да... require_once работает в ~8 раз медленнее чем функция load. Вывод:
require_once = 16.962311029434 vs
load = 2.6861710548401
Содежания файла inc.php:
<?php echo 'Hello, world!';