boostorg / core

Boost Core Utilities
133 stars 83 forks source link

span does not support std::initializer_list #126

Closed HDembinski closed 1 year ago

HDembinski commented 2 years ago

https://godbolt.org/z/be94ra9G3

#include <span>
#include <boost/core/span.hpp>
#include <initializer_list>

int main() {
    auto x = {1, 2, 3};
    auto sp = std::span(x); // works
    auto sp2 = boost::span(x); // fails
}

In Boost Histogram, where I am trying to switch to boost/core/span.hpp now, I am seeing errors like this: error: no viable conversion from 'const std::initializer_list<X>' to 'span<const X>'. So it is fundamentally not an issue with the deduction guides.

The old span that I had implemented internally for histogram supported this.

HDembinski commented 2 years ago

I think the span is missing something like this: https://github.com/boostorg/histogram/blob/develop/include/boost/histogram/detail/nonmember_container_access.hpp

and a corresponding ctor like this:

https://github.com/boostorg/histogram/blob/develop/include/boost/histogram/detail/span.hpp#L139

HDembinski commented 1 year ago

@glenfe Any progress on this and #125? I would like to move Histogram over to this span and drop my internal implementation, but I cannot until at least std::initializer_list is supported. I can add make_span myself.

glenfe commented 1 year ago

Sorry for the delay @HDembinski. I'll finish both up this month, they'll be done for 1.82.0

HDembinski commented 1 year ago

Awesome, thanks!

glenfe commented 1 year ago

Should be implemented on develop. Let me know if there are any issues using it in Histogram.

HDembinski commented 1 year ago

Thanks! Will do.

glenfe commented 1 year ago

@HDembinski I've merged to master; I was waiting to see if you needed more functionality (e.g. support for std::valarray) but there's still time to get that in.

HDembinski commented 1 year ago

Works perfectly thanks.