This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Construtor padrão | |
TestCopy() { | |
cout << "[CONSTR 1]" << endl; | |
this->val = 0; | |
} | |
//Construtor parametrizado | |
TestCopy(T val) { | |
cout << "[CONSTR 2:" << val << "]" << endl; | |
this->val = val; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TestCopy(T val) { | |
cout << "[CONSTR 2:" << val << "]" << endl; | |
this->val = val; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
t5.ts(); //5=============== | |
t1 = t3; //[OP=1] | |
t1.ts(); //1=============== | |
t1 = TestCopy<>{3}; //[CONSTR 2:3] | |
//[OP=3] | |
t3.ts(); //1=============== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vector<TestCopy<>> tm; | |
tm.push_back(TestCopy<>(99)); //[CONSTR 2:99] | |
//[MOVE] | |
tm[0].ts(); //99=============== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Generico. Sem tipos declarados | |
#define FILL(v, i, start, end, step) { \ | |
for(i=start; i < end; i+=step) \ | |
v.push_back(i); \ | |
} | |
#define ACCUM(v, ret) { \ | |
for(size_t i=0; i < v.size(); i++) \ | |
ret += v[i]; \ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename T, typename U> | |
void fill(T &t, U start, U end, U step) { | |
for(U i=start; i < end; i += step) { | |
t.push_back(i); | |
} | |
} | |
template<typename T> | |
auto accum(T &t) { | |
typename T::value_type ret{}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename T, typename U> | |
void fill2(T &v, U start, U step) { | |
*begin(v) = start; | |
generate(begin(v)+1, end(v), [&start, &step]() { return start += step; }); | |
//alternative - this is not a proper std::fill, but a generate | |
//for(auto &item : v) { | |
// item = start; | |
// start += step; | |
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void log_print(const std::string &str) { /* ... */ } | |
bool isInfoEnabled() { /* ... */ } | |
#define LOG_INFO(fmt, x) { \ | |
if(isInfoEnabled()) log_print(boost::str( boost::format(fmt) % x) ); \ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include <cstdio> | |
using namespace std; | |
//this function will be generated | |
int c_accum_i(vector<int> &v) | |
{ | |
int ret{}; | |
for(const auto &i : v) { |
OlderNewer