From 7db74eb991855c55143e96462d01f5fb256d1ef1 Mon Sep 17 00:00:00 2001 From: neingeist Date: Mon, 18 Aug 2014 23:45:07 +0200 Subject: [PATCH] do some whitespace janitor work --- accumulate.cpp | 2 +- array-bounds.cpp | 14 +++++++------- auto_ptr.cpp | 4 ++-- casts.cpp | 13 ++++--------- classes.cpp | 26 +++++++++++++------------- future.cpp | 9 +++++---- list-initializers.cpp | 2 -- object-lifetime.cpp | 4 ++-- return-type-deduction.cpp | 2 +- rtti.cpp | 5 +++-- shared_ptr.cpp | 16 ++++++++-------- typetest.cpp | 5 ++--- unique_ptr.cpp | 2 +- 13 files changed, 49 insertions(+), 55 deletions(-) diff --git a/accumulate.cpp b/accumulate.cpp index f57cc2a..2e1707b 100644 --- a/accumulate.cpp +++ b/accumulate.cpp @@ -14,7 +14,7 @@ struct myclass { int main() { int init = 100; - int numbers[] = {10,20,30}; + int numbers[] = {10, 20, 30}; int res; std::cout << "using default accumulate: "; diff --git a/array-bounds.cpp b/array-bounds.cpp index 01b9dda..f4fb7b0 100644 --- a/array-bounds.cpp +++ b/array-bounds.cpp @@ -6,12 +6,12 @@ void classic() { int array[2]; array[0] = 1; array[1] = 2; - array[3] = 3; // <- clang++ -Warray-bounds warns about this + array[3] = 3; // <- clang++ -Warray-bounds warns about this int n = 10; - std::cout << array[3] << std::endl; // no warning! - std::cout << array[4] << std::endl; // no warning! - std::cout << array[n-1] << std::endl; // no warning! + std::cout << array[3] << std::endl; // no warning! + std::cout << array[4] << std::endl; // no warning! + std::cout << array[n-1] << std::endl; // no warning! } void std_array() { @@ -22,7 +22,7 @@ void std_array() { // whoopsie array[2] = 3; - for(auto &e: array) { + for (auto &e : array) { std::cout << e << " "; } std::cout << std::endl; @@ -44,10 +44,10 @@ void std_vector() { } vector.resize(10); vector.at(2) = 3; - vector[1] = 2; // should now work + vector[1] = 2; // should now work // vector[3] = 3; // SEGFAULT - for(auto &e: vector) { + for (auto &e : vector) { std::cout << e << " "; } std::cout << std::endl; diff --git a/auto_ptr.cpp b/auto_ptr.cpp index 7d7a175..f789a5b 100644 --- a/auto_ptr.cpp +++ b/auto_ptr.cpp @@ -13,9 +13,9 @@ int main() { y = x; - std::cout << x.get() << std::endl; // Print NULL + std::cout << x.get() << std::endl; // Print NULL assert(x.get() == NULL); - std::cout << y.get() << std::endl; // Print non-NULL address i + std::cout << y.get() << std::endl; // Print non-NULL address i assert(y.get() != NULL); return 0; diff --git a/casts.cpp b/casts.cpp index 91607ef..53796d0 100644 --- a/casts.cpp +++ b/casts.cpp @@ -3,11 +3,9 @@ class mybase { protected: - std::string ids; public: - mybase(std::string ids) : ids(ids) {} @@ -17,16 +15,13 @@ class mybase { }; class myclass : public mybase { - public: - myclass(std::string ids) : mybase(ids) {} void foo() { std::cout << "i'm a myclass! ids: " << ids << std::endl; } - }; void nocast(myclass* x) { @@ -40,8 +35,8 @@ void ccast(void* x) { } void staticcast(void* x) { - // C++ static_cast. When I *know* it's myclass*, and want to revert an implicit - // conversion. + // C++ static_cast. When I *know* it's myclass*, and want to revert an + // implicit conversion. myclass* foo = static_cast(x); foo->foo(); } @@ -64,11 +59,11 @@ int main() { std::cout << "== ccast" << std::endl; ccast(&a); - ccast(&base); // XXX actually works! + ccast(&base); // XXX actually works! std::cout << "== staticcast" << std::endl; staticcast(&a); - staticcast(&base); // XXX actually works! + staticcast(&base); // XXX actually works! std::cout << "== dynamiccast" << std::endl; dynamiccast(&a); diff --git a/classes.cpp b/classes.cpp index dcfccf8..f59a23c 100644 --- a/classes.cpp +++ b/classes.cpp @@ -63,37 +63,37 @@ int main() { callptr(&animal); std::cout << "== cat" << std::endl; - animal = cat; // <- lol, operator + animal = cat; // <- lol, operator animal.makeSound(); call(cat); - callref(cat); // <- meow - callref(animal); // <- generic - callptr(&cat); // <- meow + callref(cat); // <- meow + callref(animal); // <- generic + callptr(&cat); // <- meow std::cout << "== cow" << std::endl; - animal = cow; // <- lol, operator + animal = cow; // <- lol, operator animal.makeSound(); call(cow); - callref(cow); // <- mooh - callptr(&cow); // <- mooh + callref(cow); // <- mooh + callptr(&cow); // <- mooh std::cout << "== refs" << std::endl; Animal &aref = cat; - aref.makeSound(); // <- meow - aref = cow; // <- lol, operator - aref.makeSound(); // <- meow, still + aref.makeSound(); // <- meow + aref = cow; // <- lol, operator + aref.makeSound(); // <- meow, still std::cout << "== vector:" << std::endl; // Does nothing: - std::vector animals = { cat, cow }; // <- Copies - for (auto &a: animals) { + std::vector animals = { cat, cow }; // <- Copies + for (auto &a : animals) { a.makeSound(); } std::cout << "== vector:" << std::endl; // Meow? Mooh. std::vector animalptrs = { &cat, &cow }; - for (auto &a: animalptrs) { + for (auto &a : animalptrs) { a->makeSound(); } } diff --git a/future.cpp b/future.cpp index 7de407f..913ced1 100644 --- a/future.cpp +++ b/future.cpp @@ -6,8 +6,8 @@ #include // std::chrono::milliseconds // a non-optimized way of checking for prime numbers. -bool is_prime (long int x) { - for (long int i=2; i fut = std::async(std::launch::async, is_prime, p2); - std::cout << "just getting the result, doing an implicit wait():" << std::endl; + std::cout << "just getting the result, doing an implicit wait():"; + std::cout << std::endl; bool x = fut.get(); std::cout << p2 << " " << (x?"is":"is not") << " prime." << std::endl; } -int main () { +int main() { explicitly_waiting(); implicitly_waiting(); return 0; diff --git a/list-initializers.cpp b/list-initializers.cpp index 8475b68..6d3b028 100644 --- a/list-initializers.cpp +++ b/list-initializers.cpp @@ -7,7 +7,6 @@ using namespace std; int main() { - // notice how the lists are nested to match the templates' parameters: map>> name_languages_year { {"Dennis Ritchie", {{"B", 1969}, {"C", 1973}}}, @@ -27,5 +26,4 @@ int main() { // prints 'Lisp': cout << name_languages_year["John McCarthy"].at(0).first << endl; - } diff --git a/object-lifetime.cpp b/object-lifetime.cpp index cd6cb64..0300292 100644 --- a/object-lifetime.cpp +++ b/object-lifetime.cpp @@ -1,12 +1,12 @@ #include struct A { - A() { puts("A()"); } + A() { puts("A()"); } ~A() { puts("~A()"); } }; struct B { - B() { puts("B()"); } + B() { puts("B()"); } ~B() { puts("~B()"); } }; diff --git a/return-type-deduction.cpp b/return-type-deduction.cpp index 14715bf..e795097 100644 --- a/return-type-deduction.cpp +++ b/return-type-deduction.cpp @@ -1,4 +1,4 @@ -/* http://en.wikipedia.org/wiki/C++14 */ +// http://en.wikipedia.org/wiki/C++14 #include #include diff --git a/rtti.cpp b/rtti.cpp index ad0d2d8..75806ad 100644 --- a/rtti.cpp +++ b/rtti.cpp @@ -32,7 +32,8 @@ class Hammer : public Tool { } void use(Nail nail) { - std::cout << "The nail is " << nail.getLength() << " cm long" << std::endl; + std::cout << "The nail is " << nail.getLength() << " cm long" + << std::endl; } }; @@ -50,7 +51,7 @@ void useSomeTool(Tool &tool) { std::cout << "Look, it's a " << typeid(tool).name() << "!" << std::endl; // XXX What about subclasses of Hammer? - if(typeid(tool) == typeid(Hammer)) { + if (typeid(tool) == typeid(Hammer)) { std::cout << "Stop! "; } tool.use(); diff --git a/shared_ptr.cpp b/shared_ptr.cpp index 35f0056..5982fb4 100644 --- a/shared_ptr.cpp +++ b/shared_ptr.cpp @@ -9,7 +9,7 @@ void shared_ptr() { std::cout << __FUNCTION__ << std::endl; std::shared_ptr p1(new int(5)); - std::shared_ptr p2 = p1; // Both now own the memory. + std::shared_ptr p2 = p1; // Both now own the memory. assert(p1.use_count() == 2); // Memory still exists, due to p2: @@ -29,7 +29,7 @@ void shared_ptr_container() { std::cout << __FUNCTION__ << std::endl; std::shared_ptr p1(new int(5)); - std::shared_ptr p2 = p1; // Both now own the memory. + std::shared_ptr p2 = p1; // Both now own the memory. assert(p1.use_count() == 2); std::vector> v; @@ -49,20 +49,20 @@ void weak_ptr() { std::cout << __FUNCTION__ << std::endl; std::shared_ptr p1(new int(5)); - std::weak_ptr wp1 = p1; // p1 owns the memory. + std::weak_ptr wp1 = p1; // p1 owns the memory. { - std::shared_ptr p2 = wp1.lock(); //Now p1 and p2 own the memory. + std::shared_ptr p2 = wp1.lock(); // Now p1 and p2 own the memory. assert(p2 != NULL); - if (p2) { // As p2 is initialized from a weak pointer, - // you have to check if the memory still exists! + if (p2) { // As p2 is initialized from a weak pointer, + // you have to check if the memory still exists! // Do something with p2 } - } // p2 is destroyed. Memory is owned by p1. + } // p2 is destroyed. Memory is owned by p1. assert(wp1.lock() != NULL); assert(wp1.use_count() == 1); - p1.reset(); // Memory is deleted. + p1.reset(); // Memory is deleted. assert(wp1.lock() == NULL); assert(wp1.use_count() == 0); diff --git a/typetest.cpp b/typetest.cpp index c7cc2b7..f48e395 100644 --- a/typetest.cpp +++ b/typetest.cpp @@ -1,8 +1,7 @@ #include #include -int main() -{ +int main() { int someInteger = 256; short someShort; long someLong; @@ -16,7 +15,7 @@ int main() assert(someInteger == 514); someShort = (short) someInteger; - assert((int) someShort == 514); // (short more than 1 byte) + assert((int) someShort == 514); // (short more than 1 byte) someLong = someShort * 10000; assert(someLong == 5140000l); diff --git a/unique_ptr.cpp b/unique_ptr.cpp index 2e79e90..b80adb7 100644 --- a/unique_ptr.cpp +++ b/unique_ptr.cpp @@ -26,7 +26,7 @@ void container() { v.push_back(std::move(q)); assert(q == NULL); - for(auto &e: v) { + for (auto &e : v) { std::cout << *e << std::endl; } }