Skip to content

Instantly share code, notes, and snippets.

View voidbar's full-sized avatar

Tomer Lev voidbar

View GitHub Profile
@voidbar
voidbar / windows_short_to_long_path.cpp
Last active August 25, 2022 20:31
Using std::filesystem trick to convert windows short path into long path
#include <filesystem>
#include <iostream>
#include <format> // C++20 Required
namespace fs = std::filesystem;
std::string to_long_path(const std::string& short_path) {
return fs::canonical(short_path).string();
}
@voidbar
voidbar / to_string_generic_c++17.cpp
Last active January 30, 2022 08:42
Number to string function using constexpr lamba with auto deductible parameters
#include <charconv>
#include <iostream>
#include <array>
constexpr auto ToString = [](auto number) constexpr -> const std::string {
std::array<char, 20 /* Max chars in 64 bit number*/> buffer;
if (auto [ptr, ec] = std::to_chars(buffer.data(), buffer.data() + buffer.size(), number); ec == std::errc())
{
return std::string{buffer.data(), static_cast<size_t>(ptr - buffer.data())};
}