Exemplo n.º 1
0
void print(const StrVec &sv) {
  std::cout << "<" << &sv << "> size: " << sv.size()
            << " capacity: " << sv.capacity() << " contents:";
  for (const auto &s : sv)
    std::cout << " <" << s << ">";
  std::cout << std::endl;
}
Exemplo n.º 2
0
int main() {
  StrVec sv;
  print(sv);

  sv.push_back("s1"); print(sv);
  sv.push_back("s2"); print(sv);
  sv.push_back("s3"); print(sv);
  sv.push_back("s4"); print(sv);
  sv.push_back("s5"); print(sv);

  {
    StrVec sv2(sv); print(sv2);
    sv2.push_back("s6"); print(sv); print(sv2);
    sv.pop_back(); print(sv); print(sv2);
    sv = sv2; print(sv); print(sv2);
  }

  sv.reserve(sv.capacity() / 2); print(sv);
  sv.reserve(sv.capacity() * 2); print(sv);

  sv.resize(sv.size() + 2); print(sv);
  sv.resize(sv.size() + 2, "s7"); print(sv);
  sv.resize(sv.size() - 2); print(sv);
  sv.resize(sv.size() - 2, "s7"); print(sv);

  return 0;
}
Exemplo n.º 3
0
int main()
{
    StrVec vec;
    vec.reserve(6);
    std::cout << "capacity(reserve to 6): " << vec.capacity() << std::endl;

    vec.reserve(4);
    std::cout << "capacity(reserve to 4): " << vec.capacity() << std::endl;

    vec.push_back("hello");
    vec.push_back("world");

    vec.resize(4);

    for (auto i = vec.begin(); i != vec.end(); ++i)
        std::cout << *i << std::endl;
    std::cout << "-EOF-" << std::endl;

    vec.resize(1);

    for (auto i = vec.begin(); i != vec.end(); ++i)
        std::cout << *i << std::endl;
    std::cout << "-EOF-" << std::endl;

    StrVec vec_list{ "hello", "world", "pezy" };

    for (auto i = vec_list.begin(); i != vec_list.end(); ++i)
        std::cout << *i << " ";
    std::cout << std::endl;

    // Test operator==

    const StrVec const_vec_list{ "hello", "world", "pezy" };
    if (vec_list == const_vec_list)
        for (const auto &str : const_vec_list)
            std::cout << str << " ";
    std::cout << std::endl;

    // Test operator<
    const StrVec const_vec_list_small{ "hello", "pezy", "ok" };
    std::cout << (const_vec_list_small < const_vec_list) << std::endl;

    // Test []
    std::cout << const_vec_list_small[1] << std::endl;
}
Exemplo n.º 4
0
int main()
{
	StrVec vec = { "aaa", "bbb", "ccc" };
	cout << vec.size() << " " << vec.capacity() << endl;
	vec.push_back("ddd");
	vec.print();
	system("pause");
	return 0;
}
Exemplo n.º 5
0
int main() {
    StrVec words;
    words.push_back("ss");
    words.push_back("sb");
    words.push_back("asf");
    words.push_back("safasfd");
    words.push_back("asfas");
    std::cout<<words.size()<<std::endl;
    //words = StrVec();
    //words = words;
    std::cout<<"cap "<<words.capacity()<<std::endl;
    std::cout<<"sz "<<words.size()<<std::endl;
    for_each(words.begin(), words.end(), [](const std::string &s){std::cout<<s<<std::endl;});
    std::cout<<"exit"<<std::endl;
}