diff --git a/ctle_code_gen/property_generator.py b/ctle_code_gen/property_generator.py index 9a81ffb..a83e4af 100644 --- a/ctle_code_gen/property_generator.py +++ b/ctle_code_gen/property_generator.py @@ -275,7 +275,19 @@ def generate_class( self, out ): out.ln( name + '(' ) match self.storageType: case storage_type.value: - out.ln( ' _Ty &_value ) : value(_value) {}', append = True ) + out.ln( ' _Ty &_value ) : value(_value)', append = True ) + with out.blk(): + out.comment_ln('set a default value IF the value type does not automatically set a default value') + out.ln('identity_assign_if_trivially_default_constructible<_Ty>( _value );') + out.ln() + + # add a second ctor with default value assignment + out.comment_ln('property standard ctor with specific assignment of default value') + out.ln( name + '( _Ty &_value, const _Ty &_initial_value ) : value(_value)' ) + with out.blk(): + out.comment_ln('set an initial value to the object') + out.ln('this->value = _initial_value;') + case storage_type.ptr: out.ln( ' std::unique_ptr<_Ty> &_value ) : value(_value) {}', append = True ) case storage_type.atomic: diff --git a/unit_tests/test_prop.cpp b/unit_tests/test_prop.cpp index 63fd457..0382490 100644 --- a/unit_tests/test_prop.cpp +++ b/unit_tests/test_prop.cpp @@ -62,7 +62,7 @@ class folks { private: std::vector> _persons; - int _simple_int = 23; + int _simple_int; public: folks(); @@ -95,7 +95,7 @@ folks::folks() return this->_persons; } ) - , simple_int( _simple_int ) + , simple_int( _simple_int, 23 ) { }