Home | History | Annotate | Download | only in unique.ptr.observers
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <memory>
     11 
     12 // unique_ptr
     13 
     14 // test op*()
     15 
     16 #include <memory>
     17 #include <cassert>
     18 
     19 #include "test_macros.h"
     20 #include "unique_ptr_test_helper.h"
     21 
     22 template <class UPtr>
     23 void doTest(UPtr& p, bool ExpectTrue) {
     24   if (p)
     25     assert(ExpectTrue);
     26   else
     27     assert(!ExpectTrue);
     28 
     29   if (!p)
     30     assert(!ExpectTrue);
     31   else
     32     assert(ExpectTrue);
     33 }
     34 
     35 template <bool IsArray>
     36 void test_basic() {
     37   typedef typename std::conditional<IsArray, int[], int>::type VT;
     38   typedef std::unique_ptr<VT> U;
     39   {
     40     static_assert((std::is_constructible<bool, U>::value), "");
     41     static_assert((std::is_constructible<bool, U const&>::value), "");
     42   }
     43 #if TEST_STD_VER >= 11
     44   {
     45     static_assert(!std::is_convertible<U, bool>::value, "");
     46     static_assert(!std::is_convertible<U const&, bool>::value, "");
     47   }
     48 #endif
     49   {
     50     U p(newValue<VT>(1));
     51     U const& cp = p;
     52     doTest(p, true);
     53     doTest(cp, true);
     54   }
     55   {
     56     U p;
     57     const U& cp = p;
     58     doTest(p, false);
     59     doTest(cp, false);
     60   }
     61 }
     62 
     63 int main() {
     64   test_basic</*IsArray*/ false>();
     65   test_basic<true>();
     66 }
     67