{"id":50750135,"url":"https://github.com/tcsullivan/constexpr-to-string","last_synced_at":"2026-06-11T00:32:01.930Z","repository":{"id":62382400,"uuid":"275179355","full_name":"tcsullivan/constexpr-to-string","owner":"tcsullivan","description":"C++14 code to convert integers to strings at compile-time","archived":false,"fork":false,"pushed_at":"2024-12-30T13:11:53.000Z","size":50,"stargazers_count":116,"open_issues_count":0,"forks_count":13,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-12-30T14:22:04.170Z","etag":null,"topics":["constexpr","cpp"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tcsullivan.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}},"created_at":"2020-06-26T14:47:35.000Z","updated_at":"2024-12-30T13:11:57.000Z","dependencies_parsed_at":"2024-12-31T15:00:47.373Z","dependency_job_id":null,"html_url":"https://github.com/tcsullivan/constexpr-to-string","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tcsullivan/constexpr-to-string","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tcsullivan%2Fconstexpr-to-string","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tcsullivan%2Fconstexpr-to-string/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tcsullivan%2Fconstexpr-to-string/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tcsullivan%2Fconstexpr-to-string/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tcsullivan","download_url":"https://codeload.github.com/tcsullivan/constexpr-to-string/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tcsullivan%2Fconstexpr-to-string/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34177445,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-10T02:00:07.152Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["constexpr","cpp"],"created_at":"2026-06-11T00:32:01.295Z","updated_at":"2026-06-11T00:32:01.921Z","avatar_url":"https://github.com/tcsullivan.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# constexpr-to-string\n\nRequires C++14 or later.\n\n**Features:**\n\n* Convert any integral type to a string at compile-time\n* Supports converting to bases 2 through 36\n* No external dependencies\n* Supports custom character types, e.g. `to_string\u003c123, 10, wchar_t\u003e`\n* C++20: Supports floating-point-to-string conversion with `f_to_string`\n\n**How to use:**\n\nThe file `to_string.hpp` provides a `to_string` utility, which may be used as below:\n\n```cpp\nconst char *number = to_string\u003c2147483648999954564, 16\u003e; // produces \"1DCD65003B9A1884\"\nputs(number);\nputs(to_string\u003c-42\u003e); // produces \"-42\"\nputs(to_string\u003c30, 2\u003e); // produces \"11110\"\n```\n\nWith `to_string`, all that will be found in program disassembly are the resulting string literals, as if you wrote the strings yourself.\n\nTry it [on Compiler Explorer](https://godbolt.org/z/T-MFoh).\n\n`f_to_string.hpp`, requiring C++20, provides an `f_to_string` utility for floating-point conversion:\n\n```cpp\nputs(f_to_string\u003c3.1415926\u003e); // Defaults to 5-point precision: \"3.14159\"\nputs(f_to_string\u003c{3.1415926, 7}\u003e); // Specify precision: \"3.1415926\"\n```\n\n# How it works\n\nC++14 greatly expanded the capabilities of compile-time code execution through `constexpr`. In particular, it allows for non-trivial constructors to be `constexpr`.\n\n`to_string` takes advantage of this by providing an object that converts a template-parameter integer to a string using a basic `itoa` implementation in the constructor. Through an additional `constexpr` member function, we can calculate the length of the resulting string; this can be used to size the object's string buffer for a perfect fit.\n\nBeyond this, `to_string` simply provides familiar member functions that allow for iteration and data access. The expansion of the capabilities of `auto` in C++14 help make these definitions concise.\n\nThe floating-point implementation `f_to_string` takes a similar approach, but requires C++20 as it needs a `double_wrapper` object to capture the `double` value. `double` and `float` cannot directly be template parameters as of C++20, and a non-type template parameter like the `double_wrapper` structure was not allowed before C++20.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftcsullivan%2Fconstexpr-to-string","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftcsullivan%2Fconstexpr-to-string","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftcsullivan%2Fconstexpr-to-string/lists"}