Skip to content

Instantly share code, notes, and snippets.

View day02's full-sized avatar

day day02

View GitHub Profile
#include <iostream>
enum class security_level_t : unsigned int {
none = 0xffffffff,
low = 0,
medium = 1,
high = 2,
};
static bool operator!(const security_level_t security_level) {
#include <iostream>
#include <future>
#include <thread>
#include <vector>
std::vector<int> myVec{};
void prepare_work(std::promise<void> &&promise) {
myVec = {0, 1, 0, 3};
std::cout << "Sender: Data prepared." << std::endl;
#include <array>
#include <numeric>
#include <cmath>
#include <iostream>
// array of floats with size atleast 1.
template <typename T, size_t N>
concept array_with_atleast_two_float_t = std::floating_point<T> && (N >= 2);
// concept addable
// interface or trait
trait Interface {
fn step1(&self);
fn step2(&self);
}
// function which utilizes the traits
fn utitlize_trait(obj: impl Interface) {
obj.step1();
obj.step2();
}
struct base {
base() = default;
virtual ~base() = default;
// class can not be copyable if polymorphic
base(const base &) = delete; base& operator=(const base&) = delete;
base(base &&) = default; base& operator=(base&&) = default;
virtual void do_something() = 0;
};
@day02
day02 / JThread.cpp
Last active November 10, 2020 03:47
#include <thread>
#include <chrono>
#include <iostream>
void task(std::stop_token stop_token, int value) {
while (!stop_token.stop_requested()) {
std::cout << "task working :" << --value << std::endl;
std::this_thread::sleep_for (std::chrono::seconds(1));
}
}
#include <cassert>
#include <vector>
#include <map>
#include <span>
#include <ranges>
#include <algorithm>
#include <numeric>
#include <random>
#include <iostream>
#include <execution>
#include <iostream>
#include <shared_mutex>
#include <future>
struct information {
static void writer(unsigned int value) {
std::unique_lock<std::shared_mutex> lock(s_shared_mutex);
s_data = value;
}
#include <iostream>
#include <vector>
#include <future>
struct accumulator
{
accumulator() = default;
~accumulator() = default;
#include <iostream>
template <class F, class G>
decltype(auto) compose(F&& f, G&& g) {
return [=](auto x) { return f(g(x)); };
}
int main() {
auto square = [](auto x) { return x * x;};
auto increment = [](auto x) { return x + 1;};