1 #ifndef ENTT_ENTITY_THROWING_COMPONENT_HPP
2 #define ENTT_ENTITY_THROWING_COMPONENT_HPP
3 
4 
5 namespace test {
6 
7 
8 class throwing_component {
9     struct test_exception {};
10 
11 public:
12     using exception_type = test_exception;
13     static constexpr auto moved_from_value = -1;
14 
throwing_component(int value)15     throwing_component(int value)
16         : data{value}
17     {}
18 
throwing_component(const throwing_component & other)19     throwing_component(const throwing_component &other)
20         : data{other.data}
21     {
22         if(data == trigger_on_value) {
23             data = moved_from_value;
24             throw exception_type{};
25         }
26     }
27 
operator =(const throwing_component & other)28     throwing_component & operator=(const throwing_component &other) {
29         if(other.data == trigger_on_value) {
30             data = moved_from_value;
31             throw exception_type{};
32         }
33 
34         data = other.data;
35         return *this;
36     }
37 
operator int() const38     operator int() const {
39         return data;
40     }
41 
42     static inline int trigger_on_value{};
43 
44 private:
45     int data{};
46 };
47 
48 
49 }
50 
51 
52 #endif
53