Skip to content

Commit

Permalink
Use spaces instead of tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
sftrabbit committed Dec 9, 2017
1 parent 5be668e commit 3f5efec
Show file tree
Hide file tree
Showing 47 changed files with 467 additions and 467 deletions.
16 changes: 8 additions & 8 deletions common-tasks/algorithms/copy-range-of-elements.cpp
Expand Up @@ -11,14 +11,14 @@ std::vector<int> target3;
template <typename RangeOfInts>
void foo(RangeOfInts source)
{
std::vector<int> target1{std::begin(source),
std::end(source)};
std::vector<int> target1{std::begin(source),
std::end(source)};

std::copy(std::begin(source), std::end(source),
std::begin(target2));
std::copy(std::begin(source), std::end(source),
std::begin(target2));

std::copy(std::begin(source), std::end(source),
std::back_inserter(target3));
std::copy(std::begin(source), std::end(source),
std::back_inserter(target3));
}

// Copy elements from a range to another range or container.
Expand Down Expand Up @@ -49,6 +49,6 @@ void foo(RangeOfInts source)

int main()
{
std::vector<int> vec = {5, 4, 3, 2, 1};
foo(vec);
std::vector<int> vec = {5, 4, 3, 2, 1};
foo(vec);
}
8 changes: 4 additions & 4 deletions common-tasks/algorithms/count-values-in-range.cpp
Expand Up @@ -6,11 +6,11 @@

int main()
{
std::vector<int> numbers = {1, 2, 3, 5, 6, 3, 4, 1};
std::vector<int> numbers = {1, 2, 3, 5, 6, 3, 4, 1};

int count = std::count(std::begin(numbers),
std::end(numbers),
3);
int count = std::count(std::begin(numbers),
std::end(numbers),
3);
}

// Count the number of occurrences of a particular value in a range of
Expand Down
8 changes: 4 additions & 4 deletions common-tasks/algorithms/sort-range-of-elements.cpp
Expand Up @@ -8,12 +8,12 @@

int main()
{
std::array<int, 5> arr = {3, 4, 1, 5, 2};
std::array<int, 5> arr = {3, 4, 1, 5, 2};

std::sort(std::begin(arr), std::end(arr));
std::sort(std::begin(arr), std::end(arr));

std::sort(std::begin(arr), std::end(arr),
std::greater<int>{});
std::sort(std::begin(arr), std::end(arr),
std::greater<int>{});
}

// Sort elements in a range into a given order.
Expand Down
12 changes: 6 additions & 6 deletions common-tasks/algorithms/swap-containers.cpp
Expand Up @@ -6,15 +6,15 @@

int main()
{
std::vector<int> v1 = { 1, 3, 5, 7 };
std::vector<int> v2 = { 2, 4, 6, 8 };
std::vector<int> v1 = { 1, 3, 5, 7 };
std::vector<int> v2 = { 2, 4, 6, 8 };

std::swap_ranges(std::begin(v1), std::end(v1), std::begin(v2));
std::swap_ranges(std::begin(v1), std::end(v1), std::begin(v2));

v1.swap(v2);
v1.swap(v2);

using std::swap;
swap(v1, v2);
using std::swap;
swap(v1, v2);
}

// Swap the contents of two containers.
Expand Down
8 changes: 4 additions & 4 deletions common-tasks/algorithms/swap-values.cpp
Expand Up @@ -5,11 +5,11 @@

int main()
{
std::string s1 = "Hello";
std::string s2 = "World";
std::string s1 = "Hello";
std::string s2 = "World";

using std::swap;
swap(s1, s2);
using std::swap;
swap(s1, s2);
}

// Swap the values of two objects.
Expand Down
66 changes: 33 additions & 33 deletions common-tasks/classes/copy-and-swap.cpp
Expand Up @@ -4,47 +4,47 @@
#include <utility>

class resource {
int x = 0;
int x = 0;
};

class foo
{
public:
foo()
: p{new resource{}}
{ }
public:
foo()
: p{new resource{}}
{ }

foo(const foo& other)
: p{new resource{*(other.p)}}
{ }
foo(const foo& other)
: p{new resource{*(other.p)}}
{ }

foo(foo&& other)
: p{other.p}
{
other.p = nullptr;
}
foo(foo&& other)
: p{other.p}
{
other.p = nullptr;
}

foo& operator=(foo other)
{
swap(*this, other);
foo& operator=(foo other)
{
swap(*this, other);

return *this;
}
return *this;
}

~foo()
{
delete p;
}
~foo()
{
delete p;
}

friend void swap(foo& first, foo& second)
{
using std::swap;
friend void swap(foo& first, foo& second)
{
using std::swap;

swap(first.p, second.p);
}
swap(first.p, second.p);
}

private:
resource* p;
private:
resource* p;
};

// Implement the assignment operator with strong exception safety.
Expand Down Expand Up @@ -87,9 +87,9 @@ class foo

int main()
{
foo f1, f2, f3;
f2 = f1;
f3 = std::move(f1);
foo f1, f2, f3;
f2 = f1;
f3 = std::move(f1);

swap(f2, f3);
swap(f2, f3);
}
44 changes: 22 additions & 22 deletions common-tasks/classes/delegate-behavior-to-derived-classes.cpp
Expand Up @@ -3,28 +3,28 @@
template<typename derived>
class base
{
public:
void do_something()
{
// ...
static_cast<derived*>(this)->do_something_impl();
// ...
}
public:
void do_something()
{
// ...
static_cast<derived*>(this)->do_something_impl();
// ...
}

private:
void do_something_impl()
{
// Default implementation
}
private:
void do_something_impl()
{
// Default implementation
}
};

class foo : public base<foo>
{
public:
void do_something_impl()
{
// Derived implementation
}
public:
void do_something_impl()
{
// Derived implementation
}
};

class bar : public base<bar>
Expand All @@ -33,7 +33,7 @@ class bar : public base<bar>
template<typename derived>
void use(base<derived>& b)
{
b.do_something();
b.do_something();
}

// Delegate behavior to derived classes without incurring the cost of
Expand Down Expand Up @@ -74,9 +74,9 @@ void use(base<derived>& b)

int main()
{
foo f;
use(f);
foo f;
use(f);

bar b;
use(b);
bar b;
use(b);
}
38 changes: 19 additions & 19 deletions common-tasks/classes/lexicographic-ordering.cpp
Expand Up @@ -5,20 +5,20 @@

class foo
{
public:
foo(int n_, char c_, double d_)
: n{n_}, c{c_}, d{d_}
{}
public:
foo(int n_, char c_, double d_)
: n{n_}, c{c_}, d{d_}
{}

friend bool operator<(const foo& lh, const foo& rh)
{
return std::tie(lh.n, lh.c, lh.d) <
std::tie(rh.n, rh.c, rh.d);
}
private:
int n;
char c;
double d;
friend bool operator<(const foo& lh, const foo& rh)
{
return std::tie(lh.n, lh.c, lh.d) <
std::tie(rh.n, rh.c, rh.d);
}
private:
int n;
char c;
double d;
};

// Implement a lexicographic ordering over class members.
Expand All @@ -43,11 +43,11 @@ class foo

int main()
{
foo f1(1, 'a', 3.14);
foo f2(1, 'b', 2.78);
foo f1(1, 'a', 3.14);
foo f2(1, 'b', 2.78);

if (f1 < f2)
{
return 1;
}
if (f1 < f2)
{
return 1;
}
}
32 changes: 16 additions & 16 deletions common-tasks/classes/non-member-interfaces.cpp
Expand Up @@ -2,28 +2,28 @@

namespace ns
{
class foo
{
public:
void member()
{
// Uses private data
}
class foo
{
public:
void member()
{
// Uses private data
}

private:
// Private data
};
private:
// Private data
};

void non_member(foo obj)
{
obj.member();
}
void non_member(foo obj)
{
obj.member();
}
}

int main()
{
ns::foo obj;
non_member(obj);
ns::foo obj;
non_member(obj);
}

// Reduce dependencies on internal class details and improve
Expand Down

0 comments on commit 3f5efec

Please sign in to comment.