Skip to content

Commit

Permalink
iox-eclipse-iceoryx#391 implemented function swap out of class
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
  • Loading branch information
MatthiasKillat committed May 21, 2021
1 parent 7fa5c2a commit 6b28525
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,6 @@ class storable_function<StorageType, signature<ReturnType, Args...>>
/// @param f the function to swap this with
void swap(storable_function& f) noexcept;

/// @brief swap two storable functions
/// @param f the first function to swap with g
/// @param g the second function to swap with f
static void swap(storable_function& f, storable_function& g) noexcept;

/// @brief size in bytes required to store a CallableType in a storable_function
/// @return number of bytes StorageType must be able to allocate to store CallableType
/// @note this is not smallest possible due to alignment, it may work with a smaller size but
Expand Down Expand Up @@ -207,6 +202,12 @@ class storable_function<StorageType, signature<ReturnType, Args...>>
static ReturnType invokeFreeFunction(void* callable, Args&&... args);
};

/// @brief swap two storable functions
/// @param f the first function to swap with g
/// @param g the second function to swap with f
template <typename S, typename T>
static void swap(storable_function<S, T>& f, storable_function<S, T>& g) noexcept;

} // namespace cxx
} // namespace iox

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,10 @@ void storable_function<S, signature<ReturnType, Args...>>::swap(storable_functio
*this = std::move(tmp);
}

template <typename S, typename ReturnType, typename... Args>
void storable_function<S, signature<ReturnType, Args...>>::swap(storable_function& f, storable_function& g) noexcept
template <typename S, typename T>
void swap(storable_function<S, T>& f, storable_function<S, T>& g) noexcept
{
storable_function tmp = std::move(f);
f = std::move(g);
g = std::move(tmp);
f.swap(g);
}

template <typename S, typename ReturnType, typename... Args>
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_hoofs/test/moduletests/test_cxx_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ TEST_F(function_test, StaticSwapWorks)
test_function sut1(f1);
test_function sut2(f2);

test_function::swap(sut1, sut2);
swap(sut1, sut2);

ASSERT_TRUE(sut1.operator bool());
EXPECT_EQ(sut1(1), f2(1));
Expand Down

0 comments on commit 6b28525

Please sign in to comment.