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); } }
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); } }
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() { std::ifstream ifs("../data/book.txt"); StrBlob blob; for (std::string str; std::getline(ifs, str); ) blob.push_back(str); for (StrBlobPtr pbeg(blob.begin()), pend(blob.end()); pbeg != pend; pbeg.incr()) std::cout << pbeg.deref() << 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; }
int main() { StrBlob v = {"Like", "a", "thunderbolt", "he", "falls"}; StrBlobPtr p1(v), p2 = p1, p3 = p1; ConstStrBlobPtr pc(v); for(size_t i = 0; i != v.size(); ++i) std::cout << *(p1 + i) << " "; std::cout << std::endl; p2 += 2; std::cout << *pc << std::endl; std::cout << pc->size() << std::endl; return 0; }
int main() { StrBlob sb1; StrBlob sb2{"Hello", "World"}; const StrBlob csb1; testStrBlob(csb1); std::cout << std::endl; const StrBlob csb2{"This", "Blob"}; testStrBlob(csb2); std::cout << std::endl; ConstStrBlobPtr csbp1; testConstStrBlobPtr(csbp1); std::cout << std::endl; ConstStrBlobPtr sbp2(sb1); testConstStrBlobPtr(sbp2); std::cout << std::endl; ConstStrBlobPtr sbp3(sb1, sb1.size()); testConstStrBlobPtr(sbp3); std::cout << std::endl; ConstStrBlobPtr sbp4(sb2); testConstStrBlobPtr(sbp4); std::cout << std::endl; ConstStrBlobPtr sbp5(sb2, sb2.size()); testConstStrBlobPtr(sbp5); std::cout << std::endl; ConstStrBlobPtr csbp2(csb1); testConstStrBlobPtr(csbp2); std::cout << std::endl; ConstStrBlobPtr csbp3(csb1, csb1.size()); testConstStrBlobPtr(csbp3); std::cout << std::endl; ConstStrBlobPtr csbp4(csb2); testConstStrBlobPtr(csbp4); std::cout << std::endl; ConstStrBlobPtr csbp5(csb2, csb2.size()); testConstStrBlobPtr(csbp5); std::cout << std::endl; return 0; }
int main() { ifstream input("file.txt"); StrBlob b; string s; while (getline(input, s)) b.push_back(s); for (auto it = b.begin(); neq(it, b.end()); it.incr()) cout << it.deref() << 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() { StrBlob v = {"Like", "a", "thunderbolt", "he", "falls"}; StrBlobPtr p1(v), p2 = p1, p3 = p1; ConstStrBlobPtr pc(v); for(size_t i = 0; i != v.size(); ++i) std::cout << (p1 + i).deref() << " "; std::cout << std::endl; p2 += 2; std::cout << p2.deref() << std::endl; p3[4] = "falls."; pc[4] = "fall"; // wrong, const pointer p2 = 5 + p2; // throw exception std::cout << p2.deref() << std::endl; return 0; }
int main() { string s; StrBlob a; while(cin >> s) { a.push_back(s); } StrBlobPtr sbpBegin = a.begin(); for(unsigned int c = 0; c != a.size();sbpBegin.incr()) { cout << sbpBegin.deref() << endl; ++c; } return 0; }
int main() { ifstream in("ex20.cpp"); StrBlob text; string line; while (in >> line) text.push_back(line); StrBlobPtr ptr = text.begin(); size_t curr = 0; while (curr != text.size()) { cout << ptr.deref() << ' '; ptr.incr(); ++curr; } return 0; }
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 const *argv[]) { StrBlob str; string word; while( cin >> word) { str.push_back(word); } for(auto it = str.begin(); it != str.end(); ++it ) { cout << *it << " "; } cout << endl; StrBlobPtr strPtr(str); 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; }
bool operator<(const StrBlob & lhs, const StrBlob & rhs) { return std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); }