-
Notifications
You must be signed in to change notification settings - Fork 402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement copy/move constructors and assignment operators for 'FixedPositionContainer' #2052
Comments
Hi, @elBoberido I'm interesting in this one. Could I give it a try? |
@Dennis40816 sure. The PR which introduce the class is not merged yet. I would ping you once #2051 is merged. You can of course start with that branch but there might be some force pushes until it is merged. |
@elBoberido Sure, I'll be around. Feel free to notify me once it's completed. |
@Dennis40816 it is merged. Looking forward to your PR :) |
Signed-off-by: Dennis Liu <[email protected]> The `FixedPositionContainer` was enhanced with copy and move constructors as well as assignment operations. For both copy and move operations, member variables like `m_size`, `m_begin_free`, `m_begin_used`, `m_status`, and `m_next` are handled using copy assignments. The primary distinction between copy and move is in how `m_data` is handled. Specifically, after a move operation: - The original container's `m_size`, `m_begin_free`, and `m_begin_used` are reset. - However, `m_data`, `m_status`, and `m_next` of the original container remain unchanged. Header declarations have been updated to align with these modifications.
Signed-off-by: Dennis Liu <[email protected]> Added unit tests to validate both copy and move semantics for the `FixedPositionContainer`. Run `dust/test/dust_moduletests` to view result.
Hi, elBoberido. As this is my first time making modifications to iceoryx, there might be areas I haven't fully considered, so I'd appreciate your assistance in reviewing. I have initially completed the target implementation and added unit tests. |
In the move feature, there's an issue concerning the original container instance after move constructor or move assignment. Currently, I've only modified |
@Dennis40816 looking at other containers, we also call When you think you are done, just open an PR :) |
Signed-off-by: Dennis Liu <[email protected]> Refactor the copy and move constructors of FixedPositionContainer to leverage the functionality of the respective assignment operators. This reduces code duplication and ensures consistent behavior across constructors and assignment operations. Update tests to reflect the changes in behavior.
Signed-off-by: Dennis Liu <[email protected]> The changes involved renaming the tests and ensuring the test content better aligns with the ZOMBIE criteria. The primary object under test is `SutComplex`. For each constructor or assignment, tests were conducted on empty containers, single element containers, multiple elements containers, and full capacity containers. In the case of moves, additional checks were made to see if the `DTor` of `SutComplex` was called (from `FixPositionContainer::clear()`).
Signed-off-by: Dennis Liu <[email protected]> Add issue 2052 into unreleased document in feature section.
Signed-off-by: Dennis Liu <[email protected]> The changes involved renaming the tests and ensuring the test content better aligns with the ZOMBIE criteria. The primary object under test is `SutComplex`. For each constructor or assignment, tests were conducted on empty containers, single element containers, multiple elements containers, and full capacity containers. In the case of moves, additional checks were made to see if the `DTor` of `SutComplex` was called (from `FixedPositionContainer::clear()`).
Signed-off-by: Dennis Liu <[email protected]> Add issue 2052 into unreleased document in feature section. Signed-off-by: Dennis Liu <[email protected]>
Signed-off-by: Dennis Liu <[email protected]> Add issue 2052 into unreleased document in feature section.
Signed-off-by: Dennis Liu <[email protected]> Fix nitpick mentioned in PR. Including: - Replace index value `0U` by `IndexType::First`. - Change variable to snake_case.
Signed-off-by: Dennis Liu <[email protected]> Add more strict check(e.g., check full, size, empty) and rearrange the test code.
Signed-off-by: Dennis Liu <[email protected]> Add more strict check(e.g., check full, size, empty) and rearrange the test code.
Signed-off-by: Dennis Liu <[email protected]> Fix typo in test case b46d0be7-5977-467e-adc4-2e9adc554fdd. The result should be true.
Signed-off-by: Dennis Liu <[email protected]> According to PR discussion, I used the latter method to implement both ctor and assignment.
Signed-off-by: Dennis Liu <[email protected]> Add a private function init() to reduce code duplication. Also, fix the issues mentioned after commit `b0929dd96287f46d519c634522f2700d0a646221`.
Signed-off-by: Dennis Liu <[email protected]> We use same test data(e.g., {0U, 1U, 2U, 3U} or `fillSut()` or `fillSutComplex()` function in two consecutive tests) in `FixPositionContainer` ctor or assignment related tests. {56U, 57U, 58U, 59U} replace {0U, 1U, 2U, 3U} in multiple values tests.
Signed-off-by: Dennis Liu <[email protected]> Rename `init` to `copy_and_move_impl` to clear the function purpose. Also, move up the declaration of `copy_and_move_impl`.
Signed-off-by: Dennis Liu <[email protected]> With the previous implementation of `copy_and_move_impl`, non-copyable classes would encounter compilation failures due to non-compile-time if-else branching. The compiler would check the deleted copy constructor and assignment in the `else` branch, even though they would never be called. To address this, several helper structs have been implemented to change runtime if-else branching to compile-time if-else branching for C++14. If C++17 is used, we can simply employ `if constexpr` to make the branching compile-time. The test case `e1cc7c9f-c1b5-4047-811b-004302af5c00` (UsingMoveCtorAtNonCopyableTypeShouldCompile) verifies that the implementation works for both C++14 and C++17. The assignment portion will be added in a subsequent commit.
Signed-off-by: Dennis Liu <[email protected]> Based on the discussion at [eclipse-iceoryx#2069 (comment)], additional tests have been incorporated. Furthermore, some statistical results have been updated due to modifications in the `copy_and_move_impl`. For instance, when a non-empty container is moved to an empty container using the move assignment, the `MoveCtor` is the function that is invoked, not the `operator=`. This is because if the slot was previously free, we utilize placement new to ensure proper functionality. Consequently, it is the `MoveCtor` that gets called."
Signed-off-by: Dennis Liu <[email protected]> This commit aims to fix that incorrect member such as `m_begin_free` and `m_begin_used` might cause unexpected erase error (usually terminate at line 515). Hence, the member will be updated after all data are moved or copied into `this` container, ensuring free list and used list return to normal status(not broke by copy or move). Then, `erase` can be called safely. Finally, the correct information from rhs will be assigned to member at the bottom of `copy_and_move_impl`.
Signed-off-by: Dennis Liu <[email protected]> Removed the division symbol '\'. Additionally, a new line has been added between different test sections.
Signed-off-by: Dennis Liu <[email protected]> Added unit tests to validate both copy and move semantics for the `FixedPositionContainer`. Run `dust/test/dust_moduletests` to view result.
Signed-off-by: Dennis Liu <[email protected]> Refactor the copy and move constructors of FixedPositionContainer to leverage the functionality of the respective assignment operators. This reduces code duplication and ensures consistent behavior across constructors and assignment operations. Update tests to reflect the changes in behavior.
Signed-off-by: Dennis Liu <[email protected]> The changes involved renaming the tests and ensuring the test content better aligns with the ZOMBIE criteria. The primary object under test is `SutComplex`. For each constructor or assignment, tests were conducted on empty containers, single element containers, multiple elements containers, and full capacity containers. In the case of moves, additional checks were made to see if the `DTor` of `SutComplex` was called (from `FixedPositionContainer::clear()`).
Signed-off-by: Dennis Liu <[email protected]> Add issue 2052 into unreleased document in feature section.
Signed-off-by: Dennis Liu <[email protected]> Fix nitpick mentioned in PR. Including: - Replace index value `0U` by `IndexType::First`. - Change variable to snake_case.
Signed-off-by: Dennis Liu <[email protected]> Add more strict check(e.g., check full, size, empty) and rearrange the test code.
Signed-off-by: Dennis Liu <[email protected]> Fix typo in test case b46d0be7-5977-467e-adc4-2e9adc554fdd. The result should be true.
Signed-off-by: Dennis Liu <[email protected]> According to PR discussion, I used the latter method to implement both ctor and assignment.
Signed-off-by: Dennis Liu <[email protected]> Add a private function init() to reduce code duplication. Also, fix the issues mentioned after commit `b0929dd96287f46d519c634522f2700d0a646221`.
Signed-off-by: Dennis Liu <[email protected]> We use same test data(e.g., {0U, 1U, 2U, 3U} or `fillSut()` or `fillSutComplex()` function in two consecutive tests) in `FixPositionContainer` ctor or assignment related tests. {56U, 57U, 58U, 59U} replace {0U, 1U, 2U, 3U} in multiple values tests.
Signed-off-by: Dennis Liu <[email protected]> Rename `init` to `copy_and_move_impl` to clear the function purpose. Also, move up the declaration of `copy_and_move_impl`.
Signed-off-by: Dennis Liu <[email protected]> With the previous implementation of `copy_and_move_impl`, non-copyable classes would encounter compilation failures due to non-compile-time if-else branching. The compiler would check the deleted copy constructor and assignment in the `else` branch, even though they would never be called. To address this, several helper structs have been implemented to change runtime if-else branching to compile-time if-else branching for C++14. If C++17 is used, we can simply employ `if constexpr` to make the branching compile-time. The test case `e1cc7c9f-c1b5-4047-811b-004302af5c00` (UsingMoveCtorAtNonCopyableTypeShouldCompile) verifies that the implementation works for both C++14 and C++17. The assignment portion will be added in a subsequent commit.
Signed-off-by: Dennis Liu <[email protected]> Based on the discussion at [eclipse-iceoryx#2069 (comment)], additional tests have been incorporated. Furthermore, some statistical results have been updated due to modifications in the `copy_and_move_impl`. For instance, when a non-empty container is moved to an empty container using the move assignment, the `MoveCtor` is the function that is invoked, not the `operator=`. This is because if the slot was previously free, we utilize placement new to ensure proper functionality. Consequently, it is the `MoveCtor` that gets called."
Signed-off-by: Dennis Liu <[email protected]> This commit aims to fix that incorrect member such as `m_begin_free` and `m_begin_used` might cause unexpected erase error (usually terminate at line 515). Hence, the member will be updated after all data are moved or copied into `this` container, ensuring free list and used list return to normal status(not broke by copy or move). Then, `erase` can be called safely. Finally, the correct information from rhs will be assigned to member at the bottom of `copy_and_move_impl`.
Signed-off-by: Dennis Liu <[email protected]> Removed the division symbol '\'. Additionally, a new line has been added between different test sections.
Signed-off-by: Dennis Liu <[email protected]> This commit extracts C++14 template structures from `FixedPositionContainer` to a new header `detail/fixed_position_container_helper.hpp`, resolving compile-time differences between g++-8.4 and g++-11.4, and ensuring adherence to the C++ standard. In g++-8.4, nested template deduction and usage were problematic, causing original implementation failures. Conversely, g++-11.4 processed the same structures correctly, though reasons are not fully clear. After this refactor, unit tests for `FixedPositionContainer` remain successful, and the code compiles error-free on both g++-8.4 and g++-11.4.
Signed-off-by: Dennis Liu <[email protected]> Move iclude "iox/detail/fixed_position_container_helper.hpp" from `fixed_position_container.hpp` to `fixed_position_container.inl`.
Signed-off-by: Dennis Liu <[email protected]> Zero size rhs container isn't considered. Therefore, test failed in build-test-ubuntu-with-address-sanitizer-clang-latest.
Signed-off-by: Dennis Liu <[email protected]> Simplify `copy_and_move_impl` according to `clear`. Also, add sub namespace `detail` to helper struct.
Signed-off-by: Dennis Liu <[email protected]> Add a new test case `IteratorsAfterMoveWorkAsExpected`. Remove previous test cases `ContainerIsNotMovable` and `ContainerIsNotCopyable`.
Signed-off-by: Dennis Liu <[email protected]> When we constrcut `FixedPositionContainer`. We need to make sure that internal status `m_status` be initialized correctly. Note that when the constructor (default / copy / move) is called, the lhs member(`m_status`, `m_next`) are all undefined. Therefore, `reset_member` should be used in every ctor.
Signed-off-by: Dennis Liu <[email protected]> It's can be simply replaced by a `for` loop to set m_status to FREE in copyCtor and assignmentCtor. Therefore, no need to add a new function.
…iner-copymove-func-impl iox-#2052 Implement move/copy constructor and assignment for `FixedPositionContainer`
Refactor copy_and_move_impl by new struct `SpecialCreationHelper` and enum class `SpecialCreationOperations` with C++17 features. Deleter __cplusplus branchs. Signed-off-by: Dennis Liu <[email protected]>
When we commit, Clang Format should have already been applied once. However, the CI process failed. I suspect it's due to an issue with inappropriate new lines. Signed-off-by: Dennis Liu <[email protected]>
Signed-off-by: Dennis Liu <[email protected]>
Signed-off-by: Dennis Liu <[email protected]>
…move_impl iox-#2052 Refactor copy_and_move_impl
Brief feature description
The
FixedPositionContainer
is neither move nor copy constructible or assignable. Currently it is not required but would be a nice enhancement.The text was updated successfully, but these errors were encountered: