mirror of
https://github.com/microsoft/GSL.git
synced 2025-04-24 01:55:31 -04:00
Compare commits
No commits in common. "272463043ef3e442f6c80a530d3dd38ee6781381" and "4b190d2e2a2c9ddbff06d33afe260a5b3505e69a" have entirely different histories.
272463043e
...
4b190d2e2a
@ -294,12 +294,6 @@ void operator[](std::ptrdiff_t) const = delete;
|
|||||||
|
|
||||||
Array index operator is explicitly deleted. Pointers point to single objects ([I.13: Do not pass an array as a single pointer](http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Ri-array)), so don't allow treating them as an array.
|
Array index operator is explicitly deleted. Pointers point to single objects ([I.13: Do not pass an array as a single pointer](http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Ri-array)), so don't allow treating them as an array.
|
||||||
|
|
||||||
```cpp
|
|
||||||
void swap(not_null<T>& other) { std::swap(ptr_, other.ptr_); }
|
|
||||||
```
|
|
||||||
|
|
||||||
Swaps contents with another `gsl::not_null` object.
|
|
||||||
|
|
||||||
#### Non-member functions
|
#### Non-member functions
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
@ -309,13 +303,6 @@ auto make_not_null(T&& t) noexcept;
|
|||||||
|
|
||||||
Creates a `gsl::not_null` object, deducing the target type from the type of the argument.
|
Creates a `gsl::not_null` object, deducing the target type from the type of the argument.
|
||||||
|
|
||||||
```cpp
|
|
||||||
template <typename T, typename = std::enable_if_t<std::is_move_assignable<T>::value && std::is_move_constructible<T>::value>>
|
|
||||||
void swap(not_null<T>& a, not_null<T>& b);
|
|
||||||
```
|
|
||||||
|
|
||||||
Swaps the contents of two `gsl::not_null` objects.
|
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
template <class T, class U>
|
template <class T, class U>
|
||||||
auto operator==(const not_null<T>& lhs,
|
auto operator==(const not_null<T>& lhs,
|
||||||
@ -871,10 +858,3 @@ constexpr auto at(std::span<T, extent> sp, const index i) -> decltype(sp[sp.size
|
|||||||
This overload returns a reference to the `i`s element of the `std::span` `sp`. It [`Expects`](#user-content-H-assert-expects) that the provided index is within the bounds of the array.
|
This overload returns a reference to the `i`s element of the `std::span` `sp`. It [`Expects`](#user-content-H-assert-expects) that the provided index is within the bounds of the array.
|
||||||
|
|
||||||
For [`gsl::at`](#user-content-H-span_ext-at) for [`gsl::span`](#user-content-H-span-span) see header [`span_ext`](#user-content-H-span_ext).
|
For [`gsl::at`](#user-content-H-span_ext-at) for [`gsl::span`](#user-content-H-span-span) see header [`span_ext`](#user-content-H-span_ext).
|
||||||
|
|
||||||
```cpp
|
|
||||||
template <class T, std::enable_if_t<std::is_move_assignable<T>::value && std::is_move_constructible<T>::value>>
|
|
||||||
void swap(T& a, T& b);
|
|
||||||
```
|
|
||||||
|
|
||||||
Swaps the contents of two objects. Exists only to specialize `gsl::swap<T>(gsl::not_null<T>&, gsl::not_null<T>&)`.
|
|
||||||
|
@ -75,7 +75,7 @@ using std::unique_ptr;
|
|||||||
// T must be a pointer type
|
// T must be a pointer type
|
||||||
// - disallow construction from any type other than pointer type
|
// - disallow construction from any type other than pointer type
|
||||||
//
|
//
|
||||||
template <class T, std::enable_if_t<std::is_pointer<T>::value, bool> = true>
|
template <class T, class = std::enable_if_t<std::is_pointer<T>::value>>
|
||||||
using owner = T;
|
using owner = T;
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -117,7 +117,7 @@ public:
|
|||||||
not_null(const not_null& other) = default;
|
not_null(const not_null& other) = default;
|
||||||
not_null& operator=(const not_null& other) = default;
|
not_null& operator=(const not_null& other) = default;
|
||||||
constexpr details::value_or_reference_return_t<T> get() const
|
constexpr details::value_or_reference_return_t<T> get() const
|
||||||
noexcept(noexcept(details::value_or_reference_return_t<T>(std::declval<T&>())))
|
noexcept(noexcept(details::value_or_reference_return_t<T>{std::declval<T&>()}))
|
||||||
{
|
{
|
||||||
return ptr_;
|
return ptr_;
|
||||||
}
|
}
|
||||||
@ -139,18 +139,10 @@ public:
|
|||||||
not_null& operator-=(std::ptrdiff_t) = delete;
|
not_null& operator-=(std::ptrdiff_t) = delete;
|
||||||
void operator[](std::ptrdiff_t) const = delete;
|
void operator[](std::ptrdiff_t) const = delete;
|
||||||
|
|
||||||
void swap(not_null<T>& other) { std::swap(ptr_, other.ptr_); }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
T ptr_;
|
T ptr_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, typename = std::enable_if_t<std::is_move_assignable<T>::value && std::is_move_constructible<T>::value>>
|
|
||||||
void swap(not_null<T>& a, not_null<T>& b)
|
|
||||||
{
|
|
||||||
a.swap(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
auto make_not_null(T&& t) noexcept
|
auto make_not_null(T&& t) noexcept
|
||||||
{
|
{
|
||||||
|
@ -146,9 +146,6 @@ GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
|
|||||||
return *(cont.begin() + i);
|
return *(cont.begin() + i);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T, std::enable_if_t<std::is_move_assignable<T>::value && std::is_move_constructible<T>::value>>
|
|
||||||
void swap(T& a, T& b) { std::swap(a, b); }
|
|
||||||
|
|
||||||
#if defined(__cpp_lib_span) && __cpp_lib_span >= 202002L
|
#if defined(__cpp_lib_span) && __cpp_lib_span >= 202002L
|
||||||
template <class T, std::size_t extent = std::dynamic_extent>
|
template <class T, std::size_t extent = std::dynamic_extent>
|
||||||
constexpr auto at(std::span<T, extent> sp, const index i) -> decltype(sp[sp.size()])
|
constexpr auto at(std::span<T, extent> sp, const index i) -> decltype(sp[sp.size()])
|
||||||
|
@ -206,7 +206,6 @@ add_executable(gsl_tests
|
|||||||
byte_tests.cpp
|
byte_tests.cpp
|
||||||
notnull_tests.cpp
|
notnull_tests.cpp
|
||||||
owner_tests.cpp
|
owner_tests.cpp
|
||||||
pointers_tests.cpp
|
|
||||||
span_compatibility_tests.cpp
|
span_compatibility_tests.cpp
|
||||||
span_ext_tests.cpp
|
span_ext_tests.cpp
|
||||||
span_tests.cpp
|
span_tests.cpp
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
#include <gtest/gtest.h>
|
|
||||||
|
|
||||||
#include <gsl/pointers>
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
TEST(pointers_test, swap)
|
|
||||||
{
|
|
||||||
// taken from gh-1129:
|
|
||||||
gsl::not_null<std::unique_ptr<int>> a(std::make_unique<int>(0));
|
|
||||||
gsl::not_null<std::unique_ptr<int>> b(std::make_unique<int>(1));
|
|
||||||
|
|
||||||
EXPECT_TRUE(*a == 0);
|
|
||||||
EXPECT_TRUE(*b == 1);
|
|
||||||
|
|
||||||
gsl::swap(a, b);
|
|
||||||
|
|
||||||
EXPECT_TRUE(*a == 1);
|
|
||||||
EXPECT_TRUE(*b == 0);
|
|
||||||
}
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user