Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

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

Open
#153 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
Half a day
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp
Domain
tooling

Research direction

No source file or test is named. Start by locating boost::span's constructor overloads and the existing span test coverage, then check the issue's direct-list-initialization example. Done means the example compiles and equivalent coverage confirms the intended initializer-list behavior without regressing existing range construction.

Written by the indexing model from the issue text.

Description

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.

Dominant language
C++
Stars
156
Forks
116
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from boostorg/core

All issues in boostorg/core

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.