Skip to content

Commit

Permalink
Allow _ as "don't care" shorthand for the Default contract group
Browse files Browse the repository at this point in the history
Since now we might want to write flags afterwards, e.g., `<Group, flag1, flag2>`, programmers who want the default group `<Default, flag1, flag2>` might expect to be able to equivalently write `<_, flag1, flag2>`, so let's make that work

Until now, programmers would just omit `<Default>` and that continues the work as the basic default, as before
  • Loading branch information
hsutter committed Dec 17, 2023
1 parent c119d32 commit 479a345
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion source/to_cpp1.h
Original file line number Diff line number Diff line change
Expand Up @@ -4536,7 +4536,10 @@ class cppfront
auto name = std::string{"cpp2::Default"};
if (n.group)
{
name = print_to_string(*n.group);
auto group = print_to_string(*n.group);
if (group != "_") {
name = group;
}
if (
name == "Default"
|| name == "Bounds"
Expand Down

1 comment on commit 479a345

@JohelEGP
Copy link
Contributor

Choose a reason for hiding this comment

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

This special use of _, in assert<_>(true);, bothers me due to an inconsistency.

Any extra arguments are actually normal parameters, which is actually the purpose of this _ in the first place.
The inconsistency is evident after commit 94bea67 (which #927 seeks to generalize).
That would make assert<()>(true); be a more consistent spelling of the feature
if the contract keywords are specified as
contract-keyword: <contract_group: type = default, _...: type> = /*...*/.
That is, the first "template" argument to a contract keyword is defaulted to default.

Note that CWG2450 has already made std::map<int, {}> be valid C++.
I'm not suggesting to generalize this use of _, as #927 provides a better direction for generalization.

Please sign in to comment.