C++ Logo


Advanced search

[std-proposals] Proposal (Floating Idea): Make prefix for members of standard structs that will never be used

From: Noah Goldstein <goldstein.w.n_at_[hidden]>
Date: Mon, 3 Apr 2023 15:35:02 -0500
Hi All,

The idea is to reserve a prefix that will never be used for any member
in standard structs/classes.

For example if the prefix 'nostd_' is chosen, then the standard is
agreeing to never make a member that matches 'nostd_*'.

The rationale is it is sometimes desirable to use custom fields in
template parameters to support querying for custom features.

For example martinus' quite popular unordered_map implementation [1]
gives users the ability to tune a performance attribute by adding an
'is_avalanche' flag to the hash struct [2].
class hash_unknown_quality {
}; // The implementation will do extra work to improve the output hash.

class hash_high_quality {
using is_avalanching = void;
}; // The implementation will assume the output hash is already good.

Current Issue:
Under the SD-8 guidelines[3] there is no field in standard structs
that can be safely assumed to never be used. This can undo any tuning
value gained by custom fields and makes it impossible to safely use
custom fields to control correctness related characteristics.

For example 'std::hash' may create a field 'is_avalanching' and
attach a completely different meaning to it, ultimately undoing the
value of check in martinus' unordered_map.

Benefit of this Proposal:
Under this proposal, all custom fields could be prefixed with the
chosen prefix. This would make these custom fields more reliably
usable for tuning purposes and safely usable for correctness purposes.
As well, it may prevent future blockers when trying to upgrade
standard versions as all custom field checks using the prefix can be
safely upgraded.

For example if 'is_avalanching' was replaced with
'nostd_is_avalanching' there would never be the issue of `std::hash`
creating the field 'nostd_is_avalanching'.

[1]: https://github.com/martinus/unordered_dense
[2]: https://github.com/martinus/unordered_dense#3-extensions
[3]: https://isocpp.org/std/standing-documents/sd-8-standard-library-compatibility

Received on 2023-04-03 20:35:15