optional_test_inplace_fail.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright (C) 2003, Fernando Luis Cacciola Carballal.
  2. // Copyright (C) 2015 Andrzej Krzemienski.
  3. //
  4. // Use, modification, and distribution is subject to the Boost Software
  5. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // See http://www.boost.org/lib/optional for documentation.
  9. //
  10. // You are welcome to contact the author at:
  11. // fernando_cacciola@hotmail.com
  12. #include<string>
  13. #include "boost/optional/optional.hpp"
  14. #ifdef __BORLANDC__
  15. #pragma hdrstop
  16. #endif
  17. #ifndef BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT
  18. #include "boost/utility/in_place_factory.hpp"
  19. #include "boost/utility/typed_in_place_factory.hpp"
  20. #endif
  21. #include "boost/core/lightweight_test.hpp"
  22. #include "boost/none.hpp"
  23. struct Guard
  24. {
  25. double num;
  26. std::string str;
  27. Guard() : num() {}
  28. Guard(double num_, std::string str_) : num(num_), str(str_) {}
  29. friend bool operator==(const Guard& lhs, const Guard& rhs) { return lhs.num == rhs.num && lhs.str == rhs.str; }
  30. friend bool operator!=(const Guard& lhs, const Guard& rhs) { return !(lhs == rhs); }
  31. private:
  32. Guard(const Guard&);
  33. Guard& operator=(const Guard&);
  34. };
  35. int main()
  36. {
  37. #ifndef BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT
  38. int excessive_param = 2;
  39. boost::optional<Guard> og1 ( boost::in_place(1.0, "one", excessive_param) );
  40. #else
  41. NOTHING_TO_TEST_SO_JUST_FAIL
  42. #endif
  43. return 0;
  44. }