本文整理汇总了C++中MyVector::size方法的典型用法代码示例。如果您正苦于以下问题:C++ MyVector::size方法的具体用法?C++ MyVector::size怎么用?C++ MyVector::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyVector
的用法示例。
在下文中一共展示了MyVector::size方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: result
MyVector<T> operator* (const MyVector<T>& a, const MyVector<T>& b){
MyVector<T> result(a.size());
for (std::size_t s= 0; s <= a.size(); ++s){
result[s]= a[s]*b[s];
}
return result;
}
示例2: main
int main()
{
// Create a default vector
MyVector sam;
// push some data into sam
cout << "\nPushing three values into sam";
sam.push_back(TEST_VALUE1);
sam.push_back(TEST_VALUE2);
sam.push_back(TEST_VALUE3);
cout << "\nThe values in sam are: ";
// test for out of bounds condition here
// and test exception
for (int i = 0; i < sam.size() + 1; i++)
{
try
{
cout << sam.at(i) << " ";
}
catch (int badIndex)
{
cout << "\nOut of bounds at index " << badIndex << endl;
}
}
cout << "\n--------------\n";
// clear sam and display its size and capacity
sam.clear();
cout << "\nsam has been cleared.";
cout << "\nSam's size is now " << sam.size();
cout << "\nSam's capacity is now " << sam.capacity() << endl;
cout << "---------------\n";
// Push 12 values into the vector - it should grow
cout << "\nPush 12 values into sam.";
for (int i = 0; i < MAX; i++)
sam.push_back(i);
cout << "\nSam's size is now " << sam.size();
cout << "\nSam's capcacity is now " << sam.capacity() << endl;
cout << "---------------\n";
cout << "\nTest to see if contents are correct...";
// display the values in the vector
for (int i = 0; i < sam.size(); i++)
{
cout << sam.at(i) << " ";
}
cout << "\n--------------\n";
cout << "\n\nTest Complete...";
cout << endl;
system("PAUSE");
return 0;
}
示例3: displayMyVector
void displayMyVector(MyVector& vec)
{
printf("display my vector, vector size:%d\n", vec.size());
for(unsigned int i = 0; i < vec.size(); i++)
{
Dynamic::Var var = vec.at(i);
Poco::DynamicStruct ds = var.extract<DynamicStruct>();
printf("Array[%u]:%s\n", i, ds.toString().c_str());
}
}
示例4: TestConcurrentGrowBy
//! Test concurrent invocations of method concurrent_vector::grow_by
void TestConcurrentGrowBy( int nthread ) {
int m = 100000;
MyVector v;
tbb::parallel_for( tbb::blocked_range<int>(0,m,1000), GrowBy(v) );
ASSERT( v.size()==size_t(m), NULL );
// Verify that v is a permutation of 0..m
int inversions = 0;
bool* found = new bool[m];
memset( found, 0, m );
for( int i=0; i<m; ++i ) {
int index = v[i].bar();
ASSERT( !found[index], NULL );
found[index] = true;
if( i>0 )
inversions += v[i].bar()<v[i-1].bar();
}
for( int i=0; i<m; ++i ) {
ASSERT( found[i], NULL );
ASSERT( nthread>1 || v[i].bar()==i, "sequential execution is wrong" );
}
delete[] found;
if( nthread>1 && inversions<m/10 )
std::printf("Warning: not much concurrency in TestConcurrentGrowBy\n");
}
示例5: totalSize
/**
* Gets the total number of elements in the table.
* @return the total number of elements in the table.
*/
size_t totalSize() const {
size_t k = 0;
for (size_t i = 0; i < table.size(); ++i) {
k += table[i].size();
}
return k;
}
示例6: TestContainerConstructor
//..
// Finally, we demonstrate that the correct constructors are called when
// invoked with appropriate arguments:
//..
void TestContainerConstructor()
{
const unsigned int TEST_DATA[] = { 1, 2, 3, 4, 5 };
const MyVector<unsigned int> x(&TEST_DATA[0], &TEST_DATA[5]);
const MyVector<unsigned int> y(13, 42);
ASSERT(5 == x.size());
for (int i = 0; i != 5; ++i) {
ASSERT(TEST_DATA[i] == x[i]);
}
ASSERT(42 == y.size());
for (int i = 0; i != 42; ++i) {
ASSERT(13 == y[i]);
}
}
示例7:
TEST(vector, size) {
ASSERT_EQ(myvec.size(), vec.size());
ASSERT_EQ(myvec.max_size(), vec.max_size());
ASSERT_EQ(myvec.empty(), vec.empty());
ASSERT_EQ(myempty_vec.size(), empty_vec.size());
ASSERT_EQ(myempty_vec.max_size(), empty_vec.max_size());
ASSERT_EQ(myempty_vec.empty(), empty_vec.empty());
ASSERT_EQ(myvec.capacity(), vec.capacity());
}
示例8: main
int main()
{
MyVector<int> intVector;
MyVector<string> stringVector;
intVector.push_back(3);
intVector.push_back(4);
stringVector.push_back("hi");
stringVector.push_back("bye");
for (int i = 0; i < intVector.size(); i++) {
cout << intVector[i] << endl;
}
for (int i = 0; i < stringVector.size(); i++) {
cout << stringVector[i] << endl;
}
return 0;
}
示例9: MyVector
MyVector operator*(const MyMatrix& lhs ,const MyVector& rhs) {
MyVector y = MyVector(lhs.rows_);
if (lhs.columns_ == rhs.size()) {
for(long long int i = 1; i <= lhs.rows_; i++) {
for(long long int j = 1; j <= lhs.columns_; j++) {
y[i-1] += rhs[j-1] *lhs.at(i,j);
}
}
} else {
cout << "Matrix-Vektor-Multiplikation nicht möglich Dimensionen stimmen nicht überein!" << endl;
}
return y;
}
示例10: copy
void MyVector::copy(const MyVector& rho)
{
// Copy atomic attributes
currentSize = rho.size();
currentCapacity = rho.capacity();
// Copy data payload
payload = new int[currentCapacity];
for (int i = 0; i < currentSize; i++)
{
payload[i] = rho.at(i);
}
}
示例11: main
int main ()
{
//Remove shared memory on construction and destruction
struct shm_remove
{
shm_remove() { shared_memory_object::remove("MySharedMemory"); }
~shm_remove(){ shared_memory_object::remove("MySharedMemory"); }
} remover;
managed_shared_memory segment(
create_only,
"MySharedMemory", //segment name
65536); //segment size in bytes
//Construct shared memory vector
MyVector *myvector =
segment.construct<MyVector>("MyVector")
(IntAllocator(segment.get_segment_manager()));
//Fill vector
myvector->reserve(100);
for(int i = 0; i < 100; ++i){
myvector->push_back(i);
}
//Create the vectorstream. To create the internal shared memory
//basic_string we need to pass the shared memory allocator as
//a constructor argument
MyVectorStream myvectorstream(CharAllocator(segment.get_segment_manager()));
//Reserve the internal string
myvectorstream.reserve(100*5);
//Write all vector elements as text in the internal string
//Data will be directly written in shared memory, because
//internal string's allocator is a shared memory allocator
for(std::size_t i = 0, max = myvector->size(); i < max; ++i){
myvectorstream << (*myvector)[i] << std::endl;
}
//Auxiliary vector to compare original data
MyVector *myvector2 =
segment.construct<MyVector>("MyVector2")
(IntAllocator(segment.get_segment_manager()));
//Avoid reallocations
myvector2->reserve(100);
//Extract all values from the internal
//string directly to a shared memory vector.
std::istream_iterator<int> it(myvectorstream), itend;
std::copy(it, itend, std::back_inserter(*myvector2));
//Compare vectors
assert(std::equal(myvector->begin(), myvector->end(), myvector2->begin()));
//Create a copy of the internal string
MyString stringcopy (myvectorstream.vector());
//Now we create a new empty shared memory string...
MyString *mystring =
segment.construct<MyString>("MyString")
(CharAllocator(segment.get_segment_manager()));
//...and we swap vectorstream's internal string
//with the new one: after this statement mystring
//will be the owner of the formatted data.
//No reallocations, no data copies
myvectorstream.swap_vector(*mystring);
//Let's compare both strings
assert(stringcopy == *mystring);
//Done, destroy and delete vectors and string from the segment
segment.destroy_ptr(myvector2);
segment.destroy_ptr(myvector);
segment.destroy_ptr(mystring);
return 0;
}
示例12: numRows
/**
* Gets the number of rows.
* @return the number of rows.
*/
int numRows() const {
return table.size();
}