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
#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) { |
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
#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; |
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
#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 |
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
// 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(); | |
} |
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
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; | |
}; |
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
#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)); | |
} | |
} |
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
#include <cassert> | |
#include <vector> | |
#include <map> | |
#include <span> | |
#include <ranges> | |
#include <algorithm> | |
#include <numeric> | |
#include <random> | |
#include <iostream> | |
#include <execution> |
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
#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; | |
} |
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
#include <iostream> | |
#include <vector> | |
#include <future> | |
struct accumulator | |
{ | |
accumulator() = default; | |
~accumulator() = default; |
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
#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;}; |