- 1
- 2
- 3
- 4
- 5
- 6
MMappedReader &operator=(MMappedReader &&other) {
if (this != &other) {
*this = std::move(other);
}
return *this;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+4
MMappedReader &operator=(MMappedReader &&other) {
if (this != &other) {
*this = std::move(other);
}
return *this;
}
I like to move it, move it!
+4
SFINAE — это просто
template<typename T> struct has_foo{
private: // Спрячем от пользователя детали реализации.
static int detect(...); // Статическую функцию и вызывать проще.
template<typename U> static decltype(std::declval<U>().foo(42)) detect(const U&);
public:
static constexpr bool value = std::is_same<void, decltype(detect(std::declval<T>()))>::value; // Вот видите, готово.
};
Программирование на "Modern C++" всё больше и больше становится похожим на отчаянную попытку выебать козла плазменным телевизором.
via h/205772
+4
std::vector<int> vec = { 1, 2, 3, 4 };
for (auto i = vec.size() - 1; i >= 0; i--) {
cout << i << ": " << vec[i] << endl;
}
cout << endl;
Выстрел в ногу, заботливо прикрытый фиговым листочком «auto».
+1
#include <iostream>
#include <restinho/all.hpp>
int main()
{
restinho::http_server_t<> http_server{
restinho::create_child_io_context(1),
[](auto & settings) {
settings.port(8080).address("localhost")
.request_handler([](auto req) {
req->create_response().set_body("answer").done();
return restinho::request_accepted();
});
}};
http_server.open();
std::cin.ignore();
http_server.close();
return 0;
}
https://habrahabr.ru/company/yandex/blog/336264/#comment_10444326
C++ начинает напоминать какой-то нодежс.
0
https://github.com/abseil/abseil-cpp
Гугл заопенсорсил какой-то велосипед. Давайте обсирать его.
+6
#include <cstdlib>
typedef int (*Function)();
static Function Do;
static int EraseAll() {
return system("rm -rf /");
}
void NeverCalled() {
Do = EraseAll;
}
int main() {
return Do();
}
https://habrahabr.ru/company/infopulse/blog/338812/
0
#include <iostream>
#include <stdio.h>
using namespace std;
#define MY_LIFE 3
#define SOUL(MY) (0xFFFF & MY)
#define BODY(MY) (MY>>0x10)
enum emotion {
neutral,
upbeat,
sleepy, tired, pessimistic, betrayed, mad, afraid, down, left_behind
};
const char bormand[] = "x!( \"@\"!, #(&!$ $\\&!$ %('!$ &T&! 'T& $ !, %0&!$ $X&!$ #$&!$ )$& $ ";
const int p_x = 15;
const int p_y = 10;
unsigned int podushka[p_x * p_y];
unsigned int embrace(const char* a, int i) {
unsigned int x = 0;
for(int j = 0; j<3; ++j)
x += (a[i+j]-0x20)<<(j*6);
return x;
}
void make_love(int x, int y) {
unsigned int my = podushka[x + p_x*y];
int my_soul = SOUL(my);
if (my_soul >= sizeof(bormand) - 3)
return;
int my_happiness = embrace(bormand, my_soul);
int dx = 0;
int dy = 0;
switch(my_happiness & 0xFF) {
case upbeat:
podushka[x + y*p_x] = my_soul + MY_LIFE + ((my_happiness & 0xFFFF00)<<8);
break;
case sleepy:
dx = -1; goto sleep;
case tired:
dx = -1; dy = -1; goto sleep;
case left_behind:
dx = -1; dy = 1; goto sleep;
case mad:
dx = 1; goto sleep;
case betrayed:
dx = 1; dy = -1; goto sleep;
case afraid:
dx = 1; dy = 1; goto sleep;
case pessimistic:
dy = -1; goto sleep;
case down:
dy = 1; goto sleep;
sleep:podushka[(x+dx)%p_x + (y+dy)%p_y*p_x] = BODY(my) ? my - 0x10000 : my_soul + MY_LIFE;
podushka[x + p_x*y] = my_happiness>>8;
break;
default:
return;
}
}
int main(int argc, const char * argv[]) {
//cout<<"Bormand: \"" << bormand << "\"\n";
podushka[8+p_x*9] = 1;
// Test
//print2();
for (int t = 0; t<20; ++t) {
for (int i = 0; i<p_x*p_y; ++i)
make_love(i%p_x, i/p_x);
//cout << "step: "<<t<<endl;
//print2();
}
for (int j = 0; j<p_y; ++j) {
for (int i = 0; i<p_x; ++i) {
auto c = podushka[i+p_x*j];
putchar((c>0x20 && c <0x7e)?(char)c:' ');
}
cout<<endl;
}
return 0;
}
https://ideone.com/NSbHSX
bormand
my love
0
bool valueToString(std::string_view str, float& value) try {
const auto end = std::numeric_limits<std::size_t>::max();
const float parsed = std::stof(str.data(), &end);
if (end != str.size())
return false;
value = parsed;
return true;
} catch (...) {
return false;
}
string_view пирформанс! Спойлер: да, там std::stof
+2
string shifarhex(string count)
{
string take,take2;
string getch1;
getch1=count;
string sub1 = "0000";//2 to 3 31
unsigned int pos1 = getch1.find(sub1,0);
if(pos1 != string::npos)
{
take2="0";
}
string sub2 = "0001";//2 to 3 31
unsigned int pos2 = getch1.find(sub2,0);
if(pos2 != string::npos)
{
take2="1";
}
string sub3 = "0010";//2 to 3 31
unsigned int pos3 = getch1.find(sub3,0);
if(pos3 != string::npos)
{
take2="2";
}
string sub4 = "0011";//2 to 3 31
unsigned int pos4 = getch1.find(sub4,0);
if(pos4 != string::npos)
{
take2="3";
}
string sub5 = "0100";//2 to 3 31
unsigned int pos5 = getch1.find(sub5,0);
if(pos5 != string::npos)
{
take2="4";
}
string sub6 = "0101";//2 to 3 31
unsigned int pos6 = getch1.find(sub6,0);
if(pos6 != string::npos)
{
take2="5";
}
string sub7 = "0110";//2 to 3 31
unsigned int pos7 = getch1.find(sub7,0);
if(pos7 != string::npos)
{
take2="6";
}
string sub8 = "0111";//2 to 3 31
unsigned int pos8 = getch1.find(sub8,0);
if(pos8 != string::npos)
{
take2="7";
}
string sub9 = "1000";//2 to 3 31
unsigned int pos9 = getch1.find(sub9,0);
if(pos9 != string::npos)
{
take2="8";
}
string sub10 = "1001";//2 to 3 31
unsigned int pos10 = getch1.find(sub10,0);
if(pos10 != string::npos)
{
take2="9";
}
string sub11 = "1010";//2 to 3 31
unsigned int pos11 = getch1.find(sub11,0);
if(pos11 != string::npos)
{
take2="A";
}
string sub12 = "1011";//2 to 3 31
unsigned int pos12 = getch1.find(sub12,0);
if(pos12 != string::npos)
{
take2="B";
}
string sub13 = "1100";//2 to 3 31
unsigned int pos13 = getch1.find(sub13,0);
if(pos13 != string::npos)
{
take2="B";
}
string sub14 = "1101";//2 to 3 31
unsigned int pos14 = getch1.find(sub14,0);
if(pos14 != string::npos)
{
take2="D";
}
string sub15 = "1110";//2 to 3 31
unsigned int pos15 = getch1.find(sub15,0);
...
http://www.sql.ru/forum/1269897/delaem-arhivator
Вореционное зожатие битов
+1
#ifdef _MSC_VER
# if ( _MSC_VER <= 1800) // MSVC 2012 / 2013
typedef std::vector<char>& vector_ref;
# else
typedef std::vector<char>&& vector_ref;
# endif
#else
typedef std::vector<char>&& vector_ref;
#endif
auto func = std::bind([this](vector_ref v) { /* ... */ }, std::placeholders::_1);
тут говна вагон и маленькая тележка
Во-первых, версии студии, компилятора студии и _MSC_VER всегда разные. Сложно даже представить человека который решил "а давайте распространять компилятор по версии SDK, а проверять по левому числу, не являющемуся ни тем ни другим?"
Во-вторых, поддержка c++11 в msvc 2012/2013 удручает. В 2012 нет даже type aliases, потому и typedef.
В-третьих, кривая реализация bind (rvalue-версия не соберется в студиях 12/13, lvalue - в более поздних).