forked from pezy/CppPrimer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
1,086 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
#include "ex14_26_StrBlob.h" | ||
#include <algorithm> | ||
|
||
//================================================================== | ||
// | ||
// StrBlob - operators | ||
// | ||
//================================================================== | ||
|
||
bool operator==(const StrBlob &lhs, const StrBlob &rhs) | ||
{ | ||
return *lhs.data == *rhs.data; | ||
} | ||
|
||
bool operator!=(const StrBlob &lhs, const StrBlob &rhs) | ||
{ | ||
return !(lhs == rhs); | ||
} | ||
|
||
bool operator< (const StrBlob &lhs, const StrBlob &rhs) | ||
{ | ||
return std::lexicographical_compare(lhs.data->begin(), lhs.data->end(), rhs.data->begin(), rhs.data->end()); | ||
} | ||
|
||
bool operator> (const StrBlob &lhs, const StrBlob &rhs) | ||
{ | ||
return rhs < lhs; | ||
} | ||
|
||
bool operator<=(const StrBlob &lhs, const StrBlob &rhs) | ||
{ | ||
return !(rhs < lhs); | ||
} | ||
|
||
bool operator>=(const StrBlob &lhs, const StrBlob &rhs) | ||
{ | ||
return !(lhs < rhs); | ||
} | ||
|
||
//================================================================ | ||
// | ||
// StrBlobPtr - operators | ||
// | ||
//================================================================ | ||
|
||
bool operator==(const StrBlobPtr &lhs, const StrBlobPtr &rhs) | ||
{ | ||
return lhs.curr == rhs.curr; | ||
} | ||
|
||
bool operator!=(const StrBlobPtr &lhs, const StrBlobPtr &rhs) | ||
{ | ||
return !(lhs == rhs); | ||
} | ||
|
||
bool operator< (const StrBlobPtr &x, const StrBlobPtr &y) | ||
{ | ||
return x.curr < y.curr; | ||
} | ||
|
||
bool operator> (const StrBlobPtr &x, const StrBlobPtr &y) | ||
{ | ||
return x.curr > y.curr; | ||
} | ||
|
||
bool operator<=(const StrBlobPtr &x, const StrBlobPtr &y) | ||
{ | ||
return x.curr <= y.curr; | ||
} | ||
|
||
bool operator>=(const StrBlobPtr &x, const StrBlobPtr &y) | ||
{ | ||
return x.curr >= y.curr; | ||
} | ||
|
||
//================================================================ | ||
// | ||
// ConstStrBlobPtr - operators | ||
// | ||
//================================================================ | ||
|
||
bool operator==(const ConstStrBlobPtr &lhs, const ConstStrBlobPtr &rhs) | ||
{ | ||
return lhs.curr == rhs.curr; | ||
} | ||
|
||
bool operator!=(const ConstStrBlobPtr &lhs, const ConstStrBlobPtr &rhs) | ||
{ | ||
return !(lhs == rhs); | ||
} | ||
|
||
bool operator< (const ConstStrBlobPtr &lhs, const ConstStrBlobPtr &rhs) | ||
{ | ||
return lhs.curr < rhs.curr; | ||
} | ||
|
||
bool operator> (const ConstStrBlobPtr &lhs, const ConstStrBlobPtr &rhs) | ||
{ | ||
return lhs.curr > rhs.curr; | ||
} | ||
|
||
bool operator<=(const ConstStrBlobPtr &lhs, const ConstStrBlobPtr &rhs) | ||
{ | ||
return lhs.curr <= rhs.curr; | ||
} | ||
|
||
bool operator>=(const ConstStrBlobPtr &lhs, const ConstStrBlobPtr &rhs) | ||
{ | ||
return lhs.curr >= rhs.curr; | ||
} | ||
|
||
//================================================================== | ||
// | ||
// copy assignment operator and move assignment operator. | ||
// | ||
//================================================================== | ||
|
||
StrBlob& StrBlob::operator=(const StrBlob &lhs) | ||
{ | ||
data = make_shared<vector<string>>(*lhs.data); | ||
return *this; | ||
} | ||
|
||
StrBlob& StrBlob::operator=(StrBlob &&rhs) NOEXCEPT | ||
{ | ||
if (this != &rhs) { | ||
data = std::move(rhs.data); | ||
rhs.data = nullptr; | ||
} | ||
|
||
return *this; | ||
} | ||
|
||
//================================================================== | ||
// | ||
// members | ||
// | ||
//================================================================== | ||
|
||
StrBlobPtr StrBlob::begin() | ||
{ | ||
return StrBlobPtr(*this); | ||
} | ||
|
||
StrBlobPtr StrBlob::end() | ||
{ | ||
return StrBlobPtr(*this, data->size()); | ||
} | ||
|
||
ConstStrBlobPtr StrBlob::cbegin() const | ||
{ | ||
return ConstStrBlobPtr(*this); | ||
} | ||
|
||
ConstStrBlobPtr StrBlob::cend() const | ||
{ | ||
return ConstStrBlobPtr(*this, data->size()); | ||
} |
Oops, something went wrong.