/* Heap-allocation free & small memory footprint * std::function alternative with limited capabilities. */ // example /* Copyright (c) 2026 dyknon * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the " Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom * the Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice * (including the next paragraph) shall be included in all copies * or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #include "thinfunc.h" #include #include #include using namespace tf; struct test{ std::string name; test(std::string name): name(name){ m1.bind<&test::m1, &test::message1>(); m2.bind<&test::m2, &test::message2>(); t.bind<&test::t, &test::time>(); } anchor m1; anchor m2; anchor t; void message1(){ std::println("hello! I'm {}.", name); } void message2(std::string time){ std::println("Good {}! I'm {}.", time, name); } std::string time(){ auto t = std::time(nullptr); t /= 60 * 60; t %= 24; if(t < 5){ return "night"; }else if(t < 12){ return "morning"; }else if(t < 18){ return "afternoon"; }else if(t < 20){ return "evening"; }else{ return "night"; } } }; int main(){ test o("a test object"); func& m1 = o.m1.bound(); func& m2 = o.m2.bound(); func& t = o.t.bound<&test::t, &test::time>(); m1(); m2(t()); return 0; }