1#include <bits/stdc++.h>
66template <
typename ValueType>
69 virtual void set(ValueType i) = 0;
73template <
typename ValueType>
76 virtual ValueType
get()
const = 0;
80template <
typename ValueType>
83 virtual void change(ValueType c) = 0;
87template <
typename ValueType>
96 void set(ValueType i)
override {
97 scoped_lock writer_lock(mtx);
101 ValueType get()
const override {
102 shared_lock reader_lock(mtx);
106 void change(ValueType c)
override {
107 scoped_lock writer_lock(mtx);
111 mutable shared_mutex mtx;
124 assert(g.get() == 1);
133 assert(g.
get() ==
"abc");
141 assert(g2.
get() ==
"abcde");
186#define SINGLETON(Singleton) \
189 static Singleton& instance() { \
190 static Singleton me; \
193 Singleton(const Singleton&) = delete; \
194 Singleton& operator=(const Singleton&) = delete; \
195 Singleton(Singleton&&) = delete; \
196 Singleton& operator=(Singleton&&) = delete; \
227 return make_unique<Sample_product>(123);
233 virtual unique_ptr<Interface>
create() = 0;
240 return make_unique<Sample_product>();
250 unique_ptr<Interface>
create()
override {