#include <experimental/memory>
#include <type_traits>
#include <cassert>
#include "test_macros.h"
template <class To, class From>
constexpr void test_converting_ctor() {
using ToPtr = std::experimental::observer_ptr<To>;
using FromPtr = std::experimental::observer_ptr<From>;
From obj;
FromPtr from(&obj);
ToPtr to = from;
assert(from.get() == &obj);
assert(to.get() == &obj);
#if TEST_STD_VER >= 20
static_assert(std::is_nothrow_convertible<FromPtr, ToPtr>::value);
#endif
}
template <class To, class From>
constexpr void check_non_constructible() {
using ToPtr = std::experimental::observer_ptr<To>;
using FromPtr = std::experimental::observer_ptr<From>;
static_assert(!std::is_constructible<ToPtr, FromPtr>::value);
}
struct Bar {};
struct Base {};
struct Derived : Base {};
constexpr bool test() {
test_converting_ctor<void, Bar>();
test_converting_ctor<void, int>();
test_converting_ctor<Base, Derived>();
check_non_constructible<Derived, Base>();
check_non_constructible<int, void>();
check_non_constructible<Bar, void>();
check_non_constructible<int, long>();
check_non_constructible<long, int>();
check_non_constructible<Bar, Bar const>();
test_converting_ctor<Bar const, Bar>();
return true;
}
int main(int, char**) {
test();
static_assert(test());
return 0;
}