Пример #1
0
int main()
{
	StrBlob b1 = {"what", "when", "how"};
	cout << b1.use_count() << endl;
	StrBlob b2 = b1; // copy initialization
	cout << b2.use_count() << endl;
	b2.push_back("whether"); // won't influence the value of b1
	cout << b1.back() << endl;
	cout << b2.back() << endl;
	{
		StrBlob b2 = {"a", "an", "the"};
		b1 = b2; // assign local b2 to b1
		b2.push_back("about");
		cout << b2.use_count() << endl;
	}
	b1 = b1; // assign to itself
	cout << b1.use_count() << endl; // reference count is still 1
	const StrBlob b3({"and", "or", "not"});
	cout << b3.front() << " "<< b3.back() << endl;
	StrBlob b4 = b3;
	cout << b4.use_count() << endl;
	try
	{
		StrBlob b5;
		cout << b5.front();
	}
	catch(out_of_range err)
	{
		cout << err.what() << endl;
	}
	return 0;
}
Пример #2
0
void testStrBlob(const StrBlob &sb) {
  try {
    std::cout << "front: " << sb.front() << " back: " << sb.back() << std::endl;
  } catch (std::out_of_range err) {
    std::cerr << err.what() << " out of range" << std::endl;
  } catch (std::exception err) {
    std::cerr << err.what() << std::endl;
  }
}
Пример #3
0
int main()
{
	const StrBlob cstrblob{ "come", "on", "liwen" };
	StrBlob strblob{ "how", "are","you", "chii" };

	std::cout << cstrblob.front() << " " << cstrblob.back() << std::endl;
	strblob.back() = "liwen";
	strblob.pop_back();
	std::cout << strblob.front() << " " << strblob.back() << std::endl;
}
int main()
{
	StrBlob sb{ "hello", "world" };
	const StrBlob csb{ "const", "hello", "world", "aaa" };

	std::cout << "sb : " << sb.front() << " " << sb.back() << std::endl;
	std::cout << "csb : " << csb.front() << " " << csb.back() << std::endl;
	
	return 0;
}
Пример #5
0
void pra_12_2()
{
	StrBlob b1;
	{
		StrBlob b2 = { "taopeng", "oo", "hehe" };
		b1 = b2;
		b1.push_back("about");
		cout << b2.size() << endl;
	}
	cout << b1.size() << endl;
	cout << b1.front() << " " << b1.back() << endl;

	const StrBlob b3 = b1;
	cout << b3.front() << " " << b3.back() << endl;
}
int main(int argc, char const *argv[])
{
	StrBlob b1;
	{
		StrBlob b2 = {"a", "asd", "qwed"};
		b1 = b2;
		b2.push_back("about");
		cout << "b2.size() = " << b2.size() << endl;
	}
	cout << "b1.size() = " << b1.size() << endl;
	cout << "b1.front() = " << b1.front() << endl;

	const StrBlob b3 = b1;
	cout << "b3.front() = " << b3.front() 
		<< " "
		<< "b3.back() = " << b3.back() 
		<< endl;
		
	return 0;
}
int main(int argc, char **argv)
{
	StrBlob b1;
	{
		StrBlob b2 = { "a", "an", "the" };
		b1 = b2;
		b2.push_back("about");
		cout << b2.size() << endl;
	}
	cout << b1.size() << endl;
	cout << b1.front() << "  " << b1.back() << endl;

	const StrBlob b3 = b1;
	cout << b3.front() << "  " << b3.back() << endl;

	for (auto it = b1.begin(); neq(it, b1.end()); it.incr())
	{
		cout << it.deref() << endl;
	}

	system("pause");
	return 0;
}