{"id":27867630,"url":"https://github.com/eteran/cxx11_printf","last_synced_at":"2026-03-11T01:02:24.641Z","repository":{"id":145240901,"uuid":"68887181","full_name":"eteran/cxx11_printf","owner":"eteran","description":"An implementation of printf using c++11's variadic templates","archived":false,"fork":false,"pushed_at":"2019-03-25T20:23:30.000Z","size":30,"stargazers_count":13,"open_issues_count":0,"forks_count":2,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-05-04T22:53:41.503Z","etag":null,"topics":["c-plus-plus","c-plus-plus-11","templates"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eteran.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-09-22T05:17:38.000Z","updated_at":"2024-10-14T13:10:30.000Z","dependencies_parsed_at":null,"dependency_job_id":"adacad36-947b-4007-b1f5-f3fbdf0bc9e5","html_url":"https://github.com/eteran/cxx11_printf","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/eteran/cxx11_printf","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eteran%2Fcxx11_printf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eteran%2Fcxx11_printf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eteran%2Fcxx11_printf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eteran%2Fcxx11_printf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eteran","download_url":"https://codeload.github.com/eteran/cxx11_printf/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eteran%2Fcxx11_printf/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30364610,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-10T21:41:54.280Z","status":"ssl_error","status_checked_at":"2026-03-10T21:40:59.357Z","response_time":106,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-plus-plus","c-plus-plus-11","templates"],"created_at":"2025-05-04T22:51:20.986Z","updated_at":"2026-03-11T01:02:24.590Z","avatar_url":"https://github.com/eteran.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cxx11_printf\n\nAn implementation of `printf` using c++11's variadic templates. It was inspired \nby some of the \"safe printf\" examples that I've seen. But none of them attempted\nto actually implement the `printf` fully with all of its quirks. This code is \n(an attempt) to do that.\n\nAn advantage of this, is that we can support ANY type being passed to a format, \neven complex objects. For example, when `CXX11_PRINTF_EXTENSIONS` is enabled\n`\"%?\"` means \"call `to_string` on the argument and print the result\" This uses\nADL, so it will find the version that you specify in your namespaces, or use \n`std::to_string` as a fallback. If no `to_string` is found, it uses the internal\none which asserts.\n\nNOTE: floating point is not implemented, as it is complex to do correctly, but \n      is on the TODO list.\n\t  \nUsage is similar to `snprintf`, but more robust. Instead of a buffer/size pair\nbeing passed as a parameter, you pass a context object which has two functions\nand a data member:\n\n\t// writes a single character to the output of your choosing\n\tvoid write(char ch);\n\t\n\t// writes a string of characters to the output of your choosing\n\tvoid write(const char *p, size_t n);\n\t\n\t// called when formatting is complete, useful for ensuring NUL termination\n\tvoid done();\n\t\n\t// increment this every time we write is called, this is what printf will\n\t// return.\n\tsize_t written = 0;\n\t\n\t\nA simple example of the usage of the library is as follows:\n\n\tchar buf[256];\n\tcxx11::buffer_writer ctx(buf, sizeof(buf));\n\tcxx11::Printf(ctx, \"[hello %*s %d]\", 10, \"world\", 123);\n\t\n\t// buffer now contains \"[hello      world 123]\"\n\t\nThe context uses duck typing, so any object that meets the critera will suffice,\nbut there are several examples in Formatters.h\n\n--------\n\nAdditionally, while the context based interface is very flexible and can \naccomidate essentially any destination stream or buffer. This implementation\nalso includes more familiar interfaces:\n\n* `int cxx11::sprintf(std::ostream \u0026os, const char *format, const Ts \u0026... ts);`\n* `int cxx11::sprintf(char *str, size_t size, const char *format, const Ts \u0026... ts);`\n* `int cxx11::printf(const char *format, const Ts \u0026... ts);`\n\nAll of which work in the expected ways without the need to manually manage the \nconcept of \"contexts\".\n\n\n--------\n\nPerformance so far, when optimizations are at -O3 is comparable to glibc's \nprintf. Here is the included test program's output on my machine:\n\n\thello      world, A, -123, 00001234 0x7ffe75bd6ff8 0000004294967292 ffffffff 0000000000002322\n\thello      world, A, -123, 00001234 0x7ffe75bd6ff8 0000004294967292 ffffffff 0000000000002322\n\tFirst Took:  383955 �s to execute.\n\tSecond Took: 382404 �s to execute.\n\nI am sure however, that there is room for some optimizations too :-)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feteran%2Fcxx11_printf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feteran%2Fcxx11_printf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feteran%2Fcxx11_printf/lists"}