Skip to content

Instantly share code, notes, and snippets.

View thiagomg's full-sized avatar

Thiago Massari Guedes thiagomg

View GitHub Profile
@thiagomg
thiagomg / lambda2.cpp
Created August 27, 2015 18:23
Lambda auto
//Super duper automatic
auto f1 = [&b](auto v) {
return v*b;
};
@thiagomg
thiagomg / lambda2.cpp
Created August 27, 2015 18:23
Lambda decltype
//More restrict
auto f2 = [&b](auto v) -> decltype(v*b) {
return v*b;
};
@thiagomg
thiagomg / lambda2.cpp
Created August 27, 2015 18:23
Lambda restrict
//very restrict
auto f3 = [&b](int v) -> int {
return v*b;
};
@thiagomg
thiagomg / parser_example.cpp
Last active August 27, 2015 18:25
Lambda - Parser example
fix_parser parser;
msg_transport::received_msg(transport, [&m](auto &data) {
message m = parser.get_msg(data);
processor.new_msg(m);
});
msg_transport::received_cmd(transport, [&m](auto &data) {
command c = parser.get_msg(data);
admin.new_msg(c);
@thiagomg
thiagomg / lambda.cpp
Last active August 29, 2015 11:14
Lambda
[&b](auto v) {
return v*b;
};
//Construtor padrão
TestCopy() {
cout << "[CONSTR 1]" << endl;
this->val = 0;
}
//Construtor parametrizado
TestCopy(T val) {
cout << "[CONSTR 2:" << val << "]" << endl;
this->val = val;
TestCopy(T val) {
cout << "[CONSTR 2:" << val << "]" << endl;
this->val = val;
}
//Saída do programa:
TestCopy<> t1; //[CONSTR 1]
TestCopy<> t2 {1}; //[CONSTR 2:1]
TestCopy<> t3 = t2; //[COPY]
TestCopy<> t4 {t2}; //[COPY]
TestCopy<> t5 = TestCopy<>{5}; //[CONSTR 2:5]
TestCopy<> t6 = {6}; //[CONSTR 2:6]
TestCopy<> t7 = 7; //[CONSTR 2:7]
t5.ts(); //5===============
t1 = t3; //[OP=1]
t1.ts(); //1===============
t1 = TestCopy<>{3}; //[CONSTR 2:3]
//[OP=3]
t3.ts(); //1===============
vector<TestCopy<>> tm;
tm.push_back(TestCopy<>(99)); //[CONSTR 2:99]
//[MOVE]
tm[0].ts(); //99===============