do some whitespace janitor work
This commit is contained in:
parent
0e43b30736
commit
7db74eb991
13 changed files with 49 additions and 55 deletions
|
@ -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: ";
|
||||
|
|
|
@ -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;
|
||||
|
@ -47,7 +47,7 @@ void std_vector() {
|
|||
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;
|
||||
|
|
|
@ -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<myclass*>(x);
|
||||
foo->foo();
|
||||
}
|
||||
|
|
|
@ -86,14 +86,14 @@ int main() {
|
|||
std::cout << "== vector<Animal>:" << std::endl;
|
||||
// Does nothing:
|
||||
std::vector<Animal> animals = { cat, cow }; // <- Copies
|
||||
for (auto &a: animals) {
|
||||
for (auto &a : animals) {
|
||||
a.makeSound();
|
||||
}
|
||||
|
||||
std::cout << "== vector<Animal*>:" << std::endl;
|
||||
// Meow? Mooh.
|
||||
std::vector<Animal*> animalptrs = { &cat, &cow };
|
||||
for (auto &a: animalptrs) {
|
||||
for (auto &a : animalptrs) {
|
||||
a->makeSound();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
#include <chrono> // std::chrono::milliseconds
|
||||
|
||||
// a non-optimized way of checking for prime numbers.
|
||||
bool is_prime (long int x) {
|
||||
for (long int i=2; i<x; ++i) {
|
||||
bool is_prime(long int x) {
|
||||
for (long int i = 2; i < x; ++i) {
|
||||
if (x%i == 0) return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -35,12 +35,13 @@ void implicitly_waiting() {
|
|||
long int p2 = 685102597328182763;
|
||||
|
||||
std::future<bool> 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;
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
using namespace std;
|
||||
|
||||
int main() {
|
||||
|
||||
// notice how the lists are nested to match the templates' parameters:
|
||||
map<string, vector<pair<string, int>>> 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;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* http://en.wikipedia.org/wiki/C++14 */
|
||||
// http://en.wikipedia.org/wiki/C++14
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
|
5
rtti.cpp
5
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();
|
||||
|
|
|
@ -52,7 +52,7 @@ void weak_ptr() {
|
|||
std::weak_ptr<int> wp1 = p1; // p1 owns the memory.
|
||||
|
||||
{
|
||||
std::shared_ptr<int> p2 = wp1.lock(); //Now p1 and p2 own the memory.
|
||||
std::shared_ptr<int> 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!
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
int main() {
|
||||
int someInteger = 256;
|
||||
short someShort;
|
||||
long someLong;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue