Skip to content

V0.7.4

Compare
Choose a tag to compare
@hsutter hsutter released this 27 Aug 20:20
· 49 commits to main since this release
2e23597

Highlights

Expanded compile-time support for is

Thanks to @filipsajdak for this PR! The built-in is implementation is now constexpr, and cases that are known statically now produce compile-time values.

Unified using syntax

I had been using the Cpp1 syntax since I had nothing substantially better. But that did leave the grammar divergence between the two forms:

// Cpp1 syntax, and previous Cpp2: Two different syntaxes/grammars
using std::vector;   // use one thing from std
using namespace std; // use everything in std

The historical reason for the two syntaxes is that the syntax using possibly::qualified::identifier; hid that identifier could be a function/type name or a namespace name, and it's good to have some visual distinction that we're pulling in all the declarations in a namespace.

But then I realized that this was another place we could apply the general Cpp2 _ "don't-care" wildcard, so that instead of using namespace NNN ; we now write using NNN::_ ; which is still visually explicit that we're pulling in all the declarations in a namespace but doesn't require a second special one-off syntax/grammar. Now things are more consistent:

// Now in Cpp2: One unified syntax using '_' wildcard
using std::vector; // use one thing from std
using std::_ ;     // use everything in std

Of course the latter still lowers to Cpp1 using namespace std;.

Style note: I find myself putting a space between _ ; to make it more visually pleasing, so it's possible we may discover that the syntax is too subtle if people frequently write it without the space and then miss the _. But it seems to be a nice unification to remove yet another grammar special case and still clearly express what's wanted using a generalization we already have in the _ wildcard... as Bjarne recommends, 'simplification through generalization.'

Support .sum and .contains for ..= and ..< ranges

Thanks to @brevzin for the suggestion! Examples:

std::cout << "  ((1 ..= 20).sum())$ \n"         // prints 210
             "  ((1 ..< 20).sum())$ \n"         // prints 190
             "  ((1 ..= 20).contains(0))$ \n"   // prints false
             "  ((1 ..= 20).contains(1))$ \n";  // prints true

Implementation detail: These were added as nonmembers, which is fine because UFCS finds them.

Enabled local function default arguments and cpp2::gcc_clang_msvc_min_versions()

This can be useful with 'if constexpr' to disable code known not to work on some otherwise-supported compilers (without macros). For example:

//  Disable tests on lower-level compilers that have blocking bugs:
//  GCC 14.00 or higher, Clang 16.00 or higher, MSVC 19.20 or higher
[]<auto V = gcc_clang_msvc_min_versions(1400, 1600, 1920)> () { if constexpr (V) {

    // ... tests that would fail due to older compilers' bugs ...

}}();

Enabled metafunctions to add runtime support headers

Thanks to @bluetarpmedia (Neil Henderson) and @MaxSagebaum for requesting this and providing an initial implementation to build on, respectively.

This was motivated by the @regex metafunction, which adds run-time support for actually executing the generated regex. It's provided via shared (header) code rather than by injecting a copy of the run-time support code into every translation unit that uses it, which makes sense because it's about 170K of code!

Previously, cpp2util.h (the run-time support library) included everything for all metafunctions, including for @regex. This had two problems: (1) Users paid for including/parsing it even if they never used that metafunction, which violates the "don't pay for it if you don't use it" zero-overhead principle. In this case, it roughly doubled the cost of compiling cpp2util.h for all cppfront users even if they didn't use @regex. (2) We eventually want to support users writing their own metafunctions, and this solution was hardwired into cppfront in-the-box metafunctions only.

With this change, a metafunction can say "ah, you ran me and so you're going to need the lowered Cpp1 file to include my run-time support code." For @regex that is now spelled:

t.add_runtime_support_include( "cpp2regex.h" );

Although as of yet metafunctions must be linked into cppfront, this approach isn't specific to cppfront and will extend better when we do support metafunctions that are written in user code.

Made the docs home page more discoverable

The home page used to go to the first page of the "Welcome" section. That was fine on desktop browsers because the left-hand navigation still showed the whole doc structure. However, on phones and tablets, users reported that this made the home page look like there was only a little "Welcome" information because the rest was hidden behind first having to know to click on the hamburger menu and then second additionally seeing the left-arrow and clicking on that to reveal more of the documentation.

This change makes the home page show the entire documentation so it's easily visible on all devices.

Special thanks to PRs from...

  • New contributor @jamadagni for docs typo fixes and improvements
  • @filipsajdak for further improving is and as, and fixing generation of is-constraints on wildcarded (generic) parameters
  • @MaxSagebaum for separating @regex metafunction and runtime code
  • @jarzec for ongoing CI improvements and updates

Full Changelog: v0.7.3...v0.7.4