Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boost::span cannot be implicitly constructed from std::initializer_list indirectly [feature-request] #153

Open
hadrielk opened this issue Jul 23, 2023 · 0 comments

Comments

@hadrielk
Copy link

NOTE: This isn't something std::span in C++20 supports either, unfortunately. But since Boost tries to offer things a future standard might adopt, I think this fits?

Because boost::span has no constructor signature with a direct std::initializer_list argument, but only a templated "range" one, this works:

std::initializer_list<int> il{1,2,3,4};
boost::span<int> sp(il);

but this does not, because it requires two implicit conversions to occur:

boost::span<int> sp({1,2,3,4});

I believe the above would work if this were to be added:

    constexpr span(std::initializer_list<T> il) noexcept
        : s_(boost::data(il), il.size())
    {}

I can provide a PR, if you wish.

I recognize this can lead to lifetime issues for the backing array, but that's already true for span regardless.

There is a std proposal for this, I believe: p2447r2, but I don't know its disposition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant