mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-15 23:53:33 +08:00
Array<>::operator+=(Array<>) implementation and test
This commit is contained in:
@@ -394,6 +394,18 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <uavcan::ArrayMode RhsArrayMode, unsigned int RhsMaxSize>
|
||||
SelfType& operator+=(const Array<T, RhsArrayMode, RhsMaxSize>& rhs)
|
||||
{
|
||||
typedef Array<T, RhsArrayMode, RhsMaxSize> Rhs;
|
||||
typedef typename Select<(sizeof(SizeType) > sizeof(typename Rhs::SizeType)),
|
||||
SizeType, typename Rhs::SizeType>::Result CommonSizeType;
|
||||
StaticAssert<IsDynamic>::check();
|
||||
for (CommonSizeType i = 0; i < rhs.size(); i++)
|
||||
push_back(rhs[i]);
|
||||
return *this;
|
||||
}
|
||||
|
||||
typedef ValueType value_type;
|
||||
typedef SizeType size_type;
|
||||
};
|
||||
|
||||
@@ -652,6 +652,31 @@ TEST(Array, Copyability)
|
||||
}
|
||||
|
||||
|
||||
TEST(Array, Appending)
|
||||
{
|
||||
typedef Array<FloatSpec<16, CastModeSaturate>, ArrayModeDynamic, 2> A;
|
||||
typedef Array<FloatSpec<16, CastModeSaturate>, ArrayModeDynamic, 257> B;
|
||||
A a;
|
||||
B b;
|
||||
|
||||
a.push_back(1);
|
||||
a.push_back(2);
|
||||
a += b;
|
||||
ASSERT_EQ(2, a.size());
|
||||
ASSERT_EQ(1, a[0]);
|
||||
ASSERT_EQ(2, a[1]);
|
||||
|
||||
b += a;
|
||||
ASSERT_TRUE(a == b);
|
||||
b += a;
|
||||
ASSERT_EQ(4, b.size());
|
||||
ASSERT_EQ(1, b[0]);
|
||||
ASSERT_EQ(2, b[1]);
|
||||
ASSERT_EQ(1, b[2]);
|
||||
ASSERT_EQ(2, b[3]);
|
||||
}
|
||||
|
||||
|
||||
TEST(Array, Strings)
|
||||
{
|
||||
typedef Array<IntegerSpec<8, SignednessUnsigned, CastModeSaturate>, ArrayModeDynamic, 32> A8;
|
||||
|
||||
@@ -47,7 +47,7 @@ static void stringServiceServerCallback(const uavcan::ReceivedDataStructure<root
|
||||
root_ns_a::StringService::Response& rsp)
|
||||
{
|
||||
rsp.string_response = "Request string: ";
|
||||
rsp.string_response += req.string_request.c_str();
|
||||
rsp.string_response += req.string_request;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user