From 0d6b18cd8c2e4f9a8deed890f8bacefe5ef0ff9b Mon Sep 17 00:00:00 2001 From: Ulrik Lindahl Date: Mon, 1 Jan 2024 20:07:09 +0100 Subject: [PATCH] - Added back the second ctor with a specific default value parameter - Modified the test to make sure the default value parameter is used --- ctle_code_gen/property_generator.py | 14 +++++++++++++- unit_tests/test_prop.cpp | 4 ++-- 2 files changed, 15 insertions(+), 3 deletions(-) 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 ) { }