本文整理汇总了C++中FixedArray::push_back方法的典型用法代码示例。如果您正苦于以下问题:C++ FixedArray::push_back方法的具体用法?C++ FixedArray::push_back怎么用?C++ FixedArray::push_back使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FixedArray
的用法示例。
在下文中一共展示了FixedArray::push_back方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: int
TEST(Containers, Array)
{
FixedArray<20, int> array;
FixedArray<20, int> &cref = array;
EXPECT_TRUE(array.empty());
EXPECT_TRUE(cref.empty());
EXPECT_EQ(array.size(), 0);
EXPECT_EQ(cref.size(), 0);
EXPECT_TRUE(array.push_back(100));
EXPECT_FALSE(array.empty());
EXPECT_FALSE(cref.empty());
EXPECT_EQ(array.front(), 100);
EXPECT_EQ(cref.front(), 100);
EXPECT_TRUE(array.pop_back());
EXPECT_FALSE(array.pop_back());
EXPECT_TRUE(array.empty());
EXPECT_TRUE(cref.empty());
EXPECT_TRUE(array.push_back(200));
EXPECT_TRUE(array.push_back(300));
EXPECT_EQ(array.front(), 200);
EXPECT_EQ(cref.front(), 200);
EXPECT_EQ(array.back(), 300);
EXPECT_EQ(cref.back(), 300);
EXPECT_EQ(array.size(), 2);
EXPECT_EQ(cref.size(), 2);
array.clear();
EXPECT_EQ(array.size(), 0);
EXPECT_TRUE(array.empty());
for(unsigned i=0; i< array.capacity(); i++)
EXPECT_TRUE(array.push_back(i));
EXPECT_FALSE(array.push_back(-1));
for(unsigned i=0; i < array.capacity(); i++)
{
EXPECT_EQ(array[i], int(i));
EXPECT_EQ(cref[i], int(i));
}
for(unsigned i=0; i < array.capacity(); i++)
{
EXPECT_EQ(array.back(), int(array.capacity() - 1 - i));
EXPECT_EQ(cref.back(), int(cref.capacity() - 1 - i));
EXPECT_TRUE(array.pop_back());
}
}
示例2:
TEST(Array, ConstructionTest)
{
ConstructionTest::Reset();
FixedArray<20, ConstructionTest> array;
EXPECT_EQ(0, ConstructionTest::Count());
for(int i = 0; i<10; i++)
{
array.push_back( );
EXPECT_EQ(i+1, ConstructionTest::Count());
}
}