View union_watcher.cpp
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, typename E, E SYMBOL> | |
class Proxy { | |
public: | |
Proxy(T& value, E& which) : ref(value), which(which) {} | |
Proxy& operator=(const T& value) { | |
ref = value; | |
which = SYMBOL; | |
} | |
operator T() { return ref; } | |
protected: |
View span_babysitter.cpp
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 <cstddef> | |
#include <span> | |
std::span<int> allocate(std::size_t size) { | |
int* storage = new int[size]; | |
return std::span<int>{storage, size}; | |
} | |
void deallocate(std::span<int>& items) { |
View lcb.py
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
from itertools import combinations | |
from math import log, ceil | |
def common_bases(x: int, y: int) -> int: | |
""" | |
Returns a list of all the bases common to x and y | |
That is to say, all bases n such that n can be raised by an integer power to | |
produce x or y | |
The list returned is sorted in ascending order, and may be empty if there |
View constexpr_stack_list.cpp
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
class List { | |
public: | |
constexpr ~List() { | |
if (next != nullptr) { | |
delete next; | |
next = nullptr; | |
} | |
} | |
constexpr void push(int n) { | |
get_end().next = new List; |
View negative_literal.cpp
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 <cstdlib> | |
#include <iostream> | |
signed operator "" _signed(const char* literal) { | |
std::cout << "actual literal value: " << literal << std::endl; | |
return std::strtol(literal, nullptr, 0); | |
} | |
int main() { |
View repetend.cpp
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 <cstddef> | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
struct RepeatingDecimal { | |
std::vector<bool> integer; | |
std::vector<bool> decimal; |
View variadic_xor.cpp
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 <cstddef> | |
namespace { | |
/* | |
* Helper function, variadic xor | |
* It works by counting the number of true values and returning true only | |
* if this number is 1. | |
*/ | |
template <typename T> |
View ContainerAdaptor.cpp
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 <cstddef> | |
#include <vector> | |
template <typename T> | |
class ContainerAdaptor { | |
public: | |
constexpr ContainerAdaptor(std::vector<T>& container) : _container(container) {} | |
// no const version of operator[] is provided, because we always want to resize the vector on out-of-bounds |
View constexpr_vector.cpp
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
// https://godbolt.org/z/vsacWP36z | |
// Note: Only works with x86_64 GCC (trunk) on Godbolt.org --must have a C++ stdlib that supports constexpr vector | |
#include <cstddef> | |
#include <vector> | |
class Storage { | |
private: | |
std::vector<int> foo; | |
public: |
View twelve_days.cpp
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 <iostream> | |
#include <string> | |
#include <cstddef> | |
std::array<std::string, 12> ORDINAL_DAYS = { | |
"first", | |
"second", | |
"third", |
NewerOlder