diff --git a/.gitignore b/.gitignore index 6bc0b7a722d27aac0bccee825eba391f8fa73187..81daeb234bd927cd36bac581629bb978e2ad65ad 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ /.cache/ build .DS_Store -*/.DS_Store -helper.md \ No newline at end of file +*/.DS_Store \ No newline at end of file diff --git a/docs/source/2022_2023_autumn/index.rst b/docs/source/2022_2023_autumn/index.rst index db005768f5b4c4a72bc709d715ae0660fab62ec6..7b8173414cf2c11bf111a58221011b6882e718b1 100644 --- a/docs/source/2022_2023_autumn/index.rst +++ b/docs/source/2022_2023_autumn/index.rst @@ -22,4 +22,6 @@ week_08/doc.rst week_09/doc.rst week_10/doc.rst - week_11/doc.rst \ No newline at end of file + week_11/doc.rst + week_12/doc.rst + week_13/doc.rst \ No newline at end of file diff --git a/docs/source/2022_2023_autumn/week_03/code/lowest_terms_fraction.hpp b/docs/source/2022_2023_autumn/week_03/code/lowest_terms_fraction.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5b419d66c941e15c284b43b2afbc4229498996fe --- /dev/null +++ b/docs/source/2022_2023_autumn/week_03/code/lowest_terms_fraction.hpp @@ -0,0 +1,44 @@ +#ifndef LOWEST_TERMS_FRACTION_HPP +#define LOWEST_TERMS_FRACTION_HPP + +#include + +inline int get_greatest_common_divisor(int numerator, int denominator) { + int res = 0; + while (denominator != 0) { + res = denominator; + denominator = numerator % denominator; + numerator = res; + } + return res; +} + +class LowestTermsFraction { + public: + LowestTermsFraction(int numerator, int denominator) : numerator_(numerator), denominator_{denominator} { + if (denominator_ == 0) { + throw std::domain_error{"the fraction's denominator can't be zero"}; + } + + set_to_lowest_terms(); + } + + void add(LowestTermsFraction const& other) { + numerator_ = numerator_ * other.denominator_ + other.numerator_ * denominator_; + denominator_ *= other.denominator_; + + set_to_lowest_terms(); + } + + private: + void set_to_lowest_terms() { + int const greatest_common_divisor{get_greatest_common_divisor(numerator_, denominator_)}; + numerator_ /= greatest_common_divisor; + denominator_ /= greatest_common_divisor; + } + + int numerator_; // 分子 + int denominator_; // 分母 +}; + +#endif \ No newline at end of file diff --git a/docs/source/2022_2023_autumn/week_04/code/owner_int.hpp b/docs/source/2022_2023_autumn/week_04/code/owner_int.hpp new file mode 100644 index 0000000000000000000000000000000000000000..afaa0e931645e808faa063369facf636d0e77e8d --- /dev/null +++ b/docs/source/2022_2023_autumn/week_04/code/owner_int.hpp @@ -0,0 +1,33 @@ +#ifndef OWNER_INT_HPP +#define OWNER_INT_HPP + +#include + +class OwnerInt { + public: + OwnerInt() : data_(nullptr) {} + OwnerInt(OwnerInt const& other) : data_(other.data_ ? new int(*other.data_) : nullptr) {} + OwnerInt(int value) : data_(new int(value)) {} + + OwnerInt& operator=(OwnerInt const& other) { + if (this != &other) { + OwnerInt temp(other); + swap(temp); + } + return *this; + } + + ~OwnerInt() { + delete data_; + } + + void swap(OwnerInt& other) { + using std::swap; + swap(data_, other.data_); + } + + private: + int* data_; +}; + +#endif \ No newline at end of file diff --git a/docs/source/2022_2023_autumn/week_05/doc.rst b/docs/source/2022_2023_autumn/week_05/doc.rst index 950141dc3aa12cfcebbf1df90a2b33e192d2de83..7a76b8ac74d7a11b636c2b28de590cbe70f8bdda 100644 --- a/docs/source/2022_2023_autumn/week_05/doc.rst +++ b/docs/source/2022_2023_autumn/week_05/doc.rst @@ -1,5 +1,9 @@ -耦合、内聚、封装:解放你的函数 -********************************* +自动类型推导:分离应当关注的点 +******************************* + +.. pull-quote:: + + `我只想做循环变量,谁是循环类型……我不在乎。——改自《让子弹飞》` .. TODO: diff --git a/docs/source/2022_2023_autumn/week_06/code/owner.hpp b/docs/source/2022_2023_autumn/week_06/code/owner.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9ea6db47f09b773e57b90990baf0ec434c270390 --- /dev/null +++ b/docs/source/2022_2023_autumn/week_06/code/owner.hpp @@ -0,0 +1,7 @@ +#ifndef OWNER_HPP +#define OWNER_HPP + +template +using Owner = T; + +#endif \ No newline at end of file diff --git a/docs/source/2022_2023_autumn/week_06/doc.rst b/docs/source/2022_2023_autumn/week_06/doc.rst index e8b5481bdc97a623dc9633093da66274d8f64eeb..65b7d30886ee80e18c5921a3764b35efbfe16d26 100644 --- a/docs/source/2022_2023_autumn/week_06/doc.rst +++ b/docs/source/2022_2023_autumn/week_06/doc.rst @@ -1,9 +1,5 @@ -自动类型推导:分离应当关注的点 -******************************* - -.. pull-quote:: - - `我只想做县长夫人,谁是县长,我不在乎。——《让子弹飞》` +模板:将类型和常量作为参数 +**************************** .. TODO: diff --git a/docs/source/2022_2023_autumn/week_07/doc.rst b/docs/source/2022_2023_autumn/week_07/doc.rst index 9a32092f113eec5bf5c50ac9d631b45b8b00b3d0..486ffe0f09045347eb7a370ef8b2253d1f1031f9 100644 --- a/docs/source/2022_2023_autumn/week_07/doc.rst +++ b/docs/source/2022_2023_autumn/week_07/doc.rst @@ -1,9 +1,9 @@ -概念:直接表达代码意图 -************************ +迭代器:尝试编写通用代码(泛型编程) +************************************* .. pull-quote:: - `如果一只鸟走起来像鸭子、游泳起来像鸭子、叫起来也像鸭子,那么这只鸟就可以被称为鸭子。——James Whitcomb Riley` + `如果一个类型构造起来像迭代器、解引用起来像迭代器、迭代起来也像迭代器,那么这个类型就可以被称为迭代器。——改自 James Whitcomb Riley` .. TODO: diff --git a/docs/source/2022_2023_autumn/week_08/doc.rst b/docs/source/2022_2023_autumn/week_08/doc.rst index ed5e66bb38b823597ca87ab29e80170f36149bb6..d881c1c8844c9fd43968fa7d5ce470056c55084e 100644 --- a/docs/source/2022_2023_autumn/week_08/doc.rst +++ b/docs/source/2022_2023_autumn/week_08/doc.rst @@ -1,5 +1,9 @@ -移动语义:C++ 的江湖豪情侠胆柔肠之大腿 -****************************************** +概念:直接表达代码意图 +************************ + +.. pull-quote:: + + `` .. TODO: diff --git a/docs/source/2022_2023_autumn/week_09/doc.rst b/docs/source/2022_2023_autumn/week_09/doc.rst index 8b50678a3666cc4d463ded74b19280a22dc2c241..95c91f751e4bd35d5e6731a1596307e66c701764 100644 --- a/docs/source/2022_2023_autumn/week_09/doc.rst +++ b/docs/source/2022_2023_autumn/week_09/doc.rst @@ -1,6 +1,9 @@ -智能指针:别了, ``new`` 与 ``delete`` -**************************************** +异常安全保证:C++ 课程缺失的一课 +********************************* .. TODO: -待完成 \ No newline at end of file +待完成 + +.. TODO: noexcept(noexcept(...)) +.. TODO: https://en.cppreference.com/w/cpp/language/exceptions \ No newline at end of file diff --git a/docs/source/2022_2023_autumn/week_10/doc.rst b/docs/source/2022_2023_autumn/week_10/doc.rst index 241d0548a5f284c749ee4596d8f9d34044e6bb10..ed5e66bb38b823597ca87ab29e80170f36149bb6 100644 --- a/docs/source/2022_2023_autumn/week_10/doc.rst +++ b/docs/source/2022_2023_autumn/week_10/doc.rst @@ -1,5 +1,5 @@ -finally:总是在最后执行 -***************************** +移动语义:C++ 的江湖豪情侠胆柔肠之大腿 +****************************************** .. TODO: diff --git a/docs/source/2022_2023_autumn/week_11/code/owner.hpp b/docs/source/2022_2023_autumn/week_11/code/owner.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9ea6db47f09b773e57b90990baf0ec434c270390 --- /dev/null +++ b/docs/source/2022_2023_autumn/week_11/code/owner.hpp @@ -0,0 +1,7 @@ +#ifndef OWNER_HPP +#define OWNER_HPP + +template +using Owner = T; + +#endif \ No newline at end of file diff --git a/docs/source/2022_2023_autumn/week_11/code/unique_ptr.hpp b/docs/source/2022_2023_autumn/week_11/code/unique_ptr.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d480a730cba0042a2801417de762bbe09db9fce8 --- /dev/null +++ b/docs/source/2022_2023_autumn/week_11/code/unique_ptr.hpp @@ -0,0 +1,226 @@ +#ifndef UNIQUE_PTR_HPP +#define UNIQUE_PTR_HPP + +#include "owner.hpp" + +#include +#include + +template +class UniquePtr { + public: + UniquePtr() : data_(nullptr) {} + UniquePtr(UniquePtr const&) = delete; + UniquePtr(UniquePtr&& other) noexcept : data_(std::exchange(other.data_, nullptr)) {} + + UniquePtr(std::nullptr_t) noexcept : data_(nullptr) {} + UniquePtr(Owner data) : data_(data) {} + + template + UniquePtr(UniquePtr&& other) noexcept : data_(other.release()) {} + + UniquePtr& operator=(UniquePtr const&) = delete; + UniquePtr& operator=(UniquePtr&& other) noexcept { + if (this != &other) { + reset(other.release()); + } + return *this; + } + + UniquePtr& operator=(std::nullptr_t) noexcept { + reset(); + return *this; + } + + template + UniquePtr& operator=(UniquePtr other) { + reset(other.release()); + return *this; + } + + ~UniquePtr() { + reset(); + } + + void reset(Owner pointer = nullptr) noexcept { + delete std::exchange(data_, pointer); + } + + Owner release() noexcept { + return std::exchange(data_, nullptr); + } + + void swap(UniquePtr& other) noexcept { + using std::swap; + swap(data_, other.data_); + } + + T* get() const noexcept { + return data_; + } + + operator bool() const noexcept { + return get() != nullptr; + } + + T& operator*() const noexcept(noexcept(*data_)) { + return *data_; + } + T* operator->() const noexcept { + return data_; + } + + private: + Owner data_; +}; + +template +class UniquePtr { // NOLINT + public: + UniquePtr() : data_(nullptr) {} + UniquePtr(UniquePtr const&) = delete; + UniquePtr(UniquePtr&& other) noexcept : data_(std::exchange(other.data_, nullptr)) {} + + UniquePtr(std::nullptr_t) noexcept : data_(nullptr) {} + + template + UniquePtr(ArrayPointer pointer) : data_(pointer) {} + + template + UniquePtr(UniquePtr&& other) noexcept : data_(other.release()) {} + + UniquePtr& operator=(UniquePtr const&) = delete; + UniquePtr& operator=(UniquePtr&& other) noexcept { + if (this != &other) { + reset(other.release()); + } + return *this; + } + + UniquePtr& operator=(std::nullptr_t) noexcept { + reset(); + return *this; + } + + template + UniquePtr& operator=(UniquePtr other) { + reset(other.release()); + return *this; + } + + ~UniquePtr() { + reset(); + } + + template + void reset(ArrayPointer pointer) noexcept { + delete[] std::exchange(data_, pointer); // NOLINT + } + + void reset(std::nullptr_t = nullptr) noexcept { + delete[] std::exchange(data_, nullptr); + } + + Owner release() noexcept { + return std::exchange(data_, nullptr); + } + + void swap(UniquePtr& other) noexcept { + std::swap(data_, other.data_); + } + + T* get() const noexcept { + return data_; + } + + operator bool() const noexcept { + return get() != nullptr; + } + + T& operator[](std::size_t index) const { + return *(data_ + index); + } + + private: + Owner data_{}; +}; + +template +bool operator==(UniquePtr const& lhs, UniquePtr const& rhs) { + return lhs.get() == rhs.get(); +} +template +bool operator==(UniquePtr const& lhs, std::nullptr_t) { + return lhs.get() == nullptr; +} +template +bool operator==(std::nullptr_t, UniquePtr const& rhs) { + return nullptr == rhs.get(); +} + +template +bool operator!=(UniquePtr const& lhs, UniquePtr const& rhs) { + return !(lhs == rhs); +} +template +bool operator!=(UniquePtr const& lhs, std::nullptr_t) { + return !(lhs == nullptr); +} +template +bool operator!=(std::nullptr_t, UniquePtr const& rhs) { + return !(nullptr == rhs); +} + +template +bool operator<(UniquePtr const& lhs, UniquePtr const& rhs) { + return lhs.get() < rhs.get(); +} +template +bool operator<(UniquePtr const& lhs, std::nullptr_t) { + return lhs.get() < nullptr; +} +template +bool operator<(std::nullptr_t, UniquePtr const& rhs) { + return nullptr < rhs.get(); +} + +template +bool operator>(UniquePtr const& lhs, UniquePtr const& rhs) { + return rhs < lhs; +} +template +bool operator>(UniquePtr const& lhs, std::nullptr_t) { + return nullptr < lhs; +} +template +bool operator>(std::nullptr_t, UniquePtr const& rhs) { + return rhs < nullptr; +} + +template +bool operator>=(UniquePtr const& lhs, UniquePtr const& rhs) { + return !(lhs < rhs); +} +template +bool operator>=(UniquePtr const& lhs, std::nullptr_t) { + return !(lhs < nullptr); +} +template +bool operator>=(std::nullptr_t, UniquePtr const& rhs) { + return !(nullptr < rhs); +} + +template +bool operator<=(UniquePtr const& lhs, UniquePtr const& rhs) { + return !(rhs < lhs); +} +template +bool operator<=(UniquePtr const& lhs, std::nullptr_t) { + return !(nullptr < lhs); +} +template +bool operator<=(std::nullptr_t, UniquePtr const& rhs) { + return !(rhs < nullptr); +} + +#endif \ No newline at end of file diff --git a/docs/source/2022_2023_autumn/week_11/doc.rst b/docs/source/2022_2023_autumn/week_11/doc.rst index 79aab166e739c482bd3276ed194f0a485618f3be..8b50678a3666cc4d463ded74b19280a22dc2c241 100644 --- a/docs/source/2022_2023_autumn/week_11/doc.rst +++ b/docs/source/2022_2023_autumn/week_11/doc.rst @@ -1,5 +1,5 @@ -单向链表:运用移动语义、RAII 的示例 -************************************* +智能指针:别了, ``new`` 与 ``delete`` +**************************************** .. TODO: diff --git a/docs/source/2022_2023_autumn/week_12/code/finally.hpp b/docs/source/2022_2023_autumn/week_12/code/finally.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e72286c90928a06566c177be19853ce0051a2b68 --- /dev/null +++ b/docs/source/2022_2023_autumn/week_12/code/finally.hpp @@ -0,0 +1,34 @@ +#ifndef FINALLY_HPP +#define FINALLY_HPP + +#include + +template +class FinalAction { + public: + FinalAction(Function function) : function_(std::move(function)), should_invoke_(true) {} + + FinalAction(FinalAction const&) = delete; + FinalAction(FinalAction&& other) + : function_(std::move(other.function_)), should_invoke_(std::exchange(other.should_invoke_, false)) {} + + FinalAction& operator=(FinalAction const&) = delete; + FinalAction& operator=(FinalAction const&&) = delete; + + ~FinalAction() { + if (should_invoke_) { + function_(); + } + } + + private: + Function function_; + bool should_invoke_; +}; + +template +FinalAction finally(Function function) { + return FinalAction{std::move(function)}; +} + +#endif \ No newline at end of file diff --git a/docs/source/2022_2023_autumn/week_12/doc.rst b/docs/source/2022_2023_autumn/week_12/doc.rst new file mode 100644 index 0000000000000000000000000000000000000000..241d0548a5f284c749ee4596d8f9d34044e6bb10 --- /dev/null +++ b/docs/source/2022_2023_autumn/week_12/doc.rst @@ -0,0 +1,6 @@ +finally:总是在最后执行 +***************************** + +.. TODO: + +待完成 \ No newline at end of file diff --git a/docs/source/2022_2023_autumn/week_13/code/forward_list.hpp b/docs/source/2022_2023_autumn/week_13/code/forward_list.hpp new file mode 100644 index 0000000000000000000000000000000000000000..3d9c321701be2180066fd7dcee07676cbb74ca80 --- /dev/null +++ b/docs/source/2022_2023_autumn/week_13/code/forward_list.hpp @@ -0,0 +1,14 @@ +#ifndef FORWARD_LIST_HPP +#define FORWARD_LIST_HPP + +#include "node.hpp" +#include "node_iterator.hpp" + +template +class ForwardList { + public: + + private: +}; + +#endif \ No newline at end of file diff --git a/docs/source/2022_2023_autumn/week_13/code/node.hpp b/docs/source/2022_2023_autumn/week_13/code/node.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8c2d1f82290b9209026c1b72c2f9dcaff8735b39 --- /dev/null +++ b/docs/source/2022_2023_autumn/week_13/code/node.hpp @@ -0,0 +1,12 @@ +#ifndef NODE_HPP +#define NODE_HPP + +#include "unique_ptr.hpp" + +template +struct Node { + T data; + UniquePtr next; +}; + +#endif \ No newline at end of file diff --git a/docs/source/2022_2023_autumn/week_13/code/node_iterator.hpp b/docs/source/2022_2023_autumn/week_13/code/node_iterator.hpp new file mode 100644 index 0000000000000000000000000000000000000000..253047d945cdf1baf1db9134023d38e486746ce8 --- /dev/null +++ b/docs/source/2022_2023_autumn/week_13/code/node_iterator.hpp @@ -0,0 +1,20 @@ +#ifndef NODE_ITERATOR_HPP +#define NODE_ITERATOR_HPP + +#include "node.hpp" + +template +class NodeIterator { + public: + + private: +}; + +template +class NodeConstIterator { + public: + + private: +}; + +#endif \ No newline at end of file diff --git a/docs/source/2022_2023_autumn/week_13/code/owner.hpp b/docs/source/2022_2023_autumn/week_13/code/owner.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9ea6db47f09b773e57b90990baf0ec434c270390 --- /dev/null +++ b/docs/source/2022_2023_autumn/week_13/code/owner.hpp @@ -0,0 +1,7 @@ +#ifndef OWNER_HPP +#define OWNER_HPP + +template +using Owner = T; + +#endif \ No newline at end of file diff --git a/docs/source/2022_2023_autumn/week_13/code/unique_ptr.hpp b/docs/source/2022_2023_autumn/week_13/code/unique_ptr.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d480a730cba0042a2801417de762bbe09db9fce8 --- /dev/null +++ b/docs/source/2022_2023_autumn/week_13/code/unique_ptr.hpp @@ -0,0 +1,226 @@ +#ifndef UNIQUE_PTR_HPP +#define UNIQUE_PTR_HPP + +#include "owner.hpp" + +#include +#include + +template +class UniquePtr { + public: + UniquePtr() : data_(nullptr) {} + UniquePtr(UniquePtr const&) = delete; + UniquePtr(UniquePtr&& other) noexcept : data_(std::exchange(other.data_, nullptr)) {} + + UniquePtr(std::nullptr_t) noexcept : data_(nullptr) {} + UniquePtr(Owner data) : data_(data) {} + + template + UniquePtr(UniquePtr&& other) noexcept : data_(other.release()) {} + + UniquePtr& operator=(UniquePtr const&) = delete; + UniquePtr& operator=(UniquePtr&& other) noexcept { + if (this != &other) { + reset(other.release()); + } + return *this; + } + + UniquePtr& operator=(std::nullptr_t) noexcept { + reset(); + return *this; + } + + template + UniquePtr& operator=(UniquePtr other) { + reset(other.release()); + return *this; + } + + ~UniquePtr() { + reset(); + } + + void reset(Owner pointer = nullptr) noexcept { + delete std::exchange(data_, pointer); + } + + Owner release() noexcept { + return std::exchange(data_, nullptr); + } + + void swap(UniquePtr& other) noexcept { + using std::swap; + swap(data_, other.data_); + } + + T* get() const noexcept { + return data_; + } + + operator bool() const noexcept { + return get() != nullptr; + } + + T& operator*() const noexcept(noexcept(*data_)) { + return *data_; + } + T* operator->() const noexcept { + return data_; + } + + private: + Owner data_; +}; + +template +class UniquePtr { // NOLINT + public: + UniquePtr() : data_(nullptr) {} + UniquePtr(UniquePtr const&) = delete; + UniquePtr(UniquePtr&& other) noexcept : data_(std::exchange(other.data_, nullptr)) {} + + UniquePtr(std::nullptr_t) noexcept : data_(nullptr) {} + + template + UniquePtr(ArrayPointer pointer) : data_(pointer) {} + + template + UniquePtr(UniquePtr&& other) noexcept : data_(other.release()) {} + + UniquePtr& operator=(UniquePtr const&) = delete; + UniquePtr& operator=(UniquePtr&& other) noexcept { + if (this != &other) { + reset(other.release()); + } + return *this; + } + + UniquePtr& operator=(std::nullptr_t) noexcept { + reset(); + return *this; + } + + template + UniquePtr& operator=(UniquePtr other) { + reset(other.release()); + return *this; + } + + ~UniquePtr() { + reset(); + } + + template + void reset(ArrayPointer pointer) noexcept { + delete[] std::exchange(data_, pointer); // NOLINT + } + + void reset(std::nullptr_t = nullptr) noexcept { + delete[] std::exchange(data_, nullptr); + } + + Owner release() noexcept { + return std::exchange(data_, nullptr); + } + + void swap(UniquePtr& other) noexcept { + std::swap(data_, other.data_); + } + + T* get() const noexcept { + return data_; + } + + operator bool() const noexcept { + return get() != nullptr; + } + + T& operator[](std::size_t index) const { + return *(data_ + index); + } + + private: + Owner data_{}; +}; + +template +bool operator==(UniquePtr const& lhs, UniquePtr const& rhs) { + return lhs.get() == rhs.get(); +} +template +bool operator==(UniquePtr const& lhs, std::nullptr_t) { + return lhs.get() == nullptr; +} +template +bool operator==(std::nullptr_t, UniquePtr const& rhs) { + return nullptr == rhs.get(); +} + +template +bool operator!=(UniquePtr const& lhs, UniquePtr const& rhs) { + return !(lhs == rhs); +} +template +bool operator!=(UniquePtr const& lhs, std::nullptr_t) { + return !(lhs == nullptr); +} +template +bool operator!=(std::nullptr_t, UniquePtr const& rhs) { + return !(nullptr == rhs); +} + +template +bool operator<(UniquePtr const& lhs, UniquePtr const& rhs) { + return lhs.get() < rhs.get(); +} +template +bool operator<(UniquePtr const& lhs, std::nullptr_t) { + return lhs.get() < nullptr; +} +template +bool operator<(std::nullptr_t, UniquePtr const& rhs) { + return nullptr < rhs.get(); +} + +template +bool operator>(UniquePtr const& lhs, UniquePtr const& rhs) { + return rhs < lhs; +} +template +bool operator>(UniquePtr const& lhs, std::nullptr_t) { + return nullptr < lhs; +} +template +bool operator>(std::nullptr_t, UniquePtr const& rhs) { + return rhs < nullptr; +} + +template +bool operator>=(UniquePtr const& lhs, UniquePtr const& rhs) { + return !(lhs < rhs); +} +template +bool operator>=(UniquePtr const& lhs, std::nullptr_t) { + return !(lhs < nullptr); +} +template +bool operator>=(std::nullptr_t, UniquePtr const& rhs) { + return !(nullptr < rhs); +} + +template +bool operator<=(UniquePtr const& lhs, UniquePtr const& rhs) { + return !(rhs < lhs); +} +template +bool operator<=(UniquePtr const& lhs, std::nullptr_t) { + return !(nullptr < lhs); +} +template +bool operator<=(std::nullptr_t, UniquePtr const& rhs) { + return !(rhs < nullptr); +} + +#endif \ No newline at end of file diff --git a/docs/source/2022_2023_autumn/week_13/doc.rst b/docs/source/2022_2023_autumn/week_13/doc.rst new file mode 100644 index 0000000000000000000000000000000000000000..5f3022c8c44934473d6bdc56f5055a6215c85898 --- /dev/null +++ b/docs/source/2022_2023_autumn/week_13/doc.rst @@ -0,0 +1,6 @@ +单向链表:一个综合示例 +*********************** + +.. TODO: + +待完成 \ No newline at end of file diff --git a/docs/source/_todo/free_your_function/doc.rst b/docs/source/_todo/free_your_function/doc.rst new file mode 100644 index 0000000000000000000000000000000000000000..20755c7f0c86bc297410a18fa6dbfb0e96475674 --- /dev/null +++ b/docs/source/_todo/free_your_function/doc.rst @@ -0,0 +1,6 @@ +耦合:解放你的函数 +********************************* + +.. TODO: + +待完成 \ No newline at end of file