Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing of various C++20 features #1207

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open

Testing of various C++20 features #1207

wants to merge 19 commits into from

Conversation

robertlipe
Copy link
Collaborator

A little bit of everything just to see how well C++20 is supported. This is just
a few commits for each major feature. If there's anything useful in this PR, I expect
to have to pick it apart and cherry pick as I can't imagine this whole PR going in as
one.

See related discussion on #1204.

  • Templatize FahrenheitToCelsius and inverse.
  • Toe dip for C++-20: use host endianness.
  • unicsv.cc
  • Babys's first concept.
  • Use enum class and C++20 'using' directive in xcsv.
  • use using enum in units to reduce chatter
  • DANGER: wreckless use of std::format for testing

GPSBabelDeveloper and others added 13 commits January 30, 2021 15:58
Now they DTRT without excessive promotion for ints, doubles, floats, etc...
Barely an improvement and still falls back to Qt if we don't have <bit>,
but this is just a proving ground.
The errors actually ARE easier to read. Sure, it's a lot of words in
this training-wheels case.

gpsbabel/garmin_txt.cc:974:22: error: no matching function for call to 'FahrenheitToCelsius'
      *temperature = FahrenheitToCelsius("booger");
                     ^~~~~~~~~~~~~~~~~~~
gpsbabel/defs.h:92:3: note: candidate template ignored: constraints not satisfied [with T = const char *]
T FahrenheitToCelsius(T a) { return (a - 32.0) / 1.8;}
  ^
gpsbabel/defs.h:91:10: note: because 'const char *' does not satisfy 'integral'
requires std::integral<T> || std::floating_point<T>
         ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/__concepts/arithmetic.h:30:20: note: because 'is_integral_v<const char *>' evaluated to false
concept integral = is_integral_v<_Tp>;
                   ^
gpsbabel/defs.h:91:30: note: and 'const char *' does not satisfy 'floating_point'
requires std::integral<T> || std::floating_point<T>
                             ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/__concepts/arithmetic.h:39:26: note: because 'is_floating_point_v<const char *>' evaluated to false
concept floating_point = is_floating_point_v<_Tp>;
Better type safety from enum class. Less annoying repetition via using.
@robertlipe robertlipe mentioned this pull request Nov 2, 2023
fmt.h Outdated
} ;

// It's present everywhere else, right?
#elif __has_include(<format.h>)
Copy link
Collaborator

@tsteven4 tsteven4 Nov 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The standard header is <format>, not <format.h>.
https://en.cppreference.com/w/cpp/header/format

@tsteven4
Copy link
Collaborator

tsteven4 commented Nov 3, 2023

You had a bad merge on xcsv.cc. I think this is what you meant:
xcsv.zip


// Fallback to the system version.
#elif __has_include(<format>)
# include <format.h>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, the system version is<format>

@tsteven4
Copy link
Collaborator

tsteven4 commented Nov 3, 2023

With the xcsv.cc I attached above, and actually including <format> after testing for it, on visual studio I get down to 7 errors, all in the MS supplied format include.

Severity	Code	Description	Project	File	Line	Suppression State
Error	C2338	static_assert failed: 'Cannot format an argument. To make type T formattable, provide a formatter<T> specialization. See N4928 [format.arg.store]/2 and [formatter.requirements].'	C:\Users\tstev\Source\Repos\upstream\out\build\x64-Debug\upstream	C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\include\format	3648	
Error	C2665	'std::_Format_arg_traits<_Context>::_Phony_basic_format_arg_constructor': no overloaded function could convert all the argument types	C:\Users\tstev\Source\Repos\upstream\out\build\x64-Debug\upstream	C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\include\format	1873	
Error	C2993	'unknown-type': is not a valid type for non-type template parameter '_Test'	C:\Users\tstev\Source\Repos\upstream\out\build\x64-Debug\upstream	C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\include\format	3430	
Error	C2641	cannot deduce template arguments for 'std::formatter'	C:\Users\tstev\Source\Repos\upstream\out\build\x64-Debug\upstream	C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\include\format	3432	
Error	C2783	'std::formatter<_Ty,_CharT> std::formatter(void)': could not deduce template argument for '_Ty'	C:\Users\tstev\Source\Repos\upstream\out\build\x64-Debug\upstream	C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\include\format	3432	
Error	C2780	'std::formatter<_Ty,_CharT> std::formatter(std::formatter<_Ty,_CharT>)': expects 1 arguments - 0 provided	C:\Users\tstev\Source\Repos\upstream\out\build\x64-Debug\upstream	C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\include\format	3432	
Error	C2039	'parse': is not a member of 'std::formatter'	C:\Users\tstev\Source\Repos\upstream\out\build\x64-Debug\upstream	C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\include\format	3433	

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants