From 090c5bd0ff2a18291ac45f462e38935375b407af Mon Sep 17 00:00:00 2001 From: Jeremy <51220084+jeremy-rifkin@users.noreply.github.com> Date: Sun, 30 Jul 2023 20:51:16 -0400 Subject: [PATCH] Add support for reference-style links. Cleanup a bunch of articles and minor fixes. --- wiki_articles/README.md | 17 ++++++++++++----- wiki_articles/ask.md | 8 ++++---- wiki_articles/bitint.md | 9 ++++----- wiki_articles/c99.md | 6 ++++-- wiki_articles/cas.md | 15 +++++++-------- wiki_articles/class_struct.md | 12 +++++++----- wiki_articles/conditional.md | 7 ++++--- wiki_articles/copy_swap.md | 21 ++++++++++++++------- wiki_articles/endl.md | 25 ++++++++++++++----------- wiki_articles/enum.md | 9 +++++---- wiki_articles/erase_remove.md | 9 ++++----- wiki_articles/formatting.md | 8 ++++---- wiki_articles/forward.md | 19 +++++++++---------- wiki_articles/int_size.md | 3 +-- wiki_articles/overload_equality.md | 5 +++-- wiki_articles/overload_less.md | 11 ++++++----- wiki_articles/random.md | 11 +++++++---- wiki_articles/safety.md | 7 ++++--- wiki_articles/scanf_whitespace.md | 12 ++++++------ wiki_articles/sequencing.md | 5 ++--- wiki_articles/smart_ptr.md | 11 +++++++---- wiki_articles/std_array.md | 10 +++++++--- wiki_articles/strict_weak.md | 14 +++++++------- 23 files changed, 142 insertions(+), 112 deletions(-) diff --git a/wiki_articles/README.md b/wiki_articles/README.md index 04c444a..50b9918 100644 --- a/wiki_articles/README.md +++ b/wiki_articles/README.md @@ -9,10 +9,8 @@ issue about an article. ## Wiki Markdown -The articles are written in a GitHub-flavored Markdown. -Generally, what you see as a GitHub preview is what you should be getting in the -output embed, more or less. -However, there are some extra nuances: +The articles are written in a GitHub-flavored Markdown. Generally, what you see as a GitHub preview is what you should +be getting in the output embed, more or less. However, there are some extra nuances: ### Article Title @@ -49,7 +47,16 @@ Footer here. Everything after a `footer` HTML comment will turn into the footer of the embed. This is a part of the embed at the bottom, displayed with small font. -### Image +### Links +```md +[text](url) +[tex][ref] + +[ref]: url +``` +Inline and reference-style links are supported. On discord the text cannot contain any newlines. + +### Images ```md ![](https://xyz.xyz/image.png) ``` diff --git a/wiki_articles/ask.md b/wiki_articles/ask.md index 037180f..34fa418 100644 --- a/wiki_articles/ask.md +++ b/wiki_articles/ask.md @@ -1,9 +1,9 @@ # How to Ask a Programming Question -Anyone can ask a question in our programming channels. -Following the guide -[Writing The Perfect Question](https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/) -is recommended. +Anyone can ask a question in our programming channels. Following the guide [Writing The Perfect Question][1] is +recommended. + +[1]: https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/ ## What to Post diff --git a/wiki_articles/bitint.md b/wiki_articles/bitint.md index e39835f..dc7245f 100644 --- a/wiki_articles/bitint.md +++ b/wiki_articles/bitint.md @@ -1,10 +1,9 @@ # _BitInt and Extended Integers in C/C++ -**[_BitInt(N)](https://en.cppreference.com/w/c/language/arithmetic_types#Integer_types)** -is an N-bit integer available since -[C23](https://en.cppreference.com/w/c/23), -but may not be available in C++. -Major compilers have limited support for extended integers. +**[_BitInt(N)][1]** is an N-bit integer available since [C23](https://en.cppreference.com/w/c/23), but may not be +available in C++. Major compilers have limited support for extended integers. + +[1]: https://en.cppreference.com/w/c/language/arithmetic_types#Integer_types ## GCC diff --git a/wiki_articles/c99.md b/wiki_articles/c99.md index 63dad1e..a6c0ad3 100644 --- a/wiki_articles/c99.md +++ b/wiki_articles/c99.md @@ -1,9 +1,11 @@ # Using C99 Features -C99, i.e. the [C standard released in 1999](https://port70.net/~nsz/c/c99/n1256.html) -added [a lot of features](https://en.cppreference.com/w/c/99) that make C code much more readable. +C99, i.e. the [C standard released in 1999][1] added [a lot of features][2] that make C code much more readable. Examples include: +[1]: https://port70.net/~nsz/c/c99/n1256.html +[2]: https://en.cppreference.com/w/c/99 + **[Declarations anywhere in block](https://en.cppreference.com/w/c/language/declarations#Notes)**
In C99, you can declare and initialize a variable anywhere: `int x = 3;` Declare variables where they can be initialized; don't put all variables at the top of a function. diff --git a/wiki_articles/cas.md b/wiki_articles/cas.md index 96c8e8b..c80e71c 100644 --- a/wiki_articles/cas.md +++ b/wiki_articles/cas.md @@ -1,13 +1,7 @@ # What Is an Atomic Compare-And-Swap (CAS)? -[CAS](https://en.wikipedia.org/wiki/Compare-and-swap) -allows -*[read-modify-write operations](https://en.wikipedia.org/wiki/Read%E2%80%93modify%E2%80%93write)* -for atomics. -It's often the foundation of -*[lock-free algorithms](https://en.wikipedia.org/wiki/Non-blocking_algorithm)*. -In C++, this takes the form of -**[std::atomic::compare_exchange_xxx](https://en.cppreference.com/w/cpp/atomic/atomic/compare_exchange)**: +[CAS][cas] allows *[read-modify-write operations][rmw]* for atomics. It's often the foundation of +*[lock-free algorithms][lf]*. In C++, this takes the form of **[std::atomic::compare_exchange_xxx][xchg]**: ```cpp bool atomic::compare_exchange(T& expected, T desired) { T old = load(); // All of this happens atomically. @@ -17,6 +11,11 @@ bool atomic::compare_exchange(T& expected, T desired) { } ``` +[cas]: https://en.wikipedia.org/wiki/Compare-and-swap +[rmw]: https://en.wikipedia.org/wiki/Read%E2%80%93modify%E2%80%93write +[lf]: https://en.wikipedia.org/wiki/Non-blocking_algorithm +[xchg]: https://en.cppreference.com/w/cpp/atomic/atomic/compare_exchange + ## Example - Lock-Free Singly Linked List Stack Push ```cpp struct node { int val; std::atomic next; }; diff --git a/wiki_articles/class_struct.md b/wiki_articles/class_struct.md index 178346f..9351fce 100644 --- a/wiki_articles/class_struct.md +++ b/wiki_articles/class_struct.md @@ -1,11 +1,13 @@ # What Is the Difference Between class and struct? The keywords -**[class](https://en.cppreference.com/w/cpp/keyword/class)** and -**[struct](https://en.cppreference.com/w/cpp/keyword/struct)** both declare a so-called -*[class type](https://en.cppreference.com/w/cpp/language/class)*. -The declared class will have different properties, such as default -[member access](https://en.cppreference.com/w/cpp/language/access), depending on whether `class` or `struct` was used. +**[class][class]** and **[struct][struct]** both declare a so-called *[class type][classtype]*. The declared class will +have different properties, such as default [member access][access], depending on whether `class` or `struct` was used. + +[class]: https://en.cppreference.com/w/cpp/keyword/class +[struct]: https://en.cppreference.com/w/cpp/keyword/struct +[classtype]: https://en.cppreference.com/w/cpp/language/class +[access]: https://en.cppreference.com/w/cpp/language/access ## `class` diff --git a/wiki_articles/conditional.md b/wiki_articles/conditional.md index ab4706e..e627b8d 100644 --- a/wiki_articles/conditional.md +++ b/wiki_articles/conditional.md @@ -1,12 +1,13 @@ # What Is the Conditional Operator? -The [conditional operator](https://en.cppreference.com/w/cpp/language/operator_other#Conditional_operator), -(colloquially called _ternary operator_) -of the form `Condition ? T : F` evaluates `T` if the `Condition` is true, otherwise `F`. +The [conditional operator][1], (colloquially called _ternary operator_) of the form `Condition ? T : F` evaluates `T` if +the `Condition` is true, otherwise `F`. The result of the whole expression is either the expression `T` or `F`. This also means that `T` and `F` must have compatible types. +[1]: https://en.cppreference.com/w/cpp/language/operator_other#Conditional_operator + ## Example A classic use case for the conditional operator is the `min` function. diff --git a/wiki_articles/copy_swap.md b/wiki_articles/copy_swap.md index c60c5d9..462ca19 100644 --- a/wiki_articles/copy_swap.md +++ b/wiki_articles/copy_swap.md @@ -17,24 +17,31 @@ T::T(T&& other) : T{} noexcept² { // optional swap(*this, other); } ``` -**\[1\]** `swap` is often implemented as a [hidden friend](https://stackoverflow.com/q/56795676/5740428)
-**\[2\]** These operations are almost always **[noexcept](https://en.cppreference.com/w/cpp/language/noexcept_spec)**, +**\[1\]** `swap` is often implemented as a [hidden friend][friend]
+**\[2\]** These operations are almost always **[noexcept][noexcept]**, but there are rare exceptions -(e.g. if you have a **[std::list](https://en.cppreference.com/w/cpp/container/list/list)** member)
-**\[3\]** Because of [argument-dependent lookup (ADL)](https://en.cppreference.com/w/cpp/language/adl), +(e.g. if you have a **[std::list][list]** member)
+**\[3\]** Because of [argument-dependent lookup (ADL)][adl], overloaded `swap` functions may be called instead of
-**[std::swap](https://en.cppreference.com/w/cpp/algorithm/swap)**, which is used as a fallback.
+**[std::swap][swap]**, which is used as a fallback.
**\[4\]** This copy assignment is also used for move assignment. We could implement both assignments separately, taking `const T&` and `T&&`. +[friend]: https://stackoverflow.com/q/56795676/5740428 +[noexcept]: https://en.cppreference.com/w/cpp/language/noexcept_spec +[list]: https://en.cppreference.com/w/cpp/container/list/list +[adl]: https://en.cppreference.com/w/cpp/language/adl +[swap]: https://en.cppreference.com/w/cpp/algorithm/swap + ## Pro & Contra :white_check_mark: simple implementation of assignments (and move constructor)
:white_check_mark: well-defined self-assignment
-:white_check_mark: **[noexcept](https://en.cppreference.com/w/cpp/language/noexcept_spec)** copy/move assignment -if [std::is_nothrow_swappable](https://en.cppreference.com/w/cpp/types/is_swappable)
+:white_check_mark: **[noexcept][noexcept]** copy/move assignment if [std::is_nothrow_swappable][swappable]
:x: copying always takes place, even for self-assignment
:x: must implement custom `swap` instead of using `std::swap` +[swappable]: https://en.cppreference.com/w/cpp/types/is_swappable + ## See Also <:stackoverflow:874353689031233606> [What is the copy-and-swap idiom?](https://stackoverflow.com/a/3279550/5740428) (must read!)
diff --git a/wiki_articles/endl.md b/wiki_articles/endl.md index baf91e2..bf771e7 100644 --- a/wiki_articles/endl.md +++ b/wiki_articles/endl.md @@ -1,32 +1,35 @@ # About `std::endl`, Buffers, and Flushing -I/O in C++ -(**[std::cout](https://en.cppreference.com/w/cpp/io/cout)**, i.e. -**[std::ostream](https://en.cppreference.com/w/cpp/io/basic_ostream)**) -is *buffered*, which means that not every character you write to the stream -is instantly written through to the terminal/disk. -Doing so would be very slow. +I/O in C++ (**[std::cout][cout]**, i.e. **[std::ostream][ostream]**) is *buffered*, which means that not every character +you write to the stream is instantly written through to the terminal/disk. Doing so would be very slow. Instead, there is a buffer of e.g. 8192 bytes and when it's full, all data is written through to the OS, i.e. *flushed* in one syscall. This is much more efficient. +[cout]: https://en.cppreference.com/w/cpp/io/cout +[ostream]: https://en.cppreference.com/w/cpp/io/basic_ostream + ## What Is *Flushing*? *Flushing* means that all characters currently in the buffer are written through, and the buffer is cleared. -Use **[<< std::flush](https://en.cppreference.com/w/cpp/io/manip/flush)** -or **[.flush()](https://en.cppreference.com/w/cpp/io/basic_ostream/flush)** +Use **[<< std::flush][ioflush]** +or **[.flush()][oflush]** to flush, or use -**[std::cerr](https://en.cppreference.com/w/cpp/io/cerr)**, which is unbuffered. +**[std::cerr][cerr]**, which is unbuffered. + +[ioflush]: https://en.cppreference.com/w/cpp/io/manip/flush +[oflush]: https://en.cppreference.com/w/cpp/io/basic_ostream/flush +[cerr]: https://en.cppreference.com/w/cpp/io/cerr ## `std::endl` **[std::endl](https://en.cppreference.com/w/cpp/io/manip/endl)** is an -[I/O manipulator](https://en.cppreference.com/w/cpp/io/manip) which writes a -newline character to the stream, and flushes it. +[I/O manipulator](https://en.cppreference.com/w/cpp/io/manip) which writes a newline character to the stream, and +flushes it. Use `<< '\n'` if you don't need to flush. diff --git a/wiki_articles/enum.md b/wiki_articles/enum.md index 9e88ad6..7b602ff 100644 --- a/wiki_articles/enum.md +++ b/wiki_articles/enum.md @@ -1,9 +1,7 @@ # Scoped and Unscoped Enumerations -In C++, `enum` introduces an -[unscoped enumeration](https://en.cppreference.com/w/cpp/language/enum#Unscoped_enumerations), -and `enum class` or `enum struct` introduce a -[scoped enumeration](https://en.cppreference.com/w/cpp/language/enum#Scoped_enumerations). +In C++, `enum` introduces an [unscoped enumeration][enum], and `enum class` or `enum struct` introduce a +[scoped enumeration][enumclass]. ```cpp enum class Fruit : char { NONE, // enumerator-list, NONE = 0 @@ -13,6 +11,9 @@ enum class Fruit : char { Fruit apple = Fruit::APPLE; ``` +[enum]: https://en.cppreference.com/w/cpp/language/enum#Unscoped_enumerations +[enumclass]: https://en.cppreference.com/w/cpp/language/enum#Scoped_enumerations + ## Scoped Enumeration (C++-only) - underlying type is `int` diff --git a/wiki_articles/erase_remove.md b/wiki_articles/erase_remove.md index 62f24b6..61022ca 100644 --- a/wiki_articles/erase_remove.md +++ b/wiki_articles/erase_remove.md @@ -1,10 +1,9 @@ # Erase-Remove Idiom -Elements from -**[std::string](https://en.cppreference.com/w/cpp/string/basic_string)** -and -**[std::vector](https://en.cppreference.com/w/cpp/container/vector)** -can be removed using the erase-remove idiom. +Elements from **[std::string][string]** and **[std::vector][vector]** can be removed using the erase-remove idiom. + +[string]: https://en.cppreference.com/w/cpp/string/basic_string +[vector]: https://en.cppreference.com/w/cpp/container/vector ## Example: Removing Every Zero From A Vector ```cpp diff --git a/wiki_articles/formatting.md b/wiki_articles/formatting.md index 97ad3a0..2606af4 100644 --- a/wiki_articles/formatting.md +++ b/wiki_articles/formatting.md @@ -18,14 +18,14 @@ std::cout << "hi\n"; // is clearly visible ## Auto-Formatting with clang-format -For C/C++, you can use -**[clang-format](https://clang.llvm.org/docs/ClangFormat.html)** -to decide on a style, and apply it automatically to your files. -You can use it in the terminal, or through an editor plugin. +For C/C++, you can use **[clang-format][cf]** to decide on a style, and apply it automatically to your files. You can +use it in the terminal, or through an editor plugin. Most IDEs will also let you configure a style in their settings, but clang-format is universal. +[cf]: https://clang.llvm.org/docs/ClangFormat.html + ## See Support/Plugins - **[VS Code](https://code.visualstudio.com/docs/cpp/cpp-ide#_code-formatting)** diff --git a/wiki_articles/forward.md b/wiki_articles/forward.md index 72c79c0..3b23074 100644 --- a/wiki_articles/forward.md +++ b/wiki_articles/forward.md @@ -1,9 +1,7 @@ # Perfect Forwarding and Forwarding References -References of the form `T&&` are -*[forwarding references](https://en.cppreference.com/w/cpp/language/reference#Forwarding_references)* -if `T` is a template parameter of the current function template. -These references have special deduction rules: +References of the form `T&&` are *[forwarding references][fr]* if `T` is a template parameter of the current function +template. These references have special deduction rules: ```cpp template void f(T&& r); // r is a forwarding reference @@ -17,18 +15,19 @@ f(x); // (reference collapsing) auto&& a = x; // decltype(a) = int& ``` +[fr]: https://en.cppreference.com/w/cpp/language/reference#Forwarding_references + ## Perfectly Forwarding Function Arguments With `std::forward` -No matter what `T` deduces to, the expression `r` -is an -*[lvalue](https://en.cppreference.com/w/cpp/language/value_category#lvalue)* -when used inside the function `f`. -**[std::forward](https://en.cppreference.com/w/cpp/utility/forward)** -recovers the reference type: +No matter what `T` deduces to, the expression `r` is an *[lvalue][lvalue]* when used inside the function `f`. +**[std::forward][forward]** recovers the reference type: ```cpp std::forward(r) // yields int&& if T = int std::forward(r) // yields int& if T = int& ``` +[lvalue]: https://en.cppreference.com/w/cpp/language/value_category#lvalue +[forward]: https://en.cppreference.com/w/cpp/utility/forward + ## See Also <:stackoverflow:1074747016644661258> *[Purpose of std::forward](https://stackoverflow.com/q/3582001/5740428)*
diff --git a/wiki_articles/int_size.md b/wiki_articles/int_size.md index ca2f128..99de5a8 100644 --- a/wiki_articles/int_size.md +++ b/wiki_articles/int_size.md @@ -13,8 +13,7 @@ long long │ ≤ -2^63 * │ ≥ 2^63 - 1 │ ≥ 2^64 - 1 ## :interrobang: Are Bytes Not Always 8 Bits? -A *[byte](https://eel.is/c++draft/intro.memory#def:byte)* -, which has the same size as `char` is the +A *[byte](https://eel.is/c++draft/intro.memory#def:byte)*, which has the same size as `char` is the smallest addressable unit of memory. It must be 8 bits at least, and is exactly 8 bits on diff --git a/wiki_articles/overload_equality.md b/wiki_articles/overload_equality.md index d6afd23..92df070 100644 --- a/wiki_articles/overload_equality.md +++ b/wiki_articles/overload_equality.md @@ -1,8 +1,9 @@ # Overloading the Equality Comparison Operator The equality comparison operator returns `true` iff one object is equal to another. -Defining this operator makes a type -*[EqualityComparable](https://en.cppreference.com/w/cpp/named_req/EqualityComparable)* +Defining this operator makes a type *[EqualityComparable][1]* + +[1]: https://en.cppreference.com/w/cpp/named_req/EqualityComparable ## Example ```cpp diff --git a/wiki_articles/overload_less.md b/wiki_articles/overload_less.md index 13eaf2c..b63ad7a 100644 --- a/wiki_articles/overload_less.md +++ b/wiki_articles/overload_less.md @@ -1,10 +1,11 @@ # Overloading the Less Than Operator -The less than operator returns `true` iff one object less than the other. -If it establishes a [strict weak ordering](https://en.wikipedia.org/wiki/Weak_ordering#Strict_weak_orderings), -it makes a type -*[LessThanComparable](https://en.cppreference.com/w/cpp/named_req/LessThanComparable)*, -which allows using the type in a `std::map`, in `std::sort` and other algorithms. +The less than operator returns `true` iff one object less than the other. If it establishes a [strict weak ordering][1], +it makes a type *[LessThanComparable][2]*, which allows using the type in a `std::map`, in `std::sort` and other +algorithms. + +[1]: https://en.wikipedia.org/wiki/Weak_ordering#Strict_weak_orderings +[2]: https://en.cppreference.com/w/cpp/named_req/LessThanComparable ## Example ```cpp diff --git a/wiki_articles/random.md b/wiki_articles/random.md index 85742b2..12825be 100644 --- a/wiki_articles/random.md +++ b/wiki_articles/random.md @@ -1,9 +1,12 @@ # Generating Random Numbers in C++ -The [](https://en.cppreference.com/w/cpp/header/random) -header in C++ provides (pseudo-)random number generation (PRNG): -- *[UniformRandomBitGenerators](https://en.cppreference.com/w/cpp/named_req/UniformRandomBitGenerators)* produce random bits (entropy) -- *[RandomNumberDistributions](https://en.cppreference.com/w/cpp/named_req/RandomNumberDistribution)* use entropy to generate random numbers +The [][1] header in C++ provides (pseudo-)random number generation (PRNG): +- *[UniformRandomBitGenerators][2]* produce random bits (entropy) +- *[RandomNumberDistributions][3]* use entropy to generate random numbers + +[1]: https://en.cppreference.com/w/cpp/header/random +[2]: https://en.cppreference.com/w/cpp/named_req/UniformRandomBitGenerators +[3]: https://en.cppreference.com/w/cpp/named_req/RandomNumberDistribution ## Example: Printing Ten Random Dice Rolls ```cpp diff --git a/wiki_articles/safety.md b/wiki_articles/safety.md index 07dd834..8078aca 100644 --- a/wiki_articles/safety.md +++ b/wiki_articles/safety.md @@ -10,9 +10,10 @@ Here are some crucial practices: - `-Wextra` for GCC and clang catch most common mistakes. -You can also use [clang-tidy](https://clang.llvm.org/extra/clang-tidy/), -[IntelliSense](https://code.visualstudio.com/docs/editor/intellisense), -and other diagnostics (often integrated into IDEs). +You can also use [clang-tidy][1], [IntelliSense][2], and other diagnostics (often integrated into IDEs). + +[1]: https://clang.llvm.org/extra/clang-tidy/ +[2]: https://code.visualstudio.com/docs/editor/intellisense ## No Unsafe Functions diff --git a/wiki_articles/scanf_whitespace.md b/wiki_articles/scanf_whitespace.md index 6d1861f..084d151 100644 --- a/wiki_articles/scanf_whitespace.md +++ b/wiki_articles/scanf_whitespace.md @@ -1,11 +1,11 @@ # Handling Whitespace in scanf -When the user presses space or enter in the console, -this puts `' '` and `'\n'` *[whitespace](https://en.wikipedia.org/wiki/Whitespace_character)* -characters into `stdio` respectively. -When reading an `int*` with `%d` or `float*` with `%f`, **[scanf](https://en.cppreference.com/w/c/io/fscanf)** -skips any leading whitespace. -However, `%c` for `char*` extracts whitespace characters. +When the user presses space or enter in the console, this puts `' '` and `'\n'` *[whitespace][whitespace]* characters +into `stdio` respectively. When reading an `int*` with `%d` or `float*` with `%f`, **[scanf][scanf]** skips any leading +whitespace. However, `%c` for `char*` extracts whitespace characters. + +[whitespace]: https://en.wikipedia.org/wiki/Whitespace_character +[scanf]: https://en.cppreference.com/w/c/io/fscanf ## Example Problem Say the user enters `" 70 f"`, and we want to read `70` and `f` into `int` and `char` respectively: diff --git a/wiki_articles/sequencing.md b/wiki_articles/sequencing.md index f3d061a..432374a 100644 --- a/wiki_articles/sequencing.md +++ b/wiki_articles/sequencing.md @@ -1,7 +1,6 @@ # What Is Sequencing, and What Are Sequence Points? -Some operations in C++ are *sequenced* before others, meaning that they happen -first. +Some operations in C++ are *sequenced* before others, meaning that they happen first. Unless otherwise stated, operations are *unsequenced*. @@ -37,7 +36,7 @@ When two operations are unsequenced, and this can change the result, it's UB: ```cpp int i = 0; int r = ++i + i; -// r == 1, or r == 2 ?! +// r == 1, or r == 2 ?! ``` diff --git a/wiki_articles/smart_ptr.md b/wiki_articles/smart_ptr.md index bfea5f2..2e960d6 100644 --- a/wiki_articles/smart_ptr.md +++ b/wiki_articles/smart_ptr.md @@ -1,8 +1,7 @@ # Smart Pointers in C++ -Smart pointers are types which manage a raw pointer in their constructors and destructors. -This way, you don't have to use `new`/`delete` manually, -which is easy to forget and hard to do correctly, especially when handling exceptions. +Smart pointers are types which manage a raw pointer in their constructors and destructors. This way, you don't have to +use `new`/`delete` manually, which is easy to forget and hard to do correctly, especially when handling exceptions. ## std::unique_ptr @@ -33,8 +32,12 @@ std::unique_ptr = ``` ## Relevant Links -- **[std::unique_ptr](https://en.cppreference.com/w/cpp/memory/unique_ptr)**, **[std::shared_ptr](https://en.cppreference.com/w/cpp/memory/shared_ptr)**, **[std::weak_ptr](https://en.cppreference.com/w/cpp/memory/weak_ptr)** +- **[std::unique_ptr][1]**, **[std::shared_ptr][2]**, **[std::weak_ptr][3]** - *[Smart Pointer Casts](https://en.cppreference.com/w/cpp/memory/shared_ptr/pointer_cast)* - [Standard library header ](https://en.cppreference.com/w/cpp/header/memory)
<:stackoverflow:1074747016644661258> [What is a smart pointer and when should I use one?](https://stackoverflow.com/q/106508/5740428) + +[1]: https://en.cppreference.com/w/cpp/memory/unique_ptr +[2]: https://en.cppreference.com/w/cpp/memory/shared_ptr +[3]: https://en.cppreference.com/w/cpp/memory/weak_ptr diff --git a/wiki_articles/std_array.md b/wiki_articles/std_array.md index 3de412d..67a33b1 100644 --- a/wiki_articles/std_array.md +++ b/wiki_articles/std_array.md @@ -4,9 +4,13 @@ C-style arrays have important shortcomings:
:no_entry: cannot be returned from functions
:no_entry: are not assignable with `=`
-:no_entry: can only be initialized via `""`, `{}`, or *[default initialization](https://en.cppreference.com/w/cpp/language/default_initialization)*
-:warning: might implicitly [decay to pointers](https://64.github.io/cpp-faq/decay/), notably C arrays are not passed by value to functions
-:warning: might be [variable-length arrays](https://en.wikipedia.org/wiki/Variable-length_array) (VLAs), if the developer makes a mistake +:no_entry: can only be initialized via `""`, `{}`, or *[default initialization][1]*
+:warning: might implicitly [decay to pointers][2], notably C arrays are not passed by value to functions
+:warning: might be [variable-length arrays][3] (VLAs), if the developer makes a mistake + +[1]: https://en.cppreference.com/w/cpp/language/default_initialization +[2]: https://64.github.io/cpp-faq/decay/ +[3]: https://en.wikipedia.org/wiki/Variable-length_array **[std::array](https://en.cppreference.com/w/cpp/container/array)** is a standard library container and *[aggregate type](https://en.cppreference.com/w/cpp/language/aggregate_initialization)* diff --git a/wiki_articles/strict_weak.md b/wiki_articles/strict_weak.md index 3fa9794..d8f4a96 100644 --- a/wiki_articles/strict_weak.md +++ b/wiki_articles/strict_weak.md @@ -1,17 +1,17 @@ # What Is a Strict Weak Ordering in C++? -Algorithms like -**[std::sort](https://en.cppreference.com/w/cpp/algorithm/sort)** -and containers like -**[std::set](https://en.cppreference.com/w/cpp/container/map)** require a -*[Compare](https://en.cppreference.com/w/cpp/named_req/Compare)* function, -which induces a *[strict weak ordering](https://en.wikipedia.org/wiki/Weak_ordering#Strict_weak_orderings)*. -This means that the comparison `comp(x, y)` has to behave similar to `x < y`: +Algorithms like **[std::sort][sort]** and containers like **[std::set]()** require a *[Compare][cmp]* function, which +induces a *[strict weak ordering][sw]*. This means that the comparison `comp(x, y)` has to behave similar to `x < y`: 1. `x < x` is false (*Irreflexivity*) (this makes it *strict*) 2. `x < y && y < z` implies `x < z` (*Transitivity*) 3. `x < y` implies `!(y < x)` (*Asymmetry*) 4. (see below) +[sort]: https://en.cppreference.com/w/cpp/algorithm/sort +[set]: https://en.cppreference.com/w/cpp/container/set +[cmp]: https://en.cppreference.com/w/cpp/named_req/Compare +[sw]: https://en.wikipedia.org/wiki/Weak_ordering#Strict_weak_orderings + ## 4. Transitivity of Equivalence Elements are allowed to be equivalent, i.e. `equiv(x, y)` is similar to `x == y`: - let `equiv(x, y)` be `!(x < y) && !(y < x)`