throwing_ptr
Smart pointers that throw on dereference if null
All Classes Namespaces Files Functions Typedefs Friends Macros
unique_ptr_access.cpp
Go to the documentation of this file.
1 // Copyright Claudio Bantaloukas 2017-2018.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5 
6 #include <catch.hpp>
7 #include <throwing/unique_ptr.hpp>
8 
9 TEST_CASE("unique_ptr to nullptr get returns nullptr",
10  "[unique_ptr][nullptr]") {
11  throwing::unique_ptr<int> nothing;
12  REQUIRE(nothing.get() == nullptr);
13  REQUIRE(!nothing);
14 
15  throwing::unique_ptr<int> nothing2(nullptr);
16  REQUIRE(nothing2.get() == nullptr);
17  REQUIRE(!nothing2);
18 }
19 
20 TEST_CASE("unique_ptr: operator bool", "[unique_ptr][bool]") {
21  throwing::unique_ptr<int> nothing;
22  REQUIRE(!nothing);
23 
24  throwing::unique_ptr<int> something(new int);
25  REQUIRE(something);
26 }
TEST_CASE("unique_ptr to array reset to convertible", "[unique_ptr][array][reset][conv.qual]")