mirror of
https://github.com/microsoft/GSL.git
synced 2025-04-01 08:56:29 -04:00
introduce gsl::not_null<T>::element_type
This commit is contained in:
parent
355982daf6
commit
cd7e358a6b
@ -224,6 +224,14 @@ When a nullptr check fails, `std::terminate` is called.
|
||||
|
||||
See [F.23: Use a `not_null<T>` to indicate that “null” is not a valid value](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-nullptr)
|
||||
|
||||
#### Member Types
|
||||
|
||||
```cpp
|
||||
using element_type = T;
|
||||
```
|
||||
|
||||
The type of the pointed-to object.
|
||||
|
||||
#### Member functions
|
||||
|
||||
##### Construct/Copy
|
||||
|
@ -98,6 +98,8 @@ class not_null
|
||||
public:
|
||||
static_assert(details::is_comparable_to_nullptr<T>::value, "T cannot be compared to nullptr.");
|
||||
|
||||
using element_type = T;
|
||||
|
||||
template <typename U, typename = std::enable_if_t<std::is_convertible<U, T>::value>>
|
||||
constexpr not_null(U&& u) noexcept(std::is_nothrow_move_constructible<T>::value) : ptr_(std::forward<U>(u))
|
||||
{
|
||||
|
@ -88,4 +88,10 @@ TEST(pointers_test, swap)
|
||||
"!SwapCompilesFor<NotMoveAssignableCustomPtr>");
|
||||
}
|
||||
|
||||
TEST(pointers_test, member_types)
|
||||
{
|
||||
static_assert(std::is_same_v<gsl::not_null<int>::element_type, int>,
|
||||
"check member type: element_type");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -366,6 +366,13 @@ TEST(strict_notnull_tests, TestStrictNotNull)
|
||||
}
|
||||
}
|
||||
|
||||
TEST(pointers_test, member_types)
|
||||
{
|
||||
// make sure `element_type` is inherited from `gsl::not_null`
|
||||
static_assert(std::is_same_v<gsl::strict_not_null<int>::element_type, int>,
|
||||
"check member type: element_type");
|
||||
}
|
||||
|
||||
#if defined(__cplusplus) && (__cplusplus >= 201703L)
|
||||
|
||||
TEST(strict_notnull_tests, TestStrictNotNullConstructorTypeDeduction)
|
||||
|
Loading…
x
Reference in New Issue
Block a user