make_unique_value_test.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. Copyright 2014 Glen Joseph Fernandes
  3. (glenjofe@gmail.com)
  4. Distributed under the Boost Software License, Version 1.0.
  5. (http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. #include <boost/config.hpp>
  8. #if !defined(BOOST_NO_CXX11_SMART_PTR)
  9. #include <boost/detail/lightweight_test.hpp>
  10. #include <boost/smart_ptr/make_unique.hpp>
  11. struct type {
  12. int x;
  13. int y;
  14. };
  15. int main()
  16. {
  17. {
  18. std::unique_ptr<type> result = boost::make_unique<type>();
  19. BOOST_TEST(result.get() != 0);
  20. BOOST_TEST(result->x == 0);
  21. BOOST_TEST(result->y == 0);
  22. }
  23. {
  24. std::unique_ptr<const type> result =
  25. boost::make_unique<const type>();
  26. BOOST_TEST(result.get() != 0);
  27. BOOST_TEST(result->x == 0);
  28. BOOST_TEST(result->y == 0);
  29. }
  30. #if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
  31. {
  32. std::unique_ptr<type> result =
  33. boost::make_unique<type>({ 1, 2 });
  34. BOOST_TEST(result.get() != 0);
  35. BOOST_TEST(result->x == 1);
  36. BOOST_TEST(result->y == 2);
  37. }
  38. {
  39. std::unique_ptr<const type> result =
  40. boost::make_unique<const type>({ 1, 2 });
  41. BOOST_TEST(result.get() != 0);
  42. BOOST_TEST(result->x == 1);
  43. BOOST_TEST(result->y == 2);
  44. }
  45. #endif
  46. return boost::report_errors();
  47. }
  48. #else
  49. int main()
  50. {
  51. return 0;
  52. }
  53. #endif