Skip to content

Commit

Permalink
Merge pull request #2 from jeremy-rifkin/jr/ref-links
Browse files Browse the repository at this point in the history
Add support for reference-style links. Cleanup a bunch of articles and minor fixes
  • Loading branch information
jeremy-rifkin authored Jul 31, 2023
2 parents d5a5035 + 090c5bd commit 6787e4b
Show file tree
Hide file tree
Showing 23 changed files with 142 additions and 112 deletions.
17 changes: 12 additions & 5 deletions wiki_articles/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
```
Expand Down
8 changes: 4 additions & 4 deletions wiki_articles/ask.md
Original file line number Diff line number Diff line change
@@ -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/

<!-- inline -->
## What to Post
Expand Down
9 changes: 4 additions & 5 deletions wiki_articles/bitint.md
Original file line number Diff line number Diff line change
@@ -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

<!-- inline -->
## GCC
Expand Down
6 changes: 4 additions & 2 deletions wiki_articles/c99.md
Original file line number Diff line number Diff line change
@@ -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)**<br>
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.
Expand Down
15 changes: 7 additions & 8 deletions wiki_articles/cas.md
Original file line number Diff line number Diff line change
@@ -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<T>::compare_exchange(T& expected, T desired) {
T old = load(); // All of this happens atomically.
Expand All @@ -17,6 +11,11 @@ bool atomic<T>::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<node*> next; };
Expand Down
12 changes: 7 additions & 5 deletions wiki_articles/class_struct.md
Original file line number Diff line number Diff line change
@@ -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

<!-- inline -->
## `class`
Expand Down
7 changes: 4 additions & 3 deletions wiki_articles/conditional.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
21 changes: 14 additions & 7 deletions wiki_articles/copy_swap.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)<br>
**\[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]<br>
**\[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)<br>
**\[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)<br>
**\[3\]** Because of [argument-dependent lookup (ADL)][adl],
overloaded `swap` functions may be called instead of<br>
**[std::swap](https://en.cppreference.com/w/cpp/algorithm/swap)**, which is used as a fallback.<br>
**[std::swap][swap]**, which is used as a fallback.<br>
**\[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)<br>
:white_check_mark: well-defined self-assignment<br>
:white_check_mark: **[noexcept](https://en.cppreference.com/w/cpp/language/noexcept_spec)** copy/move assignment
if [std::is_nothrow_swappable<T>](https://en.cppreference.com/w/cpp/types/is_swappable)<br>
:white_check_mark: **[noexcept][noexcept]** copy/move assignment if [std::is_nothrow_swappable<T>][swappable]<br>
:x: copying always takes place, even for self-assignment<br>
: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!)<br>
Expand Down
25 changes: 14 additions & 11 deletions wiki_articles/endl.md
Original file line number Diff line number Diff line change
@@ -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

<!-- inline -->
## 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

<!-- inline -->
## `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.

Expand Down
9 changes: 5 additions & 4 deletions wiki_articles/enum.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
<!-- inline -->
## Scoped Enumeration (C++-only)
- underlying type is `int`
Expand Down
9 changes: 4 additions & 5 deletions wiki_articles/erase_remove.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 4 additions & 4 deletions wiki_articles/formatting.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ std::cout << "hi\n"; // is clearly visible
<!-- inline -->
## 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
<!-- inline -->
## See Support/Plugins
- **[VS Code](https://code.visualstudio.com/docs/cpp/cpp-ide#_code-formatting)**
Expand Down
19 changes: 9 additions & 10 deletions wiki_articles/forward.md
Original file line number Diff line number Diff line change
@@ -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 <class T>
void f(T&& r); // r is a forwarding reference
Expand All @@ -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<T>(r) // yields int&& if T = int
std::forward<T>(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)*<br>
Expand Down
3 changes: 1 addition & 2 deletions wiki_articles/int_size.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ long long │ ≤ -2^63 * │ ≥ 2^63 - 1 │ ≥ 2^64 - 1

<!-- inline -->
## :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
Expand Down
5 changes: 3 additions & 2 deletions wiki_articles/overload_equality.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 6 additions & 5 deletions wiki_articles/overload_less.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 7 additions & 4 deletions wiki_articles/random.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Generating Random Numbers in C++

The [<random>](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 [<random>][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
Expand Down
7 changes: 4 additions & 3 deletions wiki_articles/safety.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<!-- inline -->
## No Unsafe Functions
Expand Down
Loading

0 comments on commit 6787e4b

Please sign in to comment.