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; }
TEST(CxxCase, StringBlobNoIteratorSupport) { using namespace cxx_case_strblob; { StrBlob sb{"one", "two", "three", "four"}; EXPECT_THAT(sb.size(), 4); EXPECT_THAT(sb.front(), "one"); EXPECT_THAT(sb.back(), "four"); sb.push_back("five"); EXPECT_THAT(sb.size(), 5); EXPECT_THAT(sb.front(), "one"); EXPECT_THAT(sb.back(), "five"); } { StrBlob sb; EXPECT_THAT(sb.size(), 0); EXPECT_THROW(sb.front(), std::out_of_range); } }
TEST(CxxCase, StringBlobTemplate) { using namespace cxx_case_strblob_template; { StrBlob<std::string> sb{"one", "two", "three", "four"}; EXPECT_THAT(sb.size(), 4); EXPECT_THAT(sb.front(), "one"); EXPECT_THAT(sb.back(), "four"); sb.push_back("five"); EXPECT_THAT(sb.size(), 5); EXPECT_THAT(sb.front(), "one"); EXPECT_THAT(sb.back(), "five"); } { StrBlob<std::string> sb; EXPECT_THAT(sb.size(), 0); EXPECT_THROW(sb.front(), std::out_of_range); } }
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; } }
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; }
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; }