You are not logged in.

#1 2022-07-05 06:27:18

interrupt
Member
Registered: 2018-04-08
Posts: 6

[SOLVED] C++20 - including the format header that ships with llvm14?

I'm a newbie to C++, but I'd like to use the new <format> header from C++20.

The documentation says it's now supported since clang14.

So installed clang, llvm, llvm-libs, libc++ and libc++abi.

And I tried:

#include <iostream>
#include <format>

using namespace std;

int main(void)
{
	vector<double> v {1.23, 45.42, 0.441, 1342.8, 61.5, 32.1};

	for (const auto & n : v)
		cout << format("{:>7}\n", n);
	
	return EXIT_SUCCESS;
}

Alas it says:

$ clang++ -Wall -std=c++2a -o main main.cpp 
main.cpp:2:10: fatal error: 'format' file not found
#include <format>
         ^~~~~~~~
1 error generated.

What am I missing here?

Last edited by interrupt (2022-07-05 08:38:28)

Offline

#2 2022-07-05 08:21:17

foutrelis
Developer
From: Athens, Greece
Registered: 2008-07-28
Posts: 703
Website

Re: [SOLVED] C++20 - including the format header that ships with llvm14?

You would have to pass "-stdlib=libc++" to clang++ otherwise it uses GCC's libstdc++ and not LLVM's libc++. You'd also need to rebuild libc++ with "-DLIBCXX_ENABLE_INCOMPLETE_FEATURES=ON" (for an explanation see: https://stackoverflow.com/a/71778011).

Offline

#3 2022-07-05 08:35:48

interrupt
Member
Registered: 2018-04-08
Posts: 6

Re: [SOLVED] C++20 - including the format header that ships with llvm14?

Okay, I see - thanks for the info.
Guess it's safer to still use fmt instead until the implementation is complete.

Offline

Board footer

Powered by FluxBB