throwing_type.hpp 840 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 &operator=(const throwing_type &other) {
  15. trigger = other.trigger;
  16. return *this;
  17. }
  18. void throw_on_copy(const bool mode) noexcept {
  19. trigger = mode;
  20. }
  21. bool throw_on_copy() const noexcept {
  22. return trigger;
  23. }
  24. [[nodiscard]] bool operator==(const throwing_type &other) const noexcept {
  25. return trigger == other.trigger;
  26. }
  27. private:
  28. bool trigger{};
  29. };
  30. } // namespace test
  31. #endif