Document number |
P3266R0 |
Date |
2024-05-05 |
Reply-to |
Jarrad J. Waterloo <descender76 at gmail dot com>
|
Audience |
Evolution Working Group (EWG) |
non referenceable types
Table of contents
Abstract
Consumers of pure reference types with shallow const
semantics would benefit by disallowing taking a reference to the type.
Motivational Examples
given
template<class... S> class function_ref;
template<class R, class... ArgTypes>
class function_ref<R(ArgTypes...) cv noexcept(noex)> referenceable(false)
{
};
template <class T>
class optional<T&> referenceable(false)
{
};
usage
function_ref<void ()>& f(function_ref<void ()>&);
optional<int&>& f(optional<int&>&);
void action(){}
int main()
{
function_ref<void ()> fr1{ action };
function_ref<void ()>& fr2 = fr1;
int i = 42;
optional<int&> oi1{ i };
optional<int&>& oi2 = oi1;
return 0;
}
Motivation
Currently a programmer can not create a reference to a reference as references only support a single level of indirection. Further, taking the address of a reference does not refer to the address of the reference but rather what the referent that the reference refers to. Allowing programmers to create non referenceable types would mean allowing programmers to create reference types that are more consistent with references. This would remove incorrect usage of reference types and prevent that creation of references which are largely useless and only serve to provide additional avenues to dangling.
More Potential Examples
class a referenceable(false){};
class b referenceable(true){};
In terms of this proposal, the current default of the language is referenceable(true)
.
Jarrad J. Waterloo <descender76 at gmail dot com>
non referenceable types
Table of contents
Abstract
Consumers of pure reference types with shallow
const
semantics would benefit by disallowing taking a reference to the type.Motivational Examples
given
usage
Motivation
Currently a programmer can not create a reference to a reference as references only support a single level of indirection. Further, taking the address of a reference does not refer to the address of the reference but rather what the referent that the reference refers to. Allowing programmers to create non referenceable types would mean allowing programmers to create reference types that are more consistent with references. This would remove incorrect usage of reference types and prevent that creation of references which are largely useless and only serve to provide additional avenues to dangling.
More Potential Examples
In terms of this proposal, the current default of the language is
referenceable(true)
.