Skip to content

Instantly share code, notes, and snippets.

View thiagomg's full-sized avatar

Thiago Massari Guedes thiagomg

View GitHub Profile
@thiagomg
thiagomg / macro_templ.cpp
Last active August 29, 2015 14:20
Do macro ao template
//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]; \
}
@thiagomg
thiagomg / macro_templ.cpp
Created May 5, 2015 01:09
Do macro ao template
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{};
@thiagomg
thiagomg / macro_templ.cpp
Last active August 29, 2015 14:20
Do macro ao template
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;
//}
void log_print(const std::string &str) { /* ... */ }
bool isInfoEnabled() { /* ... */ }
#define LOG_INFO(fmt, x) { \
if(isInfoEnabled()) log_print(boost::str( boost::format(fmt) % x) ); \
}
#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) {
@thiagomg
thiagomg / hello2.cpp
Created May 19, 2015 01:49
Hello - Std C++
std::cout << "Hello from Fabio !" << std::endl;
std::cout << "Hello from Thiago !" << std::endl;
std::cout << "Fabio hopes you like the site !" << std::endl;
std::cout << "Thiago hopes you like the site !" << std::endl;
@thiagomg
thiagomg / sizes.cpp
Created June 1, 2015 00:06
Tamanho e alinhamento
struct Field {
unsigned int f1; //int=4 bytes
unsigned char f2; //char=1 byte
};
@thiagomg
thiagomg / sizes.cpp
Created June 1, 2015 00:13
Tamanho e alinhamento
struct FieldC {
unsigned char f1; //char=1 byte
unsigned int f2; //int=4 bytes
};
@thiagomg
thiagomg / sizes.cpp
Created June 1, 2015 00:55
Tamanho e alinhamento
struct Field4 {
unsigned char f1; //char=1 byte
unsigned int f2; //int=4 bytes
unsigned char f3; //char=1 byte
};
@thiagomg
thiagomg / sizes.cpp
Created June 1, 2015 01:31
Tamanho e alinhamento
struct Field5 {
unsigned int f2; //int=4 bytes
unsigned char f1; //char=1 byte
unsigned char f3; //char=1 byte
};