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 Iterator1, typename Iterator2> | |
void sorted_insert(Iterator1 first_begin, | |
Iterator1 first_end, | |
Iterator2 second_begin, | |
Iterator2 second_end, | |
Iterator2 buffer_end) | |
{ | |
--first_begin; | |
--first_end; | |
--second_end; |
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> | |
constexpr bool is_positive(const T& value) | |
{ | |
return ! (value & 1 << (sizeof(T) * 8 - 1)); | |
} | |
template<bool condition> | |
struct determine; | |
template<> |
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> | |
T get_max(const T& first, const T& second) | |
{ | |
double first_half = first / 2.0; | |
double second_half = second / 2.0; | |
bool sign = std::signbit(first_half - second_half); | |
return (sign * second) + (!sign * first); | |
} |
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 Iterator> | |
std::pair<Iterator, Iterator> find_sorting_range(Iterator begin, Iterator end) | |
{ | |
Iterator start_unsorted = begin; | |
for (auto previous = start_unsorted++; | |
start_unsorted != end; | |
++previous, ++start_unsorted) | |
{ | |
if (*start_unsorted < *previous) break; |
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 Iterator> | |
auto maximum_subarray(Iterator begin, Iterator end) -> decltype(*begin + *begin) | |
{ | |
using T = decltype(*begin + *begin); | |
T sum = 0; | |
T best = 0; | |
auto largest = end; |
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 Node> | |
class XMLCompressor | |
{ | |
public: | |
using map_t = std::map<std::string, std::string>; | |
static map_t global_keywords; | |
std::string operator()(Node* node, map_t& keywords = global_keywords) |
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
class Card | |
{ | |
public: | |
using value_t = unsigned char; | |
enum Type : unsigned char | |
{ | |
Hearts, | |
Spades, |
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
std::vector<std::string> separate(const std::string& string, | |
const std::unordered_set<std::string>& dictionary) | |
{ | |
std::vector<std::string> words; | |
std::string current; | |
for (auto character = string.begin(), end = string.end(); | |
character != end; | |
++character) |
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 Node> | |
class TreeToList | |
{ | |
public: | |
Node* operator()(Node* root) | |
{ | |
_transform(root, root); | |
while (root->left) root = root->left; |
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 Iterator, typename Sum> | |
auto find_sum_pairs(Iterator begin, Iterator end, const Sum& target) | |
{ | |
std::vector<std::pair<Iterator, Iterator>> pairs; | |
if (begin == end) return pairs; | |
// O(N lg N) | |
std::sort(begin, end--); | |