Skip to content

Instantly share code, notes, and snippets.

View thiagomg's full-sized avatar

Thiago Massari Guedes thiagomg

View GitHub Profile
@thiagomg
thiagomg / config.h
Created February 4, 2016 22:20
Leitura de configuração em C++
template<typename Key, typename Value, typename AdderFunc>
void crack(config_holder<Key, Value> &config, const std::string &line, char delim, AdderFunc f) {
auto b = std::begin(line);
auto e = std::end(line);
auto pos = line.find(delim);
if( pos != std::string::npos ) {
f(config, b, b+pos, e);
}
}
@thiagomg
thiagomg / config.h
Created February 4, 2016 22:19
Leitura de configuração em C++
std::ifstream istr;
istr.open(file_name);
while( istr.good() ) {
std::string line;
std::getline(istr, line);
std::cout << line << std::endl;
}
@thiagomg
thiagomg / config.h
Created February 4, 2016 22:18
Leitura de configuração em C++
template<typename Key = std::string, typename Value = std::string, typename Store = std::unordered_map<Key, Value>>
struct config_holder {
using key_iter = typename Key::const_iterator;
using val_iter = typename Value::const_iterator;
using key_pair = std::pair<key_iter, key_iter>;
using val_pair = std::pair<val_iter, val_iter>;
using range = std::pair<key_pair, val_pair>;
using map_value = typename Store::value_type;
};
@thiagomg
thiagomg / numeric.cpp
Last active December 17, 2015 10:37
Legibilidade com C++14 - get_numeric
template<typename T>
T get_numeric(const T &input)
{
T output;
std::copy_if(begin(input), end(input), std::back_inserter(output), [](auto c) {
return ( c >= '0' && c <= '9' );
});
return output;
}
@thiagomg
thiagomg / numeric.cpp
Created December 9, 2015 13:39
Legibilidade com C++14 - get_numeric
template<typename T>
T get_numeric(const T &input)
{
T output;
std::for_each(begin(input), end(input), [&output](auto c) {
if( c >= '0' && c <= '9' ) output.push_back(c);
});
return output;
}
@thiagomg
thiagomg / numeric.cpp
Created December 9, 2015 13:39
Legibilidade com C++14 - get_numeric
std::string get_numeric(const std::string &input)
{
std::string output;
std::for_each(begin(input), end(input), [&output](const char c) {
if( c >= '0' && c <= '9' ) output.push_back(c);
});
return output;
}
@thiagomg
thiagomg / numeric.cpp
Created December 9, 2015 13:37
Legibilidade com C++14 - get_numeric
template<class OutputIterator, class ValueType>
struct numerical_appender {
numerical_appender(OutputIterator it) : _it(it) { }
void operator()(const ValueType c) {
if( c >= '0' && c <= '9' ) {
*_it = c;
_it++;
}
}
private:
@thiagomg
thiagomg / numeric.cpp
Created December 9, 2015 13:36
Legibilidade com C++14 - get_numeric
struct numerical_appender {
numerical_appender(std::string &buf) : _buf(buf) { }
void operator()(const char c) {
if( c >= '0' && c <= '9' ) _buf.push_back(c);
}
private:
std::string &_buf;
};
void get_numeric(const std::string &input, std::string &output)
@thiagomg
thiagomg / layout.cpp
Created November 23, 2015 01:57
Layout de memória de structs e classes
//16B
struct message {
int x; //4B
int y; //4B
int z; //4B
int w; //4B
};
//16B
struct pack1 {
@thiagomg
thiagomg / layout.cpp
Created November 23, 2015 01:55
Layout de memória de structs e classes
class router {
message m1;
message *m2
message &m3;
}