本文整理汇总了C++中TArray::nthAddr方法的典型用法代码示例。如果您正苦于以下问题:C++ TArray::nthAddr方法的具体用法?C++ TArray::nthAddr怎么用?C++ TArray::nthAddr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TArray
的用法示例。
在下文中一共展示了TArray::nthAddr方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_insert_remove
void test_insert_remove(void)
{
TArray<int> arr;
arr.initialize(2);
CPPUNIT_ASSERT_EQUAL((hyu32)0, arr.size());
HMD_ASSERT_HALT(arr.insert(1));
arr.insert(0) = 10;
CPPUNIT_ASSERT_EQUAL((hyu32)1, arr.size());
CPPUNIT_ASSERT_EQUAL(10, arr[0]);
arr.insert(0) = 20;
CPPUNIT_ASSERT_EQUAL((hyu32)2, arr.size());
CPPUNIT_ASSERT_EQUAL(20, arr[0]);
CPPUNIT_ASSERT_EQUAL(10, arr[1]);
arr.insert(1) = 30;
CPPUNIT_ASSERT_EQUAL((hyu32)3, arr.size());
CPPUNIT_ASSERT_EQUAL(20, arr[0]);
CPPUNIT_ASSERT_EQUAL(30, arr[1]);
CPPUNIT_ASSERT_EQUAL(10, arr[2]);
arr.insert(3) = 40;
CPPUNIT_ASSERT_EQUAL((hyu32)4, arr.size());
CPPUNIT_ASSERT_EQUAL(20, arr[0]);
CPPUNIT_ASSERT_EQUAL(30, arr[1]);
CPPUNIT_ASSERT_EQUAL(10, arr[2]);
CPPUNIT_ASSERT_EQUAL(40, arr[3]);
arr.insert(-1) = 50;
CPPUNIT_ASSERT_EQUAL((hyu32)5, arr.size());
CPPUNIT_ASSERT_EQUAL(20, arr[0]);
CPPUNIT_ASSERT_EQUAL(30, arr[1]);
CPPUNIT_ASSERT_EQUAL(10, arr[2]);
CPPUNIT_ASSERT_EQUAL(50, arr[3]);
CPPUNIT_ASSERT_EQUAL(40, arr[4]);
arr.remove(2);
CPPUNIT_ASSERT_EQUAL((hyu32)4, arr.size());
CPPUNIT_ASSERT_EQUAL(20, arr[0]);
CPPUNIT_ASSERT_EQUAL(30, arr[1]);
CPPUNIT_ASSERT_EQUAL(50, arr[2]);
CPPUNIT_ASSERT_EQUAL(40, arr[3]);
arr.remove(-3);
CPPUNIT_ASSERT_EQUAL((hyu32)3, arr.size());
CPPUNIT_ASSERT_EQUAL(20, arr[0]);
CPPUNIT_ASSERT_EQUAL(50, arr[1]);
CPPUNIT_ASSERT_EQUAL(40, arr[2]);
HMD_ASSERT_HALT(arr.remove(3));
HMD_ASSERT_HALT(arr.remove(-4));
int* p = arr.nthAddr(3);
int* q = arr.addSpaces(2);
CPPUNIT_ASSERT_EQUAL((hyu32)5, arr.size());
CPPUNIT_ASSERT_EQUAL(p, q);
}
示例2: test_array
void test_array(void)
{
int dat[10] = { 100, 110, 120, -130, 140, -15000, 16000, 1700, 18, 19000 };
TArray<int> arr;
arr.initialize(0);
CPPUNIT_ASSERT_EQUAL((int*)NULL, arr.m_contents);
CPPUNIT_ASSERT_EQUAL((hyu32)0, arr.size());
CPPUNIT_ASSERT_EQUAL((hyu32)0, arr.m_capacity);
arr.initialize(2);
CPPUNIT_ASSERT(arr.m_contents != NULL);
CPPUNIT_ASSERT_EQUAL((hyu32)0, arr.size());
CPPUNIT_ASSERT_EQUAL((hyu32)2, arr.m_capacity);
arr.add(dat, 5);
CPPUNIT_ASSERT_EQUAL((hyu32)5, arr.size());
CPPUNIT_ASSERT_EQUAL(100, arr[0]);
CPPUNIT_ASSERT_EQUAL(140, arr[4]);
arr.fill(7);
CPPUNIT_ASSERT_EQUAL(7, arr[0]);
CPPUNIT_ASSERT_EQUAL(7, arr[4]);
CPPUNIT_ASSERT(arr.checkIndex(100));
CPPUNIT_ASSERT(arr.checkIndex(-5));
CPPUNIT_ASSERT(! arr.checkIndex(-6));
arr[2] = 222;
CPPUNIT_ASSERT_EQUAL(222, *(arr.nthAddr(2)));
arr.subst(20, 202020, -1);
CPPUNIT_ASSERT_EQUAL((hyu32)21, arr.size());
CPPUNIT_ASSERT_EQUAL(-1, arr[5]);
CPPUNIT_ASSERT_EQUAL(-1, arr[19]);
CPPUNIT_ASSERT_EQUAL(202020, arr[20]);
arr.add(&dat[5], 5);
arr.add(123);
arr.add(456);
CPPUNIT_ASSERT_EQUAL((hyu32)28, arr.size());
CPPUNIT_ASSERT_EQUAL(-15000, arr[21]);
CPPUNIT_ASSERT_EQUAL(19000, arr[25]);
CPPUNIT_ASSERT_EQUAL(123, arr[26]);
CPPUNIT_ASSERT_EQUAL(456, arr[27]);
int x = 222;
CPPUNIT_ASSERT_EQUAL(2, arr.issue(x));
x = 202020;
CPPUNIT_ASSERT_EQUAL(20, arr.issue(x));
x = 123;
CPPUNIT_ASSERT_EQUAL(26, arr.issue(x));
CPPUNIT_ASSERT_EQUAL((hyu32)28, arr.size());
x = 98765;
CPPUNIT_ASSERT_EQUAL(28, arr.issue(x));
CPPUNIT_ASSERT_EQUAL(98765, arr[28]);
arr.clear();
CPPUNIT_ASSERT_EQUAL((hyu32)0, arr.size());
hyu32 capa = arr.m_capacity;
arr.reserve(capa);
CPPUNIT_ASSERT(capa != arr.m_capacity);
}