expected-noexcept.t.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright (c) 2016-2020 Martin Moene
  2. //
  3. // https://github.com/martinmoene/expected-lite
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. #include "nonstd/expected.hpp"
  8. #include <iostream>
  9. template< typename T >
  10. void use( T const & /*x*/) {}
  11. #define expected_PRESENT( x ) \
  12. std::cout << #x << ": " << x << "\n"
  13. #define expected_ABSENT( x ) \
  14. std::cout << #x << ": (undefined)\n"
  15. void report()
  16. {
  17. #ifdef __cpp_exceptions
  18. expected_PRESENT( __cpp_exceptions );
  19. #else
  20. expected_ABSENT( __cpp_exceptions );
  21. #endif
  22. #ifdef __EXCEPTIONS
  23. expected_PRESENT( __EXCEPTIONS );
  24. #else
  25. expected_ABSENT( __EXCEPTIONS );
  26. #endif
  27. #ifdef _HAS_EXCEPTIONS
  28. expected_PRESENT( _HAS_EXCEPTIONS );
  29. #else
  30. expected_ABSENT( _HAS_EXCEPTIONS );
  31. #endif
  32. #ifdef _CPPUNWIND
  33. expected_PRESENT( _CPPUNWIND );
  34. #else
  35. expected_ABSENT( _CPPUNWIND );
  36. #endif
  37. #ifdef _CPPRTTI
  38. expected_PRESENT( _CPPRTTI );
  39. #else
  40. expected_ABSENT( _CPPRTTI );
  41. #endif
  42. }
  43. int violate_access()
  44. {
  45. nonstd::expected<int, char> eu( nonstd:: make_unexpected('a') );
  46. return eu.value();
  47. }
  48. int main()
  49. {
  50. report();
  51. #if ! nsel_CONFIG_NO_EXCEPTIONS_SEH
  52. return violate_access();
  53. #else
  54. __try
  55. {
  56. return violate_access();
  57. }
  58. __except( EXCEPTION_EXECUTE_HANDLER )
  59. {
  60. std::cerr << "\n*** Executing SEH __except block ***\n";
  61. }
  62. #endif
  63. }
  64. // end of file