This file contains hidden or 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
// getting existing table for ctype<char> specialization | |
const auto temp = ctype<char>::classic_table(); | |
// create a copy of the table in vector container | |
vector<ctype<char>::mask> bar(temp, temp + ctype<char>::table_size); | |
// add/remove stream separators using bitwise arithmetic. | |
// use char-based indices because ascii codes here are equal to indices | |
bar[' '] ^= ctype_base::space; | |
bar['\t'] &= ~(ctype_base::space | ctype_base::cntrl); | |
bar[':'] |= ctype_base::space; |
This file contains hidden or 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
/** | |
usage: std::cout << measure<>::execution(functor(dummy)) << std::endl | |
*/ | |
template <typename TimeT = std::chrono::nanoseconds> struct measure { | |
template <typename F, typename... Args> | |
static typename TimeT::rep execution(F func, Args &&... args) { | |
auto start = std::chrono::steady_clock::now(); | |
func(std::forward<Args>(args)...); | |
auto duration = std::chrono::duration_cast<TimeT>( | |
std::chrono::steady_clock::now() - start); |
This file contains hidden or 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> class singleton { | |
void operator=(T const &) = delete; | |
singleton(T const &) = delete; | |
public: | |
static T &get_instance() { | |
static T inst; | |
return inst; | |
} | |
}; |
This file contains hidden or 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
// checking that iterator is forward_itertaor | |
template <class iter> | |
using iterator_type_checked = | |
std::is_same<typename std::iterator_traits<iter>::iterator_category, | |
std::forward_iterator_tag>; |
This file contains hidden or 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 function_type, typename... argument_types> | |
auto spawn_task(function_type &&f, argument_types &&... args) { | |
using result_type = | |
typename std::result_of<function_type(argument_types && ...)>::type; | |
using packaged_task = std::packaged_task<result_type(argument_types && ...)>; | |
auto task = packaged_task{std::forward<function_type>(f)}; | |
auto future = task.get_future(); | |
task(args...); |
This file contains hidden or 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
emplate<size_t N> | |
struct fibonacci : integral_constant<size_t, fibonacci<N-1>{} + fibonacci<N-2>{}> {}; | |
template<> struct fibonacci<1> : integral_constant<size_t,1> {}; | |
template<> struct fibonacci<0> : integral_constant<size_t,0> {}; |
This file contains hidden or 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
struct node { | |
int data; | |
node *left = nullptr; | |
node *right = nullptr; | |
}; | |
void TraversBFS(node *root) { | |
std::queue<node *> q; | |
q.push(root); | |
for (node *n = q.front(); !q.empty(); n = q.front()) { |
This file contains hidden or 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 <iostream> | |
#include <cstring> | |
#include <algorithm> | |
#include <iterator> | |
#include <vector> | |
#include <queue> | |
// TODO create tree as an array | |
auto build_tree(std::size_t n) { | |
std::vector<int> tree(n); |
This file contains hidden or 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 <iostream> | |
#include <algorithm> | |
#include <iterator> | |
#include <numeric> | |
int* array_append(int *arr, unsigned int &size, int value) { | |
int *new_arr = new int[size + 1]; | |
std::memcpy(new_arr, arr, size * sizeof(*new_arr)); | |
if (size && arr != nullptr) |