mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
Corrected SFINAE for conversion constructors on span.
This commit is contained in:
parent
d23f4d931c
commit
3b2419532e
31
gsl/span
31
gsl/span
@ -123,23 +123,6 @@ namespace details
|
|||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class From, class To>
|
|
||||||
struct is_allowed_pointer_conversion
|
|
||||||
: public std::integral_constant<bool, std::is_pointer<From>::value &&
|
|
||||||
std::is_pointer<To>::value &&
|
|
||||||
std::is_convertible<From, To>::value>
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class From, class To>
|
|
||||||
struct is_allowed_integral_conversion
|
|
||||||
: public std::integral_constant<
|
|
||||||
bool, std::is_integral<From>::value && std::is_integral<To>::value &&
|
|
||||||
sizeof(From) == sizeof(To) && alignof(From) == alignof(To) &&
|
|
||||||
std::is_convertible<From, To>::value>
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
template <std::ptrdiff_t From, std::ptrdiff_t To>
|
template <std::ptrdiff_t From, std::ptrdiff_t To>
|
||||||
struct is_allowed_extent_conversion
|
struct is_allowed_extent_conversion
|
||||||
: public std::integral_constant<bool, From == To || From == gsl::dynamic_extent ||
|
: public std::integral_constant<bool, From == To || From == gsl::dynamic_extent ||
|
||||||
@ -150,19 +133,7 @@ namespace details
|
|||||||
template <class From, class To>
|
template <class From, class To>
|
||||||
struct is_allowed_element_type_conversion
|
struct is_allowed_element_type_conversion
|
||||||
: public std::integral_constant<bool, std::is_same<From, std::remove_cv_t<To>>::value ||
|
: public std::integral_constant<bool, std::is_same<From, std::remove_cv_t<To>>::value ||
|
||||||
is_allowed_pointer_conversion<From, To>::value ||
|
std::is_convertible<From(*)[], To(*)[]>::value>
|
||||||
is_allowed_integral_conversion<From, To>::value>
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class From>
|
|
||||||
struct is_allowed_element_type_conversion<From, byte>
|
|
||||||
: public std::integral_constant<bool, !std::is_const<From>::value>
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class From>
|
|
||||||
struct is_allowed_element_type_conversion<From, const byte> : public std::true_type
|
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -423,6 +423,7 @@ SUITE(span_tests)
|
|||||||
span<const int, 4> s{arr};
|
span<const int, 4> s{arr};
|
||||||
CHECK(s.size() == narrow_cast<ptrdiff_t>(arr.size()) && s.data() == arr.data());
|
CHECK(s.size() == narrow_cast<ptrdiff_t>(arr.size()) && s.data() == arr.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIRM_COMPILATION_ERRORS
|
#ifdef CONFIRM_COMPILATION_ERRORS
|
||||||
{
|
{
|
||||||
span<const int, 2> s{arr};
|
span<const int, 2> s{arr};
|
||||||
@ -437,6 +438,7 @@ SUITE(span_tests)
|
|||||||
{
|
{
|
||||||
span<const int, 5> s{arr};
|
span<const int, 5> s{arr};
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
{
|
{
|
||||||
auto get_an_array = []() -> const std::array<int, 4> { return {1, 2, 3, 4}; };
|
auto get_an_array = []() -> const std::array<int, 4> { return {1, 2, 3, 4}; };
|
||||||
@ -444,7 +446,6 @@ SUITE(span_tests)
|
|||||||
// try to take a temporary std::array
|
// try to take a temporary std::array
|
||||||
take_a_span(get_an_array());
|
take_a_span(get_an_array());
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(from_std_array_const_constructor)
|
TEST(from_std_array_const_constructor)
|
||||||
@ -460,6 +461,7 @@ SUITE(span_tests)
|
|||||||
span<const int, 4> s{arr};
|
span<const int, 4> s{arr};
|
||||||
CHECK(s.size() == narrow_cast<ptrdiff_t>(arr.size()) && s.data() == arr.data());
|
CHECK(s.size() == narrow_cast<ptrdiff_t>(arr.size()) && s.data() == arr.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIRM_COMPILATION_ERRORS
|
#ifdef CONFIRM_COMPILATION_ERRORS
|
||||||
{
|
{
|
||||||
span<const int, 2> s{arr};
|
span<const int, 2> s{arr};
|
||||||
@ -509,7 +511,7 @@ SUITE(span_tests)
|
|||||||
{
|
{
|
||||||
#ifdef CONFIRM_COMPILATION_ERRORS
|
#ifdef CONFIRM_COMPILATION_ERRORS
|
||||||
span<char> s{cstr};
|
span<char> s{cstr};
|
||||||
#endif
|
#endif
|
||||||
span<const char> cs{cstr};
|
span<const char> cs{cstr};
|
||||||
CHECK(cs.size() == narrow_cast<std::ptrdiff_t>(cstr.size()) &&
|
CHECK(cs.size() == narrow_cast<std::ptrdiff_t>(cstr.size()) &&
|
||||||
cs.data() == cstr.data());
|
cs.data() == cstr.data());
|
||||||
@ -520,7 +522,7 @@ SUITE(span_tests)
|
|||||||
auto get_temp_vector = []() -> std::vector<int> { return {}; };
|
auto get_temp_vector = []() -> std::vector<int> { return {}; };
|
||||||
auto use_span = [](span<int> s) { static_cast<void>(s); };
|
auto use_span = [](span<int> s) { static_cast<void>(s); };
|
||||||
use_span(get_temp_vector());
|
use_span(get_temp_vector());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -534,7 +536,7 @@ SUITE(span_tests)
|
|||||||
auto get_temp_string = []() -> std::string { return{}; };
|
auto get_temp_string = []() -> std::string { return{}; };
|
||||||
auto use_span = [](span<char> s) { static_cast<void>(s); };
|
auto use_span = [](span<char> s) { static_cast<void>(s); };
|
||||||
use_span(get_temp_string());
|
use_span(get_temp_string());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -552,11 +554,9 @@ SUITE(span_tests)
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
#ifdef CONFIRM_COMPILATION_ERRORS
|
|
||||||
auto get_temp_string = []() -> const std::string { return {}; };
|
auto get_temp_string = []() -> const std::string { return {}; };
|
||||||
auto use_span = [](span<const char> s) { static_cast<void>(s); };
|
auto use_span = [](span<const char> s) { static_cast<void>(s); };
|
||||||
use_span(get_temp_string());
|
use_span(get_temp_string());
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -583,6 +583,7 @@ SUITE(span_tests)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef CONFIRM_COMPILATION_ERRORS
|
||||||
{
|
{
|
||||||
span<int> s;
|
span<int> s;
|
||||||
span<unsigned int> s2 = s;
|
span<unsigned int> s2 = s;
|
||||||
@ -596,12 +597,11 @@ SUITE(span_tests)
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
#ifdef CONFIRM_COMPILATION_ERRORS
|
|
||||||
span<int> s;
|
span<int> s;
|
||||||
span<short> s2 = s;
|
span<short> s2 = s;
|
||||||
static_cast<void>(s2);
|
static_cast<void>(s2);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(copy_move_and_assignment)
|
TEST(copy_move_and_assignment)
|
||||||
@ -689,7 +689,7 @@ SUITE(span_tests)
|
|||||||
span<int, 5> av = arr;
|
span<int, 5> av = arr;
|
||||||
#ifdef CONFIRM_COMPILATION_ERRORS
|
#ifdef CONFIRM_COMPILATION_ERRORS
|
||||||
CHECK(av.last<6>().length() == 6);
|
CHECK(av.last<6>().length() == 6);
|
||||||
#endif
|
#endif
|
||||||
CHECK_THROW(av.last(6).length(), fail_fast);
|
CHECK_THROW(av.last(6).length(), fail_fast);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user