Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- using namespace std;
- typedef vector<char> binary_data;
- static struct binary_data_console
- {
- static void are_equal(const string expected, const binary_data* actual)
- {
- static const char quote = '"';
- const char* binary_data_c_str = actual->data();
- cout << quote << expected << quote;
- cout << (strcmp(expected.c_str(), binary_data_c_str) == 0 ? " == " : " != ");
- cout << quote << binary_data_c_str << quote << endl;
- }
- static void are_equal(const string expected, const shared_ptr<binary_data> actual)
- {
- are_equal(expected, actual.get());
- }
- static void log(const binary_data* vec)
- {
- cout << "data: " << (char*)vec->data() << endl;
- cout << "capacity: " << vec->capacity() << endl;
- cout << "size: " << vec->size() << endl << endl;
- }
- static void log(const shared_ptr<binary_data> vec)
- {
- log(vec.get());
- }
- };
- void pause()
- {
- cout << "Press enter to continue ...";
- cin.ignore();
- }
- int main()
- {
- shared_ptr<binary_data> smart_vec1(new binary_data({ 'A', 'u', 'd', 'i', '\0' }));
- shared_ptr<binary_data> smart_vec2(new binary_data({ 'B', 'M', 'W', '\0' }));
- smart_vec2->resize(smart_vec1->size());
- std::copy(smart_vec1->begin(), smart_vec1->end(), smart_vec2->begin());
- binary_data_console::are_equal("Audi", smart_vec2);
- binary_data_console::log(smart_vec2);
- cout << "-------------------------------------------------" << endl << endl;
- binary_data* vec1 = new binary_data({ 'A', 'u', 'd', 'i', '\0' });
- binary_data* vec2 = new binary_data({ 'B', 'M', 'W', '\0' });
- vec2->resize(vec1->size());
- std::copy(vec1->begin(), vec1->end(), vec2->begin());
- binary_data_console::are_equal("Audi", vec2);
- binary_data_console::log(vec2);
- delete vec1;
- delete vec2;
- pause();
- }
Add Comment
Please, Sign In to add comment