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
#pragma once | |
#include <cstddef> | |
#include <functional> | |
#include <queue> | |
// A buffer class that accumulates items in a queue and processes them when a | |
// specified capacity is reached. | |
template <typename T, std::size_t Capacity> | |
class Buffer { |
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 <functional> | |
#include <iostream> | |
#include <mutex> | |
#include <thread> | |
#include <vector> | |
// Thread-safe implementation of a log | |
class Log { | |
private: | |
std::vector<int> codeLog; |
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 <future> | |
#include <iostream> | |
#include <numeric> | |
#include <vector> | |
// Returns the sum of all integers between [1, n] | |
int sum(const unsigned int n) { | |
std::vector<int> numbers(n); | |
std::iota(numbers.begin(), numbers.end(), 1); | |
return std::accumulate(numbers.begin(), numbers.end(), 0); |
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 <barrier> | |
#include <functional> | |
#include <iostream> | |
#include <string> | |
#include <thread> | |
#include <vector> | |
struct Person { | |
std::string name; | |
int age; |