Skip to content

<format>: Avoid dependency on <variant> #1826

@vitaut

Description

@vitaut

Describe the bug

The <format> header currently includes <varaint> which is a big dependency. However, std::variant itself is not used in the implementation, only std::monostate which is a trivial struct. Is it possible to move std::monostate to a common header to be used from <format> and <variant> to break the unnecessary dependency and potentially reduce compile times?

Command-line test case

C:\Temp>type test.cc
#include <format>

int main() {
  auto v = std::variant<int>();
}

C:\Temp>cl /I STL/stl/inc /std:c++latest test.cc
Microsoft (R) C/C++ Optimizing Compiler Version 19.29.29917 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

/std:c++latest is provided as a preview of language features from the latest C++
working draft, and we're eager to hear about bugs and suggestions for improvements.
However, note that these features are provided as-is without support, and subject
to changes or removal as the working draft evolves. See
https://go.microsoft.com/fwlink/?linkid=2045807 for details.

test.cc
Microsoft (R) Incremental Linker Version 14.29.29917.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:test.exe
test.obj

Expected behavior
The test shouldn't compile because <format> shoudn't provide std::variant.

STL version

4d7d4f1

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixedSomething works now, yay!formatC++20/23 formatthroughputMust compile faster

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions