C importing <format>

I'm working at re-acquainting myself with c++ and I'm working on the 2020 standard and I'm using FreeBSD 13.1. When compiling my code I am using these options: clang++ -Wall -pedantic-errors -pedantic -std=c++2a -fmodules.

I am running into an issue where I import <formatting> but when I try to use the format() function, I am getting an error that states "error: use of undeclared identifier 'format'".

I'm confused by the error ...from what I've found so far, it seems like there shouldn't be an issue. Am I missing something?
 
Code:
import <iostream>;
import <numbers>;
import <iomanip>;   // for setprecision() function
import <format>;    // for format() function
#include <cmath>

using namespace std;

int main() {
  const double fish_factor { 2.0 / 0.5};
  const double cm_per_meter { 100 };

  double fish_count = {};
  double fish_length = {};

  cout << "\nEnter the number of fish you want to keep: ";
  cin >> fish_count;

  cout << "Enter the average fish length in centimeters: ";
  cin >> fish_length;
  fish_length /= cm_per_meter;  // Convert to meters
  cout << endl;

  const double pond_area {fish_count * fish_length * fish_factor};
  const double pond_diameter {2.0* sqrt(pond_area / M_PI)};

  cout << "Pond diameter required for " << fish_count << " fish is " << pond_diameter
    << " meters.\n";

  cout << "Pond diameter required for " << fish_count << " fish is " << setprecision(3) << pond_diameter
    << " meters.\n";

  cout << format("Pond diameter required for {} fish is {} meters.\n\n", fish_count, pond_diameter);

  return 0;
}

It's the last cout statement before the end of the program that is giving me the issue.
 
And if you replace
Code:
 import <format>;
with
Code:
#include <format>
then everything works, right?
 
While I'm definitely not a right person to talk about c++ have a look at this.
I'm assuming that std::format is still the same as the module you're talking about. The concept of these modules is new to me but I thought it's worth sharing.
 
  • Thanks
Reactions: _al
Same caveat as _martin

I'm working at re-acquainting myself with c++ and I'm working on the 2020 standard and I'm using FreeBSD 13.1. When compiling my code I am using these options: clang++ -Wall -pedantic-errors -pedantic -std=c++2a -fmodules.
[...]

From the first table at C++ Support in Clang:
Code:
Language Standard     Flag          Available in Clang?
[...]
C++20                 -std=c++20    Partial
and at C++20 implementation status:
Clang has support for some of the features of the ISO C++ 2020 standard.

You can use Clang in C++20 mode with the -std=c++20 option (use -std=c++2a in Clang 9 and earlier).
(my emphasis)

These two quotes suggest to me that the appropriate compiler flag to use would be -std=c++20 *
C++20 Text Formatting: An Introduction might be helpful.

___
* and not -std=c++2a. As FreeBSD 13.0-RELEASE Release Notes - Contributed Software states:
The clang, lld, and lldb utilities and compiler-rt, llvm, libunwind, and libc++ libraries have been updated to version 11.0.1. 39b7445e15cd
I conclude that your (FreeBSD 13.1) Clang version is >9
 
I was curious about the import <module>; as I've never seen it before (but again, I don't like cpp much). I tried llvm15-15.0.1 and even std standard 2b and it didn't work.
 
While I'm definitely not a right person to talk about c++ have a look at this.
I'm assuming that std::format is still the same as the module you're talking about. The concept of these modules is new to me but I thought it's worth sharing.
std::format is the same ... the line I have that says "using namespace std;" removes the need to have std:: in front of it
 
Same caveat as _martin



From the first table at C++ Support in Clang:
Code:
Language Standard     Flag          Available in Clang?
[...]
C++20                 -std=c++20    Partial
and at C++20 implementation status:

(my emphasis)

These two quotes suggest to me that the appropriate compiler flag to use would be -std=c++20 *
C++20 Text Formatting: An Introduction might be helpful.

___
* and not -std=c++2a. As FreeBSD 13.0-RELEASE Release Notes - Contributed Software states:

I conclude that your (FreeBSD 13.1) Clang version is >9
I'll definitely try that ... I was using what the man page reccomended
 
std::format is the same ... the line I have that says "using namespace std;" removes the need to have std:: in front of it
That was my assumption. This is where (and in many other places) my knowledge of cpp lacks: I stated that because I'm not sure how modules affect this, can they introduce their own namespace or if that format can be part of a global namespace. If so then probably it's still in TODO.
 
As for LIBCXX_ENABLE_INCOMPLETE_FEATURES

I found this (maybe this will help):
- for 13.x.x: https://releases.llvm.org/13.0.0/projects/libcxx/docs/ReleaseNotes.html
- for the next release (14.x.x): https://reviews.llvm.org/D118901
and look into /usr/include/c++/v1/format

Edit: using _martin's link, I also found this one - https://en.cppreference.com/w/cpp/compiler_support#C.2B.2B20_library_features
Here we are looking for 'Text formatting' in the table 'C++20 library features'.

Edit2: https://libcxx.llvm.org/Status/Cxx20.html#note-p0645
Search for 'P0645R10' (and footnote '[3]' there)
 
Same caveat as _martin



From the first table at C++ Support in Clang:
Code:
Language Standard     Flag          Available in Clang?
[...]
C++20                 -std=c++20    Partial
and at C++20 implementation status:

(my emphasis)

These two quotes suggest to me that the appropriate compiler flag to use would be -std=c++20 *
C++20 Text Formatting: An Introduction might be helpful.

___
* and not -std=c++2a. As FreeBSD 13.0-RELEASE Release Notes - Contributed Software states:

I conclude that your (FreeBSD 13.1) Clang version is >9
using the update flag (-std=c++20) didn't make any difference in the issue I'm having
 
Back
Top