Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from methylDragon:master #8

Open
wants to merge 66 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
f1f6bdd
Add smart pointer tutorial and extra notes on pointers
methylDragon Jul 3, 2019
8e7ff80
Fix typo
methylDragon Jul 4, 2019
2333d0b
Add C++ section on type resolution
methylDragon Jul 10, 2019
3c387ca
Add C++ sections on lambda and inline functions
methylDragon Jul 10, 2019
4ab91a4
Add C++ data structures tutorial
methylDragon Jul 10, 2019
f17819f
Add C++ iterators section
methylDragon Jul 11, 2019
a627677
Add TOC for C++ data structures section
methylDragon Jul 11, 2019
8d58e8f
Add C++ typedef section
methylDragon Jul 11, 2019
92e10bf
Add ROS launchfile clarification
methylDragon Jul 11, 2019
9bdbfb9
Add C++ templates section (with SFINAE!)
methylDragon Jul 11, 2019
9beb42f
Add TOC for C++ templates section
methylDragon Jul 11, 2019
e7d1a9d
Add clarification for C++ template parameter and arguments
methylDragon Jul 11, 2019
cb95f0c
Append clarification to C++ templates introduction
methylDragon Jul 11, 2019
2ebd76a
Add C++ memory structure section
methylDragon Jul 12, 2019
d2b37ff
Neaten syntax for C++ header section
methylDragon Jul 12, 2019
0cdff54
Add C++ rule of five and object management rules
methylDragon Jul 12, 2019
6718c92
Clarify C++ pass by const reference
methylDragon Jul 12, 2019
10a8cb1
Prefix std:: to relevant commands
methylDragon Jul 12, 2019
8c15678
Add WIP for C++ concurrency and threading section
methylDragon Jul 12, 2019
f2b7789
Fix typo in ROS tutorial
methylDragon Jul 13, 2019
9a0d6c4
Add C++ async section
methylDragon Jul 13, 2019
43c2bc6
Fix typos in Python section
methylDragon Jul 14, 2019
cfe0a03
Add Python __slots__ section
methylDragon Jul 14, 2019
3889e2b
Start Python data structures section
methylDragon Jul 14, 2019
4369a51
Add more Python data structures!
methylDragon Jul 14, 2019
8933bd1
Finish Python data structures
methylDragon Jul 15, 2019
5875ea7
Add Python data structures TOC
methylDragon Jul 15, 2019
e9c1a25
Fix typo in ROS section
methylDragon Jul 17, 2019
54e0b1a
Migrate ROS tutorials
methylDragon Jul 22, 2019
1b40ba0
Neaten C++ tutorials
methylDragon Aug 6, 2019
2a74c5e
Add C++ linkages and preprocessor section
methylDragon Aug 6, 2019
96ae073
Remove junk
methylDragon Aug 6, 2019
8c79cb7
Neaten Regex section
methylDragon Aug 13, 2019
2b50f28
Add CMake Basics section
methylDragon Aug 14, 2019
0bd6d52
Add C/C++ focus clarification for CMake section
methylDragon Aug 14, 2019
28c6841
Refactor variable substitution and fix message bug in CMake section
methylDragon Aug 14, 2019
13df9cf
Add CMake user input section
methylDragon Aug 16, 2019
928acf8
Add warning to C++ Preprocessor section
methylDragon Aug 16, 2019
9a81f1b
Add WIP copy of CMake building section
methylDragon Aug 16, 2019
41c972c
Split CMake building section and advanced scripting section
methylDragon Aug 18, 2019
fd111f0
Add CMake advanced scripting and modules section
methylDragon Aug 18, 2019
19052f2
Update gitignore
methylDragon Aug 22, 2019
99707aa
Add table of contents to several CMake sections
methylDragon Aug 22, 2019
97b61d0
Add clarification to CMake section
methylDragon Aug 30, 2019
25f9eef
Add linked TOC to C++ Threading section
methylDragon Aug 30, 2019
bb340c0
Neaten and clarify C++ Basics Section
methylDragon Sep 11, 2019
af4fa40
Fix Python Introduction formatting
methylDragon Sep 13, 2019
8912f79
Add WIP Java tutorial
methylDragon Sep 13, 2019
7ec4b37
Add variable name (#6)
Oct 3, 2019
12c91dc
Fix C++ lambda typo
methylDragon Jun 1, 2020
ca0a427
Neaten C++ tutorial
methylDragon Feb 28, 2021
b68d8c4
Update Java tutorial
methylDragon Feb 28, 2021
ba98451
Add exception handling to Java tutorial
methylDragon Feb 28, 2021
55b37a2
Add super warning to Java tutorial
methylDragon Mar 2, 2021
8757674
Update C++ - Threading and Concurrency.md (#7)
talayhan Mar 26, 2021
ed210a4
[02-03] - Update C++ (#8)
talayhan Jul 5, 2021
a3d281f
minor fixes - shared_lock, std::ref param to thread (#9)
joepol Jul 5, 2021
113e335
Neaten C++ and MATLAB tutorials
methylDragon Mar 8, 2022
a99ed5e
Add beginnings of Rust syntax reference
methylDragon Mar 8, 2022
abf9218
Neaten C++ tutorial
methylDragon Mar 22, 2022
87a9427
Add Rust toolings and some basic syntax to tutorial
methylDragon Mar 22, 2022
ab29741
Add more Rust basics
methylDragon Mar 22, 2022
9544e16
Add Rust TODOs
methylDragon Mar 22, 2022
ad54b93
Start the Rust Loop Reference
methylDragon Mar 23, 2022
20a5168
Add link to external tutorial in CMake tutorial
methylDragon May 4, 2022
b9dcabf
Add video links to lvalues and rvalue, and move semantics
methylDragon Jun 30, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
*.swap
*.save
*.bak

*.no_toc
109 changes: 73 additions & 36 deletions C++/01 C++ - Introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ I'll be adapting it from the ever amazing Derek Banas: https://www.youtube.com/w

- How **variables, loops, conditionals, etc**. work (Basic coding fundamentals will help a lot!)
- Linux (**Terminal/Console proficiency**) (We're going to need to compile our stuff)
- Gone through the all preceding parts of the tutorial



Expand Down Expand Up @@ -102,8 +101,6 @@ common ones are
`<string>` for strings
`<fstream>` for file input outputs



> Note on `< >` vs `" "`:
>
> The type of symbol you use when importing libraries affects how the compiler prioritises which library to import in the event of a clashing name.
Expand Down Expand Up @@ -186,6 +183,17 @@ Also, constants are usually declared with all caps
`unsigned int` (Same size as signed version)
`long double` (Not less than double)

#### **decltype**

Declared type. You may be able to get the type of a variable by calling decltype on it. No promises though!

```c++
int n = 10;
decltype(n);
```



**Example Variable Initialisation:**

```c++
Expand All @@ -202,6 +210,14 @@ char myChar = 'a';
int x = 6, y = 2;
```

> You can also use the `auto` keyword if you're not sure which type to use, or if the types might vary. Do note that this sometimes involves some overhead.
>
> It does type deduction, which can sometimes avoid implicit type conversions.
>
> ```c++
> auto my_auto = 1;
> ```



#### **Multiple ways to initialise a variable**
Expand Down Expand Up @@ -235,12 +251,12 @@ std::map<int, std::string> map_var { {0, "zero"}, {1, "one"}, {2, "two"} }; // A
**Direct Initialisation**

```c++
int variable(525); // Now stores 5
int variable(525); // Now stores 525

// Note: variable() will not work! You can't initialise an empty variable that way
```

**Copy Initialisation** (Lowest priority, try to avoid)
**Copy Initialisation** (Lowest priority, try to avoid. Because this first generates the value, then copies it into the variable. It's a two step process that uses usually twice the memory and takes longer.)

```c++
// We've seen this before
Expand All @@ -262,6 +278,35 @@ varName = 8;
So you initialised varName as an integer containing 5
Then you changed the data stored in it to 8 instead.

#### **Defining Custom Types**

You can define a type alias by using the `typedef` keyword!

```c++
// Simple typedef
typedef unsigned long ulong;
ulong var_five{5}; // So now we can declare an unsigned long using this type alias!

// Pointer typedef
typedef int* int_ptr;

int a = 5;
int_ptr b = &a;

// Struct typedef
typedef struct
{
int a;
int b;
int c;
} my_struct;

my_struct haha;
haha.a = 1;
haha.b = 2;
haha.c = 3;
```



### 2.6 Outputting Variables and Variable Info <a name="2.6"></a>
Expand Down Expand Up @@ -318,35 +363,33 @@ Example

```c++
int five = 5;
cout << "5++ = " << five++ << endl; // Increment by 1
cout << "++5 = " << ++five << endl; // Increment by 1
cout << "5-- = " << five-- << endl; // Decrement by 1
cout << "--5 = " << --five << endl; // Decrement by 1
cout << "5++ gives " << five++ << endl; // Increment by 1
cout << "++5 gives " << ++five << endl; // Increment by 1
cout << "5-- gives " << five-- << endl; // Decrement by 1
cout << "--5 gives " << --five << endl; // Decrement by 1
```

Returns

```c++
5++ = 5
++5 = 7
5-- = 7
--5 = 5
```
5++ gives 5
++5 gives 7
5-- gives 7
--5 gives 5
```

**That's so weird!**

The reason for this is because when you increment or decrement on the **RIGHT** side, it'll perform the action **AFTER** it gives the value.

If you increment or decrement it on the **LEFT** side, it'll perform the action **BEFORE** it gives the value. The reason you have 7 is because 5++ incremented 5 to a 6, but sent 5 before it incremented, so when you have ++5, it took a 6 to begin with and incremented it to 7, then printed it.
> **Wait a sec, weird behaviour!**
>
> The reason for this is because when you increment or decrement on the **RIGHT** side, it'll perform the action **AFTER** it gives the value.
>
> If you increment or decrement it on the **LEFT** side, it'll perform the action **BEFORE** it gives the value. The reason you have 7 is because 5++ incremented 5 to a 6, but sent 5 before it incremented, so when you have ++5, it took a 6 to begin with and incremented it to 7, then printed it.
>
> **Order of operations! Remember it!**

**Here's another shorthand!**
**Another shorthand!**

`five += 5; // five = five + 5;`
`five -= 5; //five = five - 5;`

**Order of operations**

REMEMBER IT!
`five -= 5; // five = five - 5;`



Expand All @@ -365,10 +408,10 @@ REMEMBER IT!
<= // less than or equal to
```

!! NOTE. "==" IS **NOT** "="

== COMPARES
= ASSIGNS VALUES
> **NOTE**: `==` IS **NOT** `=`
>
> - `==` COMPARES
> - `=` ASSIGNS VALUES

**Logical Operators**

Expand Down Expand Up @@ -847,9 +890,7 @@ rawr

[go to top](#top)

LITERALLY THE BEST THING EVER

THIS IS PART OF WHAT WON ME THE GOOGLE HACKATHON. DEBUGGING LOVE.
LITERALLY THE BEST THING EVER. DEBUGGING LOVE.

```c++
try{ // Try this. If it doesn't work, then it's fine.
Expand Down Expand Up @@ -901,10 +942,6 @@ int b = a; // Error: name 'a' is not in scope







```
. .
. |\-^-/| .
Expand Down
Loading