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 <memory> | |
#include <string> | |
#include <iostream> | |
using salary_t = std::uint32_t; | |
struct user | |
{ | |
user(const std::string &name); | |
~user(); |
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 <string> | |
#include <boost/signals2.hpp> | |
template<typename T> | |
struct observable | |
{ | |
void subscribe(const auto&& observer) | |
{ | |
m_field_changed.connect(observer); |
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 <string> | |
#include <vector> | |
#include <algorithm> | |
template<typename T> | |
struct observer | |
{ | |
// callback required | |
virtual void field_changed(T &source, const std::string &field_name) = 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 <utility> | |
struct MyType | |
{ | |
[[nodiscard]] MyType() {} | |
}; | |
template <typename T, typename ... Args> | |
[[nodiscard]] T* create(Args&& ... args) |
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 <memory> | |
#include <vector> | |
struct memento | |
{ | |
std::int32_t m_balance{}; | |
memento(const std::int32_t balance) : m_balance(balance) {} | |
}; |
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> | |
struct point | |
{ | |
int m_x{}; | |
int m_y{}; | |
point(const int x, const int y) : m_x(x), m_y(y){} |
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
// Example program | |
#include <iostream> | |
#include <string> | |
#include <cmath> | |
struct point | |
{ | |
struct factory | |
{ | |
static point cartesian(const double x, const double y) { return point(x, y); } |
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 <string> | |
#include <map> | |
#include <memory> | |
enum class point_t | |
{ | |
point_2D, | |
point_3D | |
}; |
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 <functional> | |
#include <iostream> | |
template <typename T> | |
struct logger; | |
// return type and argument list | |
template <typename return_t, typename... Args> | |
struct logger<return_t (Args...)> | |
{ |
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
// Flyway Design Pattern is quite simply a space optimization technique. That allows you to use less memory by storing some of the common data to several items or several objects. | |
#include <boost/flyweight.hpp> | |
#include <string> | |
#include <iostream> | |
using namespace std; | |
struct user { | |
user(const std::string &first_name, const std::string &last_name) : m_first_name(first_name), m_last_name(last_name) {} |