- 1
- 2
//G++ now allows typename in a template template parameter.
template<template<typename> typename X> struct D; // xzibit.jpeg
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+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);
}
+143
#include <iostream>
#include <string>
using namespace std;
int main ()
{
int n,m;
char c[10][10];
cin >> n >> m;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
cin >> c[i][j];
}
}
c[0][0] = 'E';
c[n-1][0] = 'D';
c[0][m-1] = 'F';
c[n-1][m-1] = 'C';
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (c[i][j] == 'A')
{
if (j == 0) {c[i][j] = 'B';} else
{if (i>0 && c[i][j-1] != 'A' && c[i][j-1] != 'D' && c[i][j-1] != 'E' && (c[i-1][j] == 'E' || c[i-1][j] == 'F' || c[i-1][j] == 'B')) c[i][j] = 'B';}
}
else
{
if (c[i][j] == 'B')
{
if (i == 0) {c[i][j] = 'A';} else
{if (j>0 && c[i-1][j] != 'B' && c[i-1][j] != 'F' && c[i-1][j] != 'E' && (c[i][j-1] == 'D' || c[i][j-1] == 'F' || c[i][j-1] == 'A')) c[i][j] = 'A';}
}
else
{ //уголки
if (i==0 && j > 0)
{
if (c[i][j-1] == 'A' || c[i][j-1] == 'E') c[i][j] = 'F'; else c[i][j] = 'E';
}
else
{
if (i==n-1 && j > 0)
{
if (c[i][j-1] == 'A' || c[i][j-1] == 'D') c[i][j] = 'C'; else c[i][j] = 'D';
}
else
{
if (j==0 && i > 0)
{
if (c[i-1][j] == 'B' || c[i-1][j] == 'E') c[i][j] = 'D'; else c[i][j] = 'E';
}
else
{
if (j==m-1 && i > 0)
{
if (c[i-1][j] == 'B' || c[i-1][j] == 'F') c[i][j] = 'C'; else c[i][j] = 'F';
}
else
{
if ((c[i-1][j] == 'B' || c[i-1][j] == 'F') && (c[i][j-1] == 'A' || c[i][j-1] == 'D')) c[i][j] = 'C';
else
{
if (c[i-1][j] == 'B' || c[i-1][j] == 'E') c[i][j] = 'D';
else
{
if (c[i][j-1] == 'A' || c[i][j-1] == 'E') c[i][j] = 'F';
else c[i][j] = 'E';
}
}
}
}
}
}
}
}
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
cout << c[i][j];
}
cout << endl;
}
}
http://vk.com/photo70606856_365037363
Пройдено 77 тестов из 85
+66
AnimationAnimator* AnimationAnimator::getThis()
{
return this;
}
Я не знаю что это было, но теперь оно такое. Вызывается из трех мест. Мне страшно :С
+145
void* PhysicsWorld::CreateBodyImpl(const PhysicsBodyCInfo& bodyInfo)
{
void* pBody = 0;
PhysicsBody* body = 0;
switch(bodyInfo.GetType())
{
case PHYSICS_BODY:
pBody = new PhysicsKovahBody(this);
// This one is special and I dont know why. I used AddToWatch1 to get this std::string well casted.
body = (PhysicsBody*)(&(*(PhysicsKovahRigidBody*)(&*((PhysicsKovahBody*)pBody))));
pBody = body;
break;
case PHYSICS_CHARACTER_BODY:
pBody = new PhysicsKovahCharacterBody(this);
body = (PhysicsBody*)((PhysicsCharacterBody*)pBody);
break;
case PHYSICS_CAR_BODY:
pBody = new PhysicsKovahCarBody(this);
body = (PhysicsBody*)((PhysicsCarBody*)pBody);
break;
case PHYSICS_MOTO_BODY:
pBody = new PhysicsKovahMotoBody(this);
body = (PhysicsBody*)((PhysicsMotoBody*)pBody);
break;
case PHYSICS_BOAT_BODY:
pBody = new PhysicsKovahBoatBody(this);
body = (PhysicsBody*)((PhysicsBoatBody*)pBody);
break;
case PHYSICS_AIRPLANE_BODY:
pBody = new PhysicsKovahAirplaneBody(this);
body = (PhysicsBody*)(&(*(PhysicsVehicleBody*)(&(*(PhysicsAirplaneBody*)(&*((PhysicsKovahAirplaneBody*)pBody))))));
break;
case PHYSICS_HELICOPTER_BODY:
pBody = new PhysicsKovahHelicopterBody(this);
body = (PhysicsBody*)(&(*(PhysicsVehicleBody*)(&(*(PhysicsHelicopterBody*)(&*((PhysicsKovahHelicopterBody*)pBody))))));
break;
case PHYSICS_JETPACK_BODY:
pBody = new PhysicsKovahJetpackBody(this);
body = (PhysicsBody*)(&(*(PhysicsVehicleBody*)(&(*(PhysicsJetpackBody*)(&*((PhysicsKovahJetpackBody*)pBody))))));
break;
case PHYSICS_VTOL_BODY:
pBody = new PhysicsKovahVTOLBody(this);
body = (PhysicsBody*)(&(*(PhysicsVehicleBody*)(&(*(PhysicsVTOLBody*)(&*((PhysicsKovahVTOLBody*)pBody))))));
break;
case PHYSICS_CAMERA_BODY:
break;
};
if(body && body->Create(bodyInfo))
{
return pBody;
}
SafeDelete(body);
return 0;
}
+142
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
int possition[65535] = {0};
int sum[65535] = {0};
int main() {
int i=0;
int j=0;
int N;
cin >> N;
for(i=0; i<N; i++)
cin >> possition[i];
for(i=0; i<N; i++){
for(j=0; j<possition[i]; j++){
if(sum[i]<=possition[i]-j){
sum[i]+=j;}
}
if(possition[i]-sum[i]==1)
cout<<1<<" ";
else cout<<0<<" ";
}
return 0;
}
Забавное это дело - листать новые пасты на pastebin'е.