- 1
- 2
- 3
- 4
std::string CryptoOperations::getLastError()
{
return "Произошла неизвестная ошибка при выполнении криптооперации";
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−4
std::string CryptoOperations::getLastError()
{
return "Произошла неизвестная ошибка при выполнении криптооперации";
}
+9
int turn = m_mapObject->getTurnSpeed();
//НЕ НАДО ТУТ ОПТИМИЗИРОВАТЬ /= 45 !!!!
if (turn != 0) {
if (turn > 0) {
// qDebug() << "Turn plus";
turn /= 45;
if (turn < 4) turn = 4;
if (turn > 8) turn = 8;
} else {
// qDebug() << "Turn minus";
turn /= 45;
if (turn > -4) turn = -4;
if (turn < -8) turn = -8;
}
paint.drawLine(QPoint(0,-speed),QPoint(turn,-speed));
}
Вы б знали, как руки чешутся...
+5
std::string cmd = "some command";
Socket.Write( cmd.c_str(), strlen( cmd.c_str() ) );
сишные плюсЫ
+6
int main() {
interpretator_t i;
i.eval(
{let, "factorial_helper", {quote, {"this", "num"},
{if_, {eq_, {"num"}, 0}, 1, {mul_, {"num"}, {{"this"}, {"this"}, {sub_, {"num"}, 1}}}}
},
{let, "factorial", {quote, {"num"}, {{"factorial_helper"}, {"factorial_helper"}, {"num"}}},
{do_,
{write_, "vvedite chislo: "},
{assign_, "x", {to_number_, {read_}}},
{write_, "factorial: "},
{write_, {{"factorial"}, {"x"}}},
{write_, "\n"}
}
}}
);
return 0;
}
Смотрите, какой лисп я написал. Он еще и ленивый.
+1
TBufferedFileInput storage(sprintf("%s", path));
Весьма оригинальный способ приведения типа к самому себе.
−4
#include <stdio.h>
#include <iostream>
#include <regex>
using namespace std;
int cube(int);
int main()
{
char number;
label:
cout << " Введите число " << endl;
cin >> number;
regex txt_regex("/^\d+$/");
if (!regex_match(number, txt_regex))
{
cout << "Вводить можно только цифры!" << endl;
goto label;
}
int value = atoi(number);
int result = cube(value);
cout << "Куб числа " << number << " равен " << result;
return 0;
}
int cube(int number)
{
return number * number * number;
}
Возведение числа в куб.
+3
#ifndef DEFINES
#define DEFINES
#define _W_CALL(a,b) a b
#define _W_NARGS_OVERRIDE(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, N, ...) N
#define _W_NARGS(...) _W_NARGS_OVERRIDE("ignored", ##__VA_ARGS__, 10, 9, 8, 7, 6 ,5, 4, 3, 2, 1, 0)
#define _W_GETPARAM1(_1,...) _1
#define _W_GETPARAM2(_1,_2,...) _2
#define _W_GETPARAM3(_1,_2,_3,...) _3
#define _W_ARG_OVERRIDE(_1, _2, _3, NAME, ...) NAME
#define _W_ARG2(a,b) (a,b)
#define _W_ARG3(a,b,c) (a,b,c)
#define W_ARG(...) _W_ARG_OVERRIDE(__VA_ARGS__, _W_ARG3, _W_ARG2)(__VA_ARGS__)
#define _W_ARGNAME2(a,b) b
#define _W_ARGNAME3(a,b,c) b
#define _W_ARGNAME_(...) _W_ARG_OVERRIDE(__VA_ARGS__, _W_ARGNAME3, _W_ARGNAME2)(__VA_ARGS__)
#define _W_ARGNAME(a) _W_ARGNAME_ a
#define _W_ARGPREP2(a,b) a b
#define _W_ARGPREP3(a,b,c) a bc
#define _W_ARGPREP_(...) _W_ARG_OVERRIDE(__VA_ARGS__, _W_ARGPREP3, _W_ARGPREP2)(__VA_ARGS__)
#define _W_ARGPREP(a) _W_ARGPREP_ a
#define _W_FUNCTPARAM1(a) _W_ARGPREP(a)
#define _W_FUNCTPARAM2(a,b) _W_ARGPREP(a), _W_ARGPREP(b)
#define _W_FUNCTPARAM3(a,b,c) _W_ARGPREP(a) , _W_ARGPREP(b) , _W_ARGPREP(c)
#define _W_FUNCTPARAM4(a,b,c,d) _W_ARGPREP(a) , _W_ARGPREP(b) , _W_ARGPREP(c) , _W_ARGPREP(d)
#define _W_FUNCTPARAM5(a,b,c,d,e) _W_ARGPREP(a) , _W_ARGPREP(b) , _W_ARGPREP(c) , _W_ARGPREP(d) , _W_ARGPREP(e)
#define _W_FUNCTPARAM6(a,b,c,d,e,f) _W_ARGPREP(a) , _W_ARGPREP(b) , _W_ARGPREP(c) , _W_ARGPREP(d) , _W_ARGPREP(e) , _W_ARGPREP(f)
#define _W_FUNCTPARAM7(a,b,c,d,e,f,g) _W_ARGPREP(a) , _W_ARGPREP(b) , _W_ARGPREP(c) , _W_ARGPREP(d) , _W_ARGPREP(e) , _W_ARGPREP(f), _W_ARGPREP(g)
#define _W_FUNCTPARAM8(a,b,c,d,e,f,g,h) _W_ARGPREP(a) , _W_ARGPREP(b) , _W_ARGPREP(c) , _W_ARGPREP(d) , _W_ARGPREP(e) , _W_ARGPREP(f), _W_ARGPREP(g), _W_ARGPREP(h)
#define _W_FUNCTPARAM9(a,b,c,d,e,f,g,h,i) _W_ARGPREP(a) , _W_ARGPREP(b) , _W_ARGPREP(c) , _W_ARGPREP(d) , _W_ARGPREP(e) , _W_ARGPREP(f), _W_ARGPREP(g), _W_ARGPREP(h), _W_ARGPREP(i)
#define _W_FUNCTPARAM10(a,b,c,d,e,f,g,h,i,j) _W_ARGPREP(a) , _W_ARGPREP(b) , _W_ARGPREP(c) , _W_ARGPREP(d) , _W_ARGPREP(e) , _W_ARGPREP(f), _W_ARGPREP(g), _W_ARGPREP(h), _W_ARGPREP(i), _W_ARGPREP(j)
#define _W_FUNCTPARAMS_OVERRIDE(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, NAME, ...) NAME
#define _W_FUNCTPARAMS(...) _W_FUNCTPARAMS_OVERRIDE(__VA_ARGS__,_W_FUNCTPARAM10,_W_FUNCTPARAM9,_W_FUNCTPARAM8,_W_FUNCTPARAM7,_W_FUNCTPARAM6,_W_FUNCTPARAM5,_W_FUNCTPARAM4,_W_FUNCTPARAM3,_W_FUNCTPARAM2,_W_FUNCTPARAM1)(__VA_ARGS__)
#define _W_FUNCTNAME1(a) _W_ARGNAME(a)
#define _W_FUNCTNAME2(a,b) _W_ARGNAME(a), _W_ARGNAME(b)
#define _W_FUNCTNAME3(a,b,c) _W_ARGNAME(a) , _W_ARGNAME(b) , _W_ARGNAME(c)
#define _W_FUNCTNAME4(a,b,c,d) _W_ARGNAME(a) , _W_ARGNAME(b) , _W_ARGNAME(c) , _W_ARGNAME(d)
#define _W_FUNCTNAME5(a,b,c,d,e) _W_ARGNAME(a) , _W_ARGNAME(b) , _W_ARGNAME(c) , _W_ARGNAME(d) , _W_ARGNAME(e)
#define _W_FUNCTNAME6(a,b,c,d,e,f) _W_ARGNAME(a) , _W_ARGNAME(b) , _W_ARGNAME(c) , _W_ARGNAME(d) , _W_ARGNAME(e) , _W_ARGNAME(f)
#define _W_FUNCTNAME7(a,b,c,d,e,f,g) _W_ARGNAME(a) , _W_ARGNAME(b) , _W_ARGNAME(c) , _W_ARGNAME(d) , _W_ARGNAME(e) , _W_ARGNAME(f), _W_ARGNAME(g)
#define _W_FUNCTNAME8(a,b,c,d,e,f,g,h) _W_ARGNAME(a) , _W_ARGNAME(b) , _W_ARGNAME(c) , _W_ARGNAME(d) , _W_ARGNAME(e) , _W_ARGNAME(f), _W_ARGNAME(g), _W_ARGNAME(h)
#define _W_FUNCTNAME9(a,b,c,d,e,f,g,h,i) _W_ARGNAME(a) , _W_ARGNAME(b) , _W_ARGNAME(c) , _W_ARGNAME(d) , _W_ARGNAME(e) , _W_ARGNAME(f), _W_ARGNAME(g), _W_ARGNAME(h), _W_ARGNAME(i)
#define _W_FUNCTNAME10(a,b,c,d,e,f,g,h,i,j) _W_ARGNAME(a) , _W_ARGNAME(b) , _W_ARGNAME(c) , _W_ARGNAME(d) , _W_ARGNAME(e) , _W_ARGNAME(f), _W_ARGNAME(g), _W_ARGNAME(h), _W_ARGNAME(i), _W_ARGNAME(j)
#define _W_FUNCTNAMES_OVERRIDE(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, NAME, ...) NAME
#define _W_FUNCTNAMES(...) _W_FUNCTNAMES_OVERRIDE(__VA_ARGS__,_W_FUNCTNAME10,_W_FUNCTNAME9,_W_FUNCTNAME8,_W_FUNCTNAME7,_W_FUNCTNAME6,_W_FUNCTNAME5,_W_FUNCTNAME4,_W_FUNCTNAME3,_W_FUNCTNAME2,_W_FUNCTNAME1)(__VA_ARGS__)
#define W_FUNCT(className, retType, functName, ...) \
private: \
retType _##functName( _W_FUNCTPARAMS(__VA_ARGS__) ); \
retType (className::*__##functName)( _W_FUNCTPARAMS(__VA_ARGS__) ); \
public: \
retType functName( _W_FUNCTPARAMS(__VA_ARGS__) ) { return (this->*__##functName)( _W_FUNCTNAMES(__VA_ARGS__) ); }
#define W_FUNCT_REL(className, functName, classPointer) classPointer->__##functName = & className::_##functName;
#define _W_STRING(X) #X
#endif // DEFINES
Немножко надэфайнил.
+1
import std.io;
import std.string;
import calendar.month;
module calendar.date;
namespace Chrono
{
export
struct Date {
Date(int, Month, int);
int day() const
{
return d;
}
Month month() const
{
return m;
}
Int year() const
{
return y;
}
private:
int d;
Month m;
int y;
};
export
std::ostream &operator<<(std::ostream &, const Date &);
export
std::string to_string(const Date &);
}
По мотивам: http://habrahabr.ru/company/infopulse/blog/267781/
зы. https://github.com/isocpp/CppCoreGuidelines/blob/master/talks/Large-Scale-C%2B%2B-With-Modules.pdf
+4
long long int Factorial(long long int m_nValue)
{
long long int result=m_nValue;
long long int result_next;
long long int pc = m_nValue;
do
{
result_next = result*(pc-1);
result = result_next;
pc--;
}while(pc>2);
m_nValue = result;
return m_nValue;
}
http://rosettacode.org/wiki/Factorial#C.2B.2B
+2
#include <memory>
#include <list>
struct ListNode;
using List = std::unique_ptr<const ListNode>;
struct ListNode {
const int data;
const List next;
~ListNode()
{
if(!next)
return;
else {
std::list<ListNode*> nodes;
for(auto pn = next.get(); pn->next; pn = pn->next.get()) {
nodes.push_back(const_cast<ListNode*>(pn));
}
for(decltype(nodes)::reverse_iterator in = nodes.rbegin(); in != nodes.rend(); ++in) {
const_cast<List&>((*in)->next).reset();
}
}
}
};
List Cons(int head, List tail)
{
return List(new ListNode{head, std::move(tail)});
}
List Nil()
{
return List();
}
size_t len(const List & self)
{
if (!self) {
return 0;
}
return 1 + len(self->next);
}
#include <iostream>
void test(size_t n)
{
auto p = Nil();
for (size_t i = 0; i < n; ++i) {
auto x = std::move(p);
p = Cons(1, std::move(x));
}
std::cout << "done: " << std::endl;
}
int main()
{
test(131028);
}
односвязный список против джависта
источник: https://www.linux.org.ru/forum/development/11752940?cid=11755489