optional_test_deleted_default_ctor.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2017 Peter Dimov
  2. // Copyright 2017 Vinnie NotDefaultConstructible
  3. // Copyright 2018 Andrzej Krzemienski
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. //
  7. // http://www.boost.org/LICENSE_1_0.txt
  8. #include <boost/config.hpp>
  9. #if defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
  10. int main()
  11. {
  12. }
  13. #else
  14. #include <boost/optional.hpp>
  15. #include <utility>
  16. class basic_multi_buffer;
  17. class const_buffers_type // a similar declaration in boost.beast had problem
  18. { // with boost opitonal
  19. basic_multi_buffer const* b_;
  20. friend class basic_multi_buffer;
  21. explicit
  22. const_buffers_type(basic_multi_buffer const& b);
  23. public:
  24. const_buffers_type() = delete;
  25. const_buffers_type(const_buffers_type const&) = default;
  26. const_buffers_type& operator=(const_buffers_type const&) = default;
  27. };
  28. void test_beast_example()
  29. {
  30. // test if it even compiles
  31. boost::optional< std::pair<const_buffers_type, int> > opt, opt2;
  32. opt = opt2;
  33. (void)opt;
  34. }
  35. struct NotDefaultConstructible // minimal class exposing the problem
  36. {
  37. NotDefaultConstructible() = delete;
  38. };
  39. void test_assign_for_non_default_constructible()
  40. {
  41. // test if it even compiles
  42. boost::optional<NotDefaultConstructible> opt, opt2;
  43. opt = opt2;
  44. (void)opt;
  45. }
  46. int main()
  47. {
  48. test_beast_example();
  49. test_assign_for_non_default_constructible();
  50. }
  51. #endif