Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions include/boost/core/span.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,17 @@ class span;

namespace detail {

template<class U, class T, class = void>
struct span_convertible
{
static constexpr bool value = false;
};

template<class U, class T>
struct span_convertible {
static constexpr bool value = std::is_convertible<U(*)[], T(*)[]>::value;
struct span_convertible<U, T, typename std::enable_if<
std::is_convertible<U(*)[], T(*)[]>::value>::type>
{
static constexpr bool value = true;
};

template<std::size_t E, std::size_t N>
Expand Down
18 changes: 18 additions & 0 deletions test/span_constructible_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ struct range {
}
};

struct buffer {
void* data() {
return 0;
}

const void* data() const {
return 0;
}

std::size_t size() const {
return 0;
}
};

struct base { };

struct derived
Expand Down Expand Up @@ -138,6 +152,10 @@ void test_range()
const range<int>&>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<base>,
range<derived>&>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int>,
buffer>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int>,
const buffer&>));
}

void test_initializer_list()
Expand Down
Loading