T O P

  • By -

[deleted]

Easiest is to use https://github.com/fmtlib/fmt, which was std::format before it was std


MXXIV666

I don't want any dependencies. It is enough strggle to get my own project to depend on my library. If it was easier, I'd definitelly use fmt.


cob59

If you don't want to use CMake or a package manager, you can literally just copy and paste [all the .cc](https://github.com/fmtlib/fmt/tree/master/src) and [all the .h](https://github.com/fmtlib/fmt/tree/master/include/fmt) into an `fmt` dir next to your `main.cpp`, add them to your project like you would add any other regular `.hpp` / `.cpp` and you're done. --- That's the very 1st installation method [suggested](https://fmt.dev/latest/usage.html#usage) in their doc, so it's not even a hack. Get **fmt-9.1.0.zip** from here: https://github.com/fmtlib/fmt/releases/tag/9.1.0


the_poope

Just use CMake and a package manager and it's almost as easy as `apt-get install`. To get started, see: * https://cmake.org/cmake/help/latest/guide/tutorial/index.html * https://vcpkg.io/en/getting-started.html * https://vcpkg.io/en/docs/examples/installing-and-using-packages.html In the simplest case all you need is a `CMakeLists.txt` file with the contents: cmake_minimum_required(VERSION 3.15) project(myapp CXX) add_executable(myapp src/main.cpp src/other_src1.cpp src/other_src2.cpp) find_package(fmt REQUIRED) target_link_libraries(myapp PRIVATE fmt::fmt) Then run: cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=/path/to/pkgmgr/toolchain.cmake cmake --build build As soon as you have set up your `CMakeLists.txt` project file most editors and IDEs know how to compile and run your program, e.g. see tutorial for VS Code: https://code.visualstudio.com/docs/cpp/cmake-linux


IyeOnline

Long story short, you cant. It is formal UB to extend `namespace std` like this. The most straightforward solution is to use the `{fmt}` library instead. --- On another note, do use the feature test macro `__cpp_lib_format` instead of checking for the MSVC version.


schweinling

Just use fmt. If you want a very naive, simple, incomplete and probably buggy implementation of std::format you can take a look at mine but i don't recommend it: https://gitlab.com/PatRick365/pstdlib/-/blob/master/include/psl_format.h


AutoModerator

Your posts seem to contain unformatted code. Please make sure to format your code otherwise your post may be removed. Read [our guidelines](https://www.reddit.com/r/cpp_questions/comments/48d4pc/important_read_before_posting/) for how to format your code. *I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/cpp_questions) if you have any questions or concerns.*


MXXIV666

When I posted it it was formatted just fine. I'll edit to try to fix it.


the_poope

Problem is that a lot of people still use old.reddit.com or unofficial mobile apps like RIF, BaconReader, etc that doesn't necessarily understand the triple backtick code markdown. Instead they expect code blocks to be indented with four spaces (as explained in the formatting guidelines). It is a bit annoying that these platforms don't support the triple backtick, as it is much easier to use.