throwing_type.hpp 907 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #ifndef ENTT_COMMON_THROWING_TYPE_HPP
  2. #define ENTT_COMMON_THROWING_TYPE_HPP
  3. namespace test {
  4. struct throwing_type_exception {};
  5. struct throwing_type {
  6. throwing_type(bool mode)
  7. : trigger{mode} {}
  8. throwing_type(const throwing_type &other)
  9. : trigger{other.trigger} {
  10. if(trigger) {
  11. throw throwing_type_exception{};
  12. }
  13. }
  14. ~throwing_type() { /* make it non trivially destructible */ }
  15. throwing_type &operator=(const throwing_type &other) {
  16. trigger = other.trigger;
  17. return *this;
  18. }
  19. void throw_on_copy(const bool mode) noexcept {
  20. trigger = mode;
  21. }
  22. bool throw_on_copy() const noexcept {
  23. return trigger;
  24. }
  25. [[nodiscard]] bool operator==(const throwing_type &other) const noexcept {
  26. return trigger == other.trigger;
  27. }
  28. private:
  29. bool trigger{};
  30. };
  31. } // namespace test
  32. #endif