mirror of
https://github.com/microsoft/GSL.git
synced 2025-04-02 09:18:33 -04:00
Replace the occurances of `class = std::enable_if_t<Cond>` and `typename = std::enable_if_t<Cond>` that have been identified in the previous commit with `std::enable_if_t<Cond, bool> = true`. This commit is inspired by #1174, which changed one occurance in the owner header. This commit is aimed to fix all remaining occurances.
43 lines
1.0 KiB
C++
43 lines
1.0 KiB
C++
#include <gtest/gtest.h>
|
|
|
|
#include <gsl/pointers>
|
|
|
|
#include <memory>
|
|
#include <type_traits>
|
|
#include <utility>
|
|
|
|
namespace
|
|
{
|
|
|
|
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);
|
|
}
|
|
|
|
// These are regressions, should be fixed.
|
|
struct NotMovable
|
|
{
|
|
NotMovable(NotMovable&&) = delete;
|
|
NotMovable& operator=(NotMovable&&) = delete;
|
|
};
|
|
template <typename U, typename = void>
|
|
static constexpr bool SwapCompilesFor = false;
|
|
template <typename U>
|
|
static constexpr bool
|
|
SwapCompilesFor<U, std::void_t<decltype(gsl::swap<U>(std::declval<gsl::not_null<U>&>(),
|
|
std::declval<gsl::not_null<U>&>()))>> =
|
|
true;
|
|
static_assert(!SwapCompilesFor<NotMovable>, "!SwapCompilesFor<NotMovable>");
|
|
|
|
} // namespace
|