based

Opinionated utility library
git clone git://git.dimitrijedobrota.com/based.git
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING

commit de0eccb93776d7f47e26fdb03b589a23e80b439e
parent e71e73f6b35a2b46e81b641c238f613335600661
author Dimitrije Dobrota < mail@dimitrijedobrota.com >
date Sat, 14 Jun 2025 18:17:33 +0200

to_string quick implementation

Diffstat:
A include/based/string/to_string.hpp | +++++++++++++++++++++++++

1 files changed, 25 insertions(+), 0 deletions(-)


diff --git a/ include/based/string/to_string.hpp b/ include/based/string/to_string.hpp

@@ -0,0 +1,25 @@

#pragma once

#include <algorithm>
#include <string>

namespace based
{

template<class T>
// requires unsigned integral types
constexpr std::string to_string(T value)
{
constexpr const T radix = 10;
std::string res;

do {
res.push_back('0' + (value % radix));
} while ((value /= radix) > 0);

std::ranges::reverse(res);

return res;
}

} // namespace based