Array<>::operator+=(Array<>) implementation and test

This commit is contained in:
Pavel Kirienko
2014-03-14 02:19:57 +04:00
parent 62abf10f65
commit 0f1b124086
3 changed files with 38 additions and 1 deletions
@@ -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;
};
+25
View File
@@ -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;
+1 -1
View File
@@ -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;
}