Skip to content

Commit

Permalink
iox-eclipse-iceoryx#391 removed immovable argument type test - unsupp…
Browse files Browse the repository at this point in the history
…orted case

Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
  • Loading branch information
MatthiasKillat committed May 17, 2021
1 parent 469dac8 commit faa411a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ class storable_function<StorageType, signature<ReturnType, Args...>>
/// itself. This appears to be unavoidable and also happens in std::function.
/// The user can always provide a wrapped callable which takes a reference,
/// which is generally preferable for large objects anyway.
/// @note Arguments of class type cannot have the move constructor explicitly deleted since the arguments
/// must be forwarded internally which is done by move or, if no move is specified, by copy.
/// If the move operation is explcitly deleted the compiler will not fall back to copy but emit an error.
/// Not specifying move or using a default implementation is fine.
/// This is also the case for std::function (for the gcc implementation at least).
ReturnType operator()(Args... args);


Expand Down
35 changes: 1 addition & 34 deletions iceoryx_hoofs/test/moduletests/test_cxx_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ struct Arg : Counter<Arg> {
Arg(const Arg &) = default;
Arg &operator=(const Arg &) = default;

// we cannot do this, the function wrapper requires the arguments to be copy-constructible
// We cannot delete move, the function wrapper requires the arguments to be copy-constructible
// according to the standard this means the copy Ctor must exist and move cannot be explicitly deleted
// (it does not necessarily have to be defined, in which case the compiler will perform a copy
// whenever a move would be possible)
Expand All @@ -147,26 +147,10 @@ struct Arg : Counter<Arg> {
int32_t value;
};

struct ImmovableArg : Counter<ImmovableArg> {
ImmovableArg() = default;
ImmovableArg(uint32_t value) : value(value) {};
ImmovableArg(const ImmovableArg &) = default;
ImmovableArg(ImmovableArg &&) = delete;

ImmovableArg &operator=(const ImmovableArg &) = default;
ImmovableArg &operator=(ImmovableArg &&) = delete;

int32_t value;
};

int32_t freeFunctionWithCopyableArg(Arg arg) {
return arg.value;
}

int32_t freeFunctionWithImmovableArg(ImmovableArg arg) {
return arg.value;
}


class function_test : public Test
{
Expand Down Expand Up @@ -550,21 +534,4 @@ TEST_F(function_test, callWithCopyConstructibleArgument)
// note that by using the numCopies counter we can observe that the std::function call also performs 2 copies of arg in this case
}

#if 0
//remove test since this case is not supported
TEST_F(function_test, callWithImmovableArgument)
{
iox::cxx::function<int32_t(ImmovableArg), 1024> sut(freeFunctionWithImmovableArg);
// std::function<int32_t(ImmovableArg)> func(freeFunctionWithImmovableArg); // cannot be constructed
ImmovableArg::resetCounts();

ImmovableArg arg(73); // cannot be called

auto result = sut(arg);

EXPECT_EQ(result, freeFunctionWithImmovableArg(arg));
}
#endif


} // namespace

0 comments on commit faa411a

Please sign in to comment.