Skip to content

Support both generic and native format of std::filesystem::path #3715

Closed
@zhihaoy

Description

@zhihaoy

Why

Need a way to include the paths with only slashes rather than backslashes in the output in a cross-platform manner. This can be done by introducing type in format-spec for path.

How to use the proposed feature

On Windows,

std::filesystem::path filename = R"(C:\Users\zhihaoy\.cache)";
print("|{}|", filename);  // prints |C:\Users\zhihaoy\.cache|
print("|{:n}|", filename);  // prints `.native()` |C:\Users\zhihaoy\.cache|
print("|{:g}|", filename);  // prints `.generic_wstring()` |C:/Users/zhihaoy/.cache|

On POSIX, the last line prints .generic_string().

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions