libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

null.pass.cpp (961B)


      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 // The deleter is not called if get() == 0
     15 
     16 #include <memory>
     17 #include <cassert>
     18 
     19 class Deleter {
     20   int state_;
     21 
     22   Deleter(Deleter&);
     23   Deleter& operator=(Deleter&);
     24 
     25 public:
     26   Deleter() : state_(0) {}
     27 
     28   int state() const { return state_; }
     29 
     30   void operator()(void*) { ++state_; }
     31 };
     32 
     33 template <class T>
     34 void test_basic() {
     35   Deleter d;
     36   assert(d.state() == 0);
     37   {
     38     std::unique_ptr<T, Deleter&> p(nullptr, d);
     39     assert(p.get() == nullptr);
     40     assert(&p.get_deleter() == &d);
     41   }
     42   assert(d.state() == 0);
     43 }
     44 
     45 int main() {
     46   test_basic<int>();
     47   test_basic<int[]>();
     48 }