Currently, std::span has a very specific set of converting constructors. If one has a UDT that doesn't conform to the requirements of those constructors, then one must use the pointer + length constructor, possibly by creating some custom make_span() or similar function. I propose the following converting constructor instead:
template <class T>
span(T & _value)
: span(span_traits<T>::data(_value), span_traits<T>::size(_value))
{
}
The default for span_traits can be:
template <class T>
struct span_traits
{
static T *
data(T & _value) { return _value.data(); }
static ptrdiff_t
size(T & _value) { return _value.size(); }
};
That default will work with Standard Library containers and other types that follow that pattern.
Then, if users are permitted to specialize span_traits, other types can be adapted readily, and some of the current constructor overloads could be replaced with specializations of span_traits.
There might be reason to split span_traits into two function templates, but that's a minor detail relative to the idea of adding a customization point to adapt it to other UDTs.
_____
Rob Stewart
robert....@sig.com
Senior Software Engineer, Middleware using std::disclaimer;
Susquehanna International Group, LLP
http://www.sig.com
________________________________
IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.