CoolerCppIdiom
cooler c++ patterns like async, event delegate, json auto serialization
Install / Use
/learn @hiitiger/CoolerCppIdiomREADME
CoolerCppIdiom
Collection of useful c++ tools / common idioms you might not found elsewhere, provide with clean code and easy to use api, mose of then are just one file with minimal dependency.
How to
Just include the corresponding file.
Useful kits
cooler cpp async
A cooler version of promise pattern, we can create our own dispatcher to dispatch task to threads(ui,pool,io,http,etc) just like using std::async and future<T>::then.
This specific implementation uses ppltask, but we can implement it on any primise-like library for c++.
using namespace concurrency_;
auto t = delayed(1000)
| ui([] {
std::cout << "running on ui" << std::endl;
})
| io([] {
std::cout << "running on io" << std::endl;
return std::this_thread::get_id();
})
| delay<std::thread::id>(100)
| pool([](std::thread::id id) {
std::cout << "running on pool" << std::endl;
std::cout << "received thread_id" << id << std::endl;
});
json auto serialize
Make json serialization easier for your life.
With nlohmann's JSON for Modern C++ plus a helper file, we can do this now
struct Person{
std::string name;
std::optional<std::uint32_t> age;
std::optional<std::vector<Person>> friends;
};
JSON_AUTO(Person, name, age, friends)
void func()
{
Person p;
p.name = "John";
json obj = p;
Person op = obj;
}
Event Delegate
A simple yet powerful event delegate implementation, support trackable listener, provide an alternate bind to std::bind which support bind to smart pointer.
Event<void(const std::string&, std::string&&)> signal1;
auto func1 = Storm::lambda([&, nocopy]() {
signal1("123", "123");
});
auto conn1 = signal1.add([&slot1](const std::string& v, std::string&& str){
slot1 = true;
std::cout << "\nslot 1: " << v << ", " << std::string(std::move(str)) << std::endl;
});
Connection conn2 = signal1.add([&slot2, &conn2](const std::string& v, std::string&& str) {
slot2 = true;
std::cout << "\nslot 2: " << v << ", " << str << std::endl;
conn2.disconnect();
});
func1();
qasync
An async call adapter for Qt which enables user to post async lambda to Qt's UI thread.
workerpool
A easy to use c++11 thread pool.
snowflake
Snowflake uuid generator in c++.
throttle
A simple throttle control.
trace
Object leak trace, perf timer and extras.
time
Timetick, Datetime, FpsTimer.
com ptr
Windows Com ptr implementation with clean and safe interface.
object tree
Object tree is a useful way to manage object in c++.
Qt metecall
Generica Qt metacall which enables user to call QObject's method with name and QVariantList packed arguments.
...
const QString& object;
const QString& method;
const QVariantList& args;
//get meta method from method name
QMetaMethod metaMethod;
Qx::metaCall(object, metaMethod, args);
Qt genericsignalmap
Generica Qt signal map which enables user to connect QObject's signal with name and QVariantList packed arguments.
GenericSignalMapper* mapper1 = new GenericSignalMapper(method, this);
connect(object, qFlagLocation(signature.toUtf8().constData()), mapper1, SLOT(mapSlot()));
connect(mapper1, SIGNAL(mapped(QObject*, QMetaMethod, QVariantList)), this, SLOT(onGenericSignal(QObject*, QMetaMethod, QVariantList)));
Related Skills
clearshot
Structured screenshot analysis for UI implementation and critique. Analyzes every UI screenshot with a 5×5 spatial grid, full element inventory, and design system extraction — facts and taste together, every time. Escalates to full implementation blueprint when building. Trigger on any digital interface image file (png, jpg, gif, webp — websites, apps, dashboards, mockups, wireframes) or commands like 'analyse this screenshot,' 'rebuild this,' 'match this design,' 'clone this.' Skip for non-UI images (photos, memes, charts) unless the user explicitly wants to build a UI from them. Does NOT trigger on HTML source code, CSS, SVGs, or any code pasted as text.
openpencil
2.1kThe world's first open-source AI-native vector design tool and the first to feature concurrent Agent Teams. Design-as-Code. Turn prompts into UI directly on the live canvas. A modern alternative to Pencil.
HappyColorBlend
HappyColorBlendVibe Project Guidelines Project Overview HappyColorBlendVibe is a Figma plugin for color palette generation with advanced tint/shade blending capabilities. It allows designers to
Flyaro-waffle-app
Waffle Delight - Full Stack MERN Application Rules & Documentation Project Overview A comprehensive waffle delivery application built with MERN stack featuring premium UI/UX, admin management, a
