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 <iostream> | |
// Just A CRTP pratices | |
template<typename Derived> | |
class enable_compare_operators | |
{ | |
public: | |
bool operator == (enable_compare_operators<Derived> const & rhs) const | |
{ |
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
// largely inspire by https://monoinfinito.wordpress.com/series/introduction-to-c-template-metaprogramming/ | |
#include <iostream> | |
// represent a fraction (upper/downer) | |
template <int upper, int downer> | |
struct frac | |
{ | |
static constexpr int up = upper; | |
static constexpr int down = downer; |
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 <iostream> | |
#include <type_traits> | |
namespace functional_list | |
{ | |
struct NIL | |
{ | |
using head = NIL; |
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 <iostream> | |
#include <vector> | |
#include <type_traits> | |
template<typename T> | |
struct can_string_cat_impl | |
{ | |
template <typename Operand> | |
static auto test(Operand o) -> decltype(std::declval<std::string>() += o); | |
template <typename...> |
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 <iostream> | |
#include <vector> | |
#include <algorithm> | |
#include <numeric> | |
template<typename T = int> | |
class mat | |
{ | |
T width = 0, height = 0; | |
std::vector<std::vector<T>> hold; |
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 <iostream> | |
#include <functional> | |
#include <memory> | |
std::function<int(void)> create_counter(int start) | |
{ | |
std::shared_ptr<int> ptr = std::make_shared<int>(start); | |
std::function<int(void)> inc_one = [ptr] () { | |
return (*ptr)++; | |
}; |
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 <array> | |
#include <map> | |
#include <limits> | |
#include <iostream> | |
using course = int; | |
using days = int; | |
using score_table = std::array<std::array<int, 5>, 4>; | |
inline |
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 <algorithm> | |
#include <iostream> | |
#include <string_view> | |
std::vector<int> findSubstring(std::string s, std::vector<std::string>& words) | |
{ | |
std::string::size_type word_length = words.front().length(); | |
std::sort(words.begin(), words.end()); |
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 <iostream> | |
// based on https://stackoverflow.com/a/46711735/5921729 | |
constexpr inline | |
long long int hash(char const * str, int h = 0) | |
{ | |
return (!str[h] ? 5381 : (hash(str, h+1)*33) ^ str[h] ); | |
} | |
constexpr inline |
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> | |
T max (T&& t) {return t;} | |
template<typename T, typename ... Types> | |
auto max(T && t, Types && ...args) | |
{ | |
return std::max(t, max(args...)); | |
} | |
OlderNewer