- 1
auto filename = std::string{};
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+48
auto filename = std::string{};
+142
typedef enum {
INIT1=0, INIT2, INIT3, INIT4, INIT5, INIT6, INITN,
BIND1, BIND2, BIND3, BIND4, BIND5, BIND6, BINDN,
YIELD1, YIELD2, YIELD3, YIELD4, YIELD5, YIELD6, YIELDN,
COMPARE, CHECK, FILTER, CFILTER, PFILTER, CHOOSE, NOOP, CONTINUE,
GET_ENODE,
GET_CGR1, GET_CGR2, GET_CGR3, GET_CGR4, GET_CGR5, GET_CGR6, GET_CGRN,
IS_CGR
} opcode;
...
...
...
switch (m_pc->m_opcode) {
case INIT1:
m_app = m_registers[0];
if (m_app->get_num_args() != 1)
goto backtrack;
m_registers[1] = m_app->get_arg(0);
m_pc = m_pc->m_next;
goto main_loop;
case INIT2:
m_app = m_registers[0];
if (m_app->get_num_args() != 2)
goto backtrack;
m_registers[1] = m_app->get_arg(0);
m_registers[2] = m_app->get_arg(1);
m_pc = m_pc->m_next;
goto main_loop;
case INIT3:
m_app = m_registers[0];
if (m_app->get_num_args() != 3)
goto backtrack;
m_registers[1] = m_app->get_arg(0);
m_registers[2] = m_app->get_arg(1);
m_registers[3] = m_app->get_arg(2);
m_pc = m_pc->m_next;
goto main_loop;
case INIT4:
m_app = m_registers[0];
if (m_app->get_num_args() != 4)
goto backtrack;
m_registers[1] = m_app->get_arg(0);
m_registers[2] = m_app->get_arg(1);
m_registers[3] = m_app->get_arg(2);
m_registers[4] = m_app->get_arg(3);
m_pc = m_pc->m_next;
goto main_loop;
case INIT5:
m_app = m_registers[0];
if (m_app->get_num_args() != 5)
goto backtrack;
m_registers[1] = m_app->get_arg(0);
m_registers[2] = m_app->get_arg(1);
m_registers[3] = m_app->get_arg(2);
m_registers[4] = m_app->get_arg(3);
m_registers[5] = m_app->get_arg(4);
m_pc = m_pc->m_next;
goto main_loop;
case INIT6:
m_app = m_registers[0];
if (m_app->get_num_args() != 6)
goto backtrack;
m_registers[1] = m_app->get_arg(0);
m_registers[2] = m_app->get_arg(1);
m_registers[3] = m_app->get_arg(2);
m_registers[4] = m_app->get_arg(3);
m_registers[5] = m_app->get_arg(4);
m_registers[6] = m_app->get_arg(5);
m_pc = m_pc->m_next;
goto main_loop;
case INITN:
m_app = m_registers[0];
m_num_args = m_app->get_num_args();
if (m_num_args != static_cast<const initn *>(m_pc)->m_num_args)
goto backtrack;
for (unsigned i = 0; i < m_num_args; i++)
m_registers[i+1] = m_app->get_arg(i);
m_pc = m_pc->m_next;
goto main_loop;
Из изходников STM-солвера Z3
https://github.com/Z3Prover/z3/blob/master/src/smt/mam.cpp#L2298
Почему нельзя было оставить только вариант INITN? Цикл отбирает так много ресурсов?
+139
//Башня хаханойская
#include <iostream>
#include<ctime>
#include<math.h>
using namespace std;
int count=0;
void hanoi_towers(int quantity, int from, int to, int buf_peg)
{
int mass[10];
if (quantity != 0)
{
hanoi_towers(quantity-1, from, buf_peg, to);
for (int i = 0; i < quantity; i++) {
mass[i]=1+rand()%quantity;
cout <<" ["<<i<<"]="<<mass[i]<<endl;}
cout <<"S kol'ca # "<< from << " na kol'co # " << to << endl;
hanoi_towers(quantity-1, buf_peg, to, from);
count++;
}
}
int main()
{
int mas[10];
int start_peg = 1, destination_peg=3, buffer_peg=2, plate_quantity,p;
cout << "Koli4estvo discov:" << endl;
cin >> plate_quantity;
for (int i = 0; i < plate_quantity; i++) {
mas[i]=i;
cout <<"1 massiv=["<<i<<"]="<<mas[i]<<endl;}
hanoi_towers(plate_quantity, start_peg, destination_peg, buffer_peg);
cout<<"Kol. iteracui = "<<count<<endl;
p=pow(2.0,plate_quantity)-1 ;
cout<<"Po formule ="<<p<<endl;
for (int i = 0; i < plate_quantity; i++) {
cout <<"3 massiv=["<<i<<"]="<<mas[i]<<endl;
}
getchar();
getchar();
}
//Башня хаханойская
+143
void MyWindow::OkButtonClicked()
{
if((!cb1->isChecked()) && (!cb2->isChecked()))
emit Simple(line->text());
if((cb1->isChecked()) && (!cb2->isChecked()))
emit Register(line->text());
if((!cb1->isChecked()) && (cb2->isChecked()))
emit Invers(line->text());
if((cb1->isChecked()) && (cb2->isChecked()))
emit RegVers(line->text());
}
+148
//G++ now allows typename in a template template parameter.
template<template<typename> typename X> struct D; // xzibit.jpeg
Пятый gcc вышел. Больше крестоблядства за те же деньги.
https://gcc.gnu.org/gcc-5/changes.html
+146
#ifndef FILTER_H
#define FILTER_H
#include <cassert>
#include <vector>
#include <algorithm>
template<typename T>
class filter_container;
namespace detail {
template<typename Iter, typename Pred>
class filter {
public:
filter(Iter begin, Iter end, Pred pred) :_begin(begin), _end(end), _pred(pred) { }
filter(const filter & f) : _begin(f._begin), _end(f._end), _pred(f._pred) { }
filter & operator = (const filter & f) {
if(this != &f) {
_begin = f._begin;
_end = f._end;
_pred = f._pred;
}
return *this;
}
~filter() { }
class const_iterator {
public:
typedef typename Iter::reference reference;
typedef typename Iter::pointer pointer;
const_iterator(Iter iter, const filter & cont) :_iter(iter), _cont(&cont) { advance_until_pred(); }
const_iterator(const const_iterator & i) :_iter(i._iter), _cont(i._cont) { }
const_iterator & operator = (const const_iterator & i) {
if(this != &i) {
_iter = i._iter;
_cont = i._cont
}
return *this;
}
~const_iterator() { }
const_iterator & operator++() { advance_until_pred(); return *this; }
const_iterator operator++(int) {
const_iterator ret = *this;
advance_until_pred();
return ret;
}
const reference operator*() const { return *_iter; }
const pointer operator->() const { return &*_iter; }
bool operator == (const const_iterator & i) const {
assert(_cont == i._cont);
return _iter == i._iter;
}
bool operator != (const const_iterator & i) const { return !(*this == i); }
protected:
Iter _iter;
const filter * _cont;
private:
void advance_until_pred() {
if(_iter != _cont->_end) {
std::advance(_iter, 1);
}
_iter = std::find_if(_iter, _cont->_end, _cont->_pred);
}
private:
const_iterator();
};
class iterator : public const_iterator {
public:
iterator(Iter iter, const filter & cont) :const_iterator(iter, cont) { }
iterator(const iterator & i) :const_iterator(i) { }
iterator & operator = (const iterator & i) { const_iterator::operator=(i); return *this; }
~iterator() { }
reference operator*() { return *_iter; }
pointer operator->() { return &*_iter; }
private:
iterator();
};
iterator begin() { return iterator(_begin, *this); }
iterator end() { return iterator(_end, *this); }
const_iterator cbegin() const { return const_iterator(_begin, *this); }
const_iterator cend() const { return const_iterator(_end, *this); }
private:
Iter _begin, _end;
Pred _pred;
private:
filter();
};
}
template<typename Iter, typename Pred>
detail::filter<Iter, Pred> filter(Iter begin, Iter end, Pred pred) {
return detail::filter<Iter, Pred>(begin, end, pred);
}
#endif // FILTER_H
Тривиальная крестовщина, ничего выдающегося. Внезапно подумалось, что подобный контейнер был бы довольно удобен.
Мне просто любопытно, насколько быстро этот пост будет слит автоминусаторами :)
+141
class ammo
{
public:
bool existance;
COORD alloc;
void print()
{
pole[alloc.Y+1][alloc.X]=' ';
pole[alloc.Y][alloc.X]='*';
}
};
ammo bullet[10];
void initpole();
void replaceunit();
void printpole();
void redirect();
void fire();
void ammomove();
int main(int argc, char* argv[]) //òåëî
{
initpole();
do{
if(kbhit())
redirect();
printpole();
ammomove();
Sleep(0);
}
while(chk!=27);
return 0;
}
void redirect() //обработка нажатой клавиши
{
chk=getch();
if(chk==32)
{
bullet[bulletcounter].existance=true;
if(bulletcounter<10)
bulletcounter++;
else
bulletcounter=0;
fire();
}
else if(chk==75 || chk==77)
replaceunit();
else if(chk==112)
{
system("pause");
system("cls");
}
}
void fire() //инициализация пули
{
bullet[bulletcounter].alloc.X=x;
bullet[bulletcounter].alloc.Y=y-3;
if(bullet[bulletcounter].existance==true)
bullet[bulletcounter].print();
}
void ammomove() //сдвиг пули
{
if(bullet[bulletcounter].existance==true)
if(bullet[bulletcounter].alloc.Y>1)
{
bullet[bulletcounter].alloc.Y--;
bullet[bulletcounter].print();
}
else
{
bullet[bulletcounter].existance=false;
pole[bullet[bulletcounter].alloc.Y][bullet[bulletcounter].alloc.X]=' ';
}
}
по нажатию пробела должна вылетать пулька, но чегот не хочет она вылетать, есть идеи? :3
+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/
Можно, лал.
+147
https://ideone.com/xM1uqd
+144
static const char *
inet_ntop4(src, dst, size)
const u_char *src;
char *dst;
size_t size;
{
static const char fmt[] = "%u.%u.%u.%u";
char tmp[sizeof "255.255.255.255"];
if (SPRINTF((tmp, fmt, src[0], src[1], src[2], src[3])) > size) {
errno = ENOSPC;
return (NULL);
}
strcpy(dst, tmp);
return (dst);
}