optional_test_tc_base.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright (C) 2014 Andrzej Krzemienski.
  2. //
  3. // Use, modification, and distribution is subject to the Boost Software
  4. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/lib/optional for documentation.
  8. //
  9. // You are welcome to contact the author at:
  10. // akrzemi1@gmail.com
  11. #include "boost/optional/optional.hpp"
  12. #ifdef __BORLANDC__
  13. #pragma hdrstop
  14. #endif
  15. #include "boost/core/lightweight_test.hpp"
  16. #if defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
  17. int main()
  18. {
  19. }
  20. #else
  21. #include <utility>
  22. struct NotDefaultConstructible
  23. {
  24. NotDefaultConstructible() = delete;
  25. };
  26. void test_tc_base()
  27. {
  28. boost::optional<NotDefaultConstructible> o;
  29. BOOST_TEST(boost::none == o);
  30. }
  31. struct S
  32. {
  33. };
  34. template<class T>
  35. struct W
  36. {
  37. T& t_;
  38. template<class... Args>
  39. W(Args&&... args)
  40. : t_(std::forward<Args>(args)...)
  41. {
  42. }
  43. };
  44. void test_value_init()
  45. {
  46. #ifndef BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX
  47. {
  48. S s;
  49. W<S> w{s};
  50. }
  51. #endif
  52. {
  53. S s;
  54. W<S> w(s);
  55. }
  56. }
  57. void test_optoinal_reference_wrapper()
  58. {
  59. boost::optional<W<S&> > o;
  60. BOOST_TEST(boost::none == o);
  61. }
  62. int main()
  63. {
  64. test_tc_base();
  65. test_value_init();
  66. test_optoinal_reference_wrapper();
  67. return boost::report_errors();
  68. }
  69. #endif