- 1
# define BOOST_MPL_AUX_NTTP_DECL(T, x) T x
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+9
# define BOOST_MPL_AUX_NTTP_DECL(T, x) T x
Очень интересный стайлгайд Алексей Гуртового
+9
int numBlock = 0;
for(int i = 0; i < 16; i++)
for(int j = 0; j < 25; j++)
{
if(levelInfo[i][j].active)
{
if(levelInfo[i][j].part && levelInfo[i][j].type) continue;
if(levelInfo[i][j].type)
{
tempLevel[numBlock*8 ] = i*24;
tempLevel[numBlock*8+1] = (j)*24;
tempLevel[numBlock*8+2] = (i+2)*24;
tempLevel[numBlock*8+3] = (j)*24;
tempLevel[numBlock*8+4] = (i+2)*24;
tempLevel[numBlock*8+5] = (j+1)*24;
tempLevel[numBlock*8+6] = i*24;
tempLevel[numBlock*8+7] = (j+1)*24;
}
else
{
tempLevel[numBlock*8 ] = i*24;
tempLevel[numBlock*8+1] = (j)*24;
tempLevel[numBlock*8+2] = (i+1)*24;
tempLevel[numBlock*8+3] = (j)*24;
tempLevel[numBlock*8+4] = (i+1)*24;
tempLevel[numBlock*8+5] = (j+1)*24;
tempLevel[numBlock*8+6] = i*24;
tempLevel[numBlock*8+7] = (j+1)*24;
}
if(levelInfo[i][j].type)
for(int k = 0; k < 8; k++) tempTex[numBlock*8+k] = coord[0][k];
else
for(int k = 0; k < 8; k++) tempTex[numBlock*8+k] = coord[1][k];
}
else
{
tempLevel[numBlock*8 ] = i*24;
tempLevel[numBlock*8+1] = (j)*24;
tempLevel[numBlock*8+2] = (i+1)*24;
tempLevel[numBlock*8+3] = (j)*24;
tempLevel[numBlock*8+4] = (i+1)*24;
tempLevel[numBlock*8+5] = (j+1)*24;
tempLevel[numBlock*8+6] = i*24;
tempLevel[numBlock*8+7] = (j+1)*24;
for(int k = 0; k < 8; k++) tempTex[numBlock*8+k] = coord[2][k];
}
numBlock++;
}
for(int i = 0; i < 2; i++)
for(int j = 0; j < 3; j++)
{
if(!fallBlocks[i][j].active) continue;
if(fallBlocks[i][j].part && fallBlocks[i][j].type) continue;
if(!fallBlocks[i][j].type)
{
tempLevel[numBlock*8 ] = (fallPosX+i)*24;
tempLevel[numBlock*8+1] = (fallPosY-j)*24;
tempLevel[numBlock*8+2] = (fallPosX+i+1)*24;
tempLevel[numBlock*8+3] = (fallPosY-j)*24;
tempLevel[numBlock*8+4] = (fallPosX+i+1)*24;
tempLevel[numBlock*8+5] = (fallPosY-j+1)*24;
tempLevel[numBlock*8+6] = (fallPosX+i)*24;
tempLevel[numBlock*8+7] = (fallPosY-j+1)*24;
for(int k = 0; k < 8; k++) tempTex[numBlock*8+k] = coord[1][k];
}
else
{
tempLevel[numBlock*8 ] = (fallPosX+i)*24;
tempLevel[numBlock*8+1] = (fallPosY-j)*24;
tempLevel[numBlock*8+2] = (fallPosX+i+2)*24;
tempLevel[numBlock*8+3] = (fallPosY-j)*24;
tempLevel[numBlock*8+4] = (fallPosX+i+2)*24;
tempLevel[numBlock*8+5] = (fallPosY-j+1)*24;
tempLevel[numBlock*8+6] = (fallPosX+i)*24;
tempLevel[numBlock*8+7] = (fallPosY-j+1)*24;
for(int k = 0; k < 8; k++) tempTex[numBlock*8+k] = coord[0][k];
}
numBlock++;
}
Нямка. В унитаз уже не помещается, вылью сюда
+28
QVector<double*>*** ElemBoundCond = tbc->getElementsBC();
+16
function<future<int> (int)> f = [](int a){ cout << a << '\n'; return mreturn(a + 6); };
int a = (mreturn(5) >>= f).get();
cout << a;
+13
void Fetch_image::fetch( ...
, bool& image_repo_available)
{
///...
if( smth)
{
/// ...
image_repo_available = false;/// 1
throw Exception( ...);/// 2
}
else
{
/// ...
image_repo_available = true;
}
}
bool Fetch_image::process(... ,bool& image_repo_available)
{
/// ...
bool image_repo_available = false;
try
{
/// ...
fetch(..., image_repo_available);
}
catch(Exception const & ex)/// 3
{
log(...);
return false; /// 4
}
catch (...)
{
return false; /// 5
}
/// ...
}
Параметры по ссылке
///1 устанавливаем значение
///2 бросаем исключение
///3 в catch ожидаем, что значение сохранится
///4 возврат из ф-ии
И дальше по стеку еще 5 или 6 функций, которые принимают ссылку...
Нахер так жить, котаны?
+9
// fib.h
#pragma once
using ull = unsigned long long;
inline constexpr ull fib(size_t n, ull first, ull second) {
return n == 0 ? first : fib(n - 1, second, first + second);
}
inline constexpr ull fib(size_t n) {
return fib(n, 0, 1);
}
// fibs.h
#pragma once
#include "fib.h"
#include <array>
enum class fibs : ull {
#define FIB(i, val) fib##i = val,
#define COUNT(val) COUNT = val
#include "fibs.inl"
#undef COUNT
#undef FIB
};
std::array<ull, static_cast<size_t>(fibs::COUNT)> const & fibs_values() {
static std::array<ull, static_cast<size_t>(fibs::COUNT)> values = {
#define FIB(i, val) val,
#define COUNT(val)
#include "fibs.inl"
#undef COUNT
#undef FIB
};
return values;
}
// main.cpp
#include "fibs.h"
#include <iostream>
int main() {
using namespace std;
for (auto fib : fibs_values()) {
cout << fib << "," << endl;
}
return 0;
}
// fibs.inl = gen.exe > fibs.inl
// gen.cpp
#include "fib.h"
#include <iostream>
int main() {
using namespace std;
size_t i;
for (i = 0; i < 94; i++) {
cout << "FIB(" << i << ", " << fib(i) << ")" << endl;
}
cout << "COUNT(" << i << ")";
return 0;
}
+13
auto write = [&buf](future<int> size) -> future<bool> {
return streamW.write(size.get(), buf).then(
[](future<int> op){
return op.get() > 0; }); };
auto flse = [](future<int> op){
return future::make_ready_future(false);}; auto copy = do_while(
[&buf]() -> future<bool> {
return streamR.read(512, buf) .then(
[](future<int> op){ return (op.get() > 0) ? write : flse;}); });
///////////////////////////////////////////////////////////////////////////
int cnt = 0;
do {
cnt = await streamR.read(512, buf);
if ( cnt == 0 ) break;
cnt = await streamW.write(cnt, buf);
} while (cnt > 0);
Первое и второе угадайте что? Правильно, С++. В компиляторе студии и первое и второе будет. Первое уже даже есть. Ни первое ни второе не приняли в стандарт на сколько мне известно и надеюсь лобисты Майкрософт во главе с Саттером пойдут на ... подальше от крестов.
www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3722.pdf
+8
void print(int i) {printf("int: %d\n", i);}
void print(double f) {printf("double: %f\n", f);}
void print(char const * c) {printf("str: %s\n", c);}
void WTF(...) {}
template<typename... T>
void print(T ... t)
{
WTF((print(t), 0)...);
}
int main()
{
print(1, "hello", 3.0);
return 0;
}
http://ideone.com/wddRC7
+14
Node<maxCnt> n[sizeY][sizeX], on;
//...
auto EachConvex = [](auto f, Body& b)
{
for (auto g : b.g)
{
auto cp = Body::ConvexPtr(&b, g);
auto bounds = cp.bounds();
auto max = Rect(0, 0, sizeX - 1, sizeY - 1);
auto out = max.intersect(bounds);
auto b = max & bounds;
for (auto x = b.left; x < b.right; ++i)
for (auto y = b.top; x < b.bottom; ++i)
f(n[y][x], cp);
if (out)
f(on, cp);
}
return true;
}
+13
typedef std::queue<Msg> Queue;
struct SharedQueue
{
private:
Queue m_queue;
boost::mutex m_mux;
boost::condition_variable m_condvar;
private:
struct is_empty
{
Queue& queue;
is_empty( Queue& q):
queue(q)
{
}
bool operator()() const
{
return !queue.empty();
}
};
public:
void push(const Msg& msg)
{
boost::mutex::scoped_lock lock(m_mux);
m_queue.push( msg);
m_condvar.notify_one();
}
bool try_pop( Msg& msg, Kind kind)
{
boost::system_time const timeout=boost::get_system_time()+ boost::posix_time::milliseconds( 30000);
boost::mutex::scoped_lock lock( m_mux);
if ( m_condvar.timed_wait( lock, timeout, is_empty( m_queue)))
{
if( !m_queue.empty() && m_queue.front().kind == kind)
{
msg = m_queue.front();
m_queue.pop();
return true;
}
}
return false;
}
};
Это ж пипец, дорогие товарищи...