{"id":27057721,"url":"https://github.com/mrange/tsprintf","last_synced_at":"2025-04-05T11:32:59.610Z","repository":{"id":149117087,"uuid":"43735754","full_name":"mrange/tsprintf","owner":"mrange","description":"tsprintf is a portable type-safe printf library with no runtime cost over printf","archived":false,"fork":false,"pushed_at":"2015-10-18T13:50:46.000Z","size":216,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T02:09:05.726Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mrange.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}},"created_at":"2015-10-06T07:21:26.000Z","updated_at":"2024-11-05T12:55:14.000Z","dependencies_parsed_at":"2023-04-10T11:46:39.777Z","dependency_job_id":null,"html_url":"https://github.com/mrange/tsprintf","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrange%2Ftsprintf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrange%2Ftsprintf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrange%2Ftsprintf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrange%2Ftsprintf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrange","download_url":"https://codeload.github.com/mrange/tsprintf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247331773,"owners_count":20921844,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2025-04-05T11:32:51.894Z","updated_at":"2025-04-05T11:32:59.596Z","avatar_url":"https://github.com/mrange.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"tsprintf\n========\n\ntsprintf is library that brings type-safety to printf\n\nprintf (and its variants) has many strengths (even in the day of C++11)\n\n1. Often outperforms C++ streams\n2. No dynamic allocation of memory\n3. In some case more readable than C++ streams (in the eye of the beholder)\n4. C++ streams can cause code-bloat\n\nOne of the major short-comings of printf is that there's no type-safety meaning\nthis will compile and most likely crash when executing:\n```c++\n  printf (\n      \"This is so wrong: %s\"\n    , 314\n    );\n```\n\nAn easy and catastrophic mistake to make.\n\nNow, many compilers (VC, g++, clang++) checks that the format string and the\nargument types matches. In addition we have tools like LINT. What is the need of\ntype-safe printf?\n\n1. You might have other printf like functions. The compilers tend to ignore\n   those as it doesn't know the semantics of your functions.\n2. It's interesting to see how much checks can be performed in compile-time in\n   C++14\n\nThe following code compiles as expected:\n```c++\n  TS_PRINTF (\"Hello\\n\");\n  TS_PRINTF (\"Hello %s,%lld\\n\", \"World\", 3LL);\n```\n\nHowever the following illegal code fails to compile as the format string\ndoesn't match the argument types.\n```c++\n  TS_PRINTF (\n      \"Due to type mismatch compilation stops here... %d\\n\"\n    , \"Because this is not an int\"\n    );\n```\n\nIn VS2015 the error looks like this:\n```\n\t1\u003ec:\\temp\\github\\tsprintf\\src\\test_suite\\../tsprintf/tsprintf.hpp(316): error C2338: Type mismatch between format string and provided argument\n\t1\u003e  c:\\temp\\github\\tsprintf\\src\\test_suite\\../tsprintf/tsprintf.hpp(357): note: see reference to class template instantiation 'typesafe_printf::details::error_reporter\u003c0,const char *,int\u003e' being compiled\n```\n\nerror_reporter\u003c0,const char *,int\u003e is interpreted like this: For argument 0 the\nargument type was const char * but was expected to be int (because of %d in the\nformat string).\n\nclang/g++ gives a similar error report.\n\nTODO\n----\n\n2. Improve test suite\n4. Performance tests (to make sure compilation times doesn't fall through the floor)\n5. Find a way to replace TS_PRINTF macro with a template method\n\nDONE:\n----\n\n1. Implement TS_SPRINTF and all other variants\n3. Make it compile in clang++\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrange%2Ftsprintf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrange%2Ftsprintf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrange%2Ftsprintf/lists"}