PageRenderTime 53ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter06.pass.cpp

http://github.com/chapuni/libcxx
C++ | 39 lines | 18 code | 8 blank | 13 comment | 2 complexity | 70e612e4ca828bbe610688fc1a5e15bf MD5 | raw file
  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. // <memory>
  10. // unique_ptr
  11. // Test unique_ptr(pointer, deleter) ctor
  12. #include <memory>
  13. #include <cassert>
  14. // unique_ptr(pointer, deleter) should work with function pointers
  15. // unique_ptr<void> should work
  16. bool my_free_called = false;
  17. void my_free(void*)
  18. {
  19. my_free_called = true;
  20. }
  21. int main()
  22. {
  23. {
  24. int i = 0;
  25. std::unique_ptr<void, void (*)(void*)> s(&i, my_free);
  26. assert(s.get() == &i);
  27. assert(s.get_deleter() == my_free);
  28. assert(!my_free_called);
  29. }
  30. assert(my_free_called);
  31. }