Skip to content

Commit d5c867d

Browse files
committed
tones of up
1 parent a3e220d commit d5c867d

33 files changed

+2141
-41
lines changed

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ read more [here](https://ros-developer.com/2017/11/08/docker/)
103103
## [C++ Tutorials](#)
104104
* [Align](docs/align.md)
105105
* [Allocator](docs/allocator.md)
106-
* [Algorithms library](docs/algorithms.md)
106+
* [Algorithms Library](docs/algorithms.md)
107107
* [Assert](docs/assert.md)
108108
* [Atomic operations and Atomic Types](docs/atomic.md)
109109
* [Asynchronous programming](docs/asynchronous_programming.md)
@@ -113,23 +113,24 @@ read more [here](https://ros-developer.com/2017/11/08/docker/)
113113
* [Callbacks](docs/callbacks.md)
114114
* [Callable Objects, std::function, std::bind, Lambda](docs/callable_objects_function_bind_lambda.md)
115115
* [Clock, Date, Time](docs/date_time.md)
116-
* [Conditional Compilation](src/conditional_compilation.cpp)
116+
* [Conditional Compilation From CMakeLists](src/conditional_compilation.cpp)
117117
* [Containers](docs/containers.md)
118118
* [vector](docs/vector.md)
119119
* [lists](src/lists.cpp)
120120
* [C arrays, std::array, span](docs/array_span.md)
121121
* [set, map, pair, tuple, tie, unordered_map, multimap, unordered_set, multiset](docs/set_map_pair_tuple.md)
122122
* [stack, queue, priority_queue, deque](docs/stack_queue_priority_queue_deque.md)
123123
* [Const, Constexpr and Mutable](docs/const_constexpr_mutable.md)
124+
* [Immutable Objects](docs/immutable_objects.md)
124125
* [Data Types, Numerical Limits, Machine Epsilon, Precision](docs/primitive_data_types_numerical_limits_machine_epsilon_precision.md)
125126
* [Data Types Conversions, Casting](docs/type_conversions_casting.md)
126-
* [Decay](docs/std_decay.md)
127+
* [Decay](docs/decay.md)
127128
* [Dynamic Memory Allocation in C](docs/dynamic_memory_allocation.md)
128129
* [Enum](docs/enum.md)
129130
* [Error Handling](docs/error_handling.md)
130131
* [Exception Handling, noexcept](docs/exception_handling.md)
131132
* [Extern Variables, Extern Functions](src/extern/variable/main.cpp)
132-
* [File System ](src/filesystem.cpp)
133+
* [File System](docs/filesystem.md)
133134
* [Forking](docs/fork.md)
134135
* [Forwarding Reference](docs/forward.md)
135136
* [Functions, Extern Function, Function Objects, Function Pointer, Inline Functions](docs/functions.md)
@@ -140,12 +141,12 @@ read more [here](https://ros-developer.com/2017/11/08/docker/)
140141
* [Lambda](docs/lambda.md)
141142
* [Literals](docs/literals.md)
142143
* [Loading Classes Dynamically From Plugins](docs/loading_classes_dynamically_from_plugins.md)
143-
* [Macro](src/macro.cpp)
144+
* [Macros](docs/macros.md)
144145
* [Memory Error Detection With Memory Address Sanitizer and Valgrind](docs/memory_leaking_valgrind.md)
145146
* [Modules](docs/cpp_modules.md)
146147
* [Nested Namespaces, Unnamed/Anonymous Namespaces](docs/nested_unnamed_anonymous_namespaces.md)
147148
* [Numeral Systems in C++ Decimal, Binary, Octal, Hexadecimal](docs/numeral_system.md)
148-
* [Optional](src/optional.cpp)
149+
* [Optional](docs/optional.md)
149150
* [Parameter Pack Expansion ...](docs/parameter_pack_expansion_(...).md)
150151
* [Register Keyword](docs/register.md)
151152
* [Regex](docs/regex.md)
@@ -164,13 +165,13 @@ read more [here](https://ros-developer.com/2017/11/08/docker/)
164165
* [Structs](src/structs.cpp)
165166
* [Structured binding declaration](src/structured_binding_declaration.cpp)
166167
* [Switch Case](src/switch_case.cpp)
167-
* [Template, Expression templates](docs/templates.md)
168+
* [Template, Expression Templates](docs/templates.md)
168169
* [Ternary (One Line If)](src/ternary.cpp)
169170
* [Temporary Objects](docs/temporary_objects.md)
170171
* [Track memory allocations(overriding new operator)](docs/track_memory_allocations_overriding_new_operator.md)
171172
* [Trivial, standard-layout, Passive/ Plain old data structure (PDS)/ (POD), and literal types](docs/trivial_standard_pds_pod_layout.md)
172173
* [Type Traits](docs/type_traits.md)
173-
* [Typedef, Type alias (using keyword))](src/typedef.cpp)
174+
* [Typedef, Type alias (using keyword))](docs/typedef.md)
174175
* [type_dispatch, integral_constant, true/false type](src/type_dispatch_integral_constant_true_false_type.cpp)
175176
* [Unions](docs/union.md)
176177
* [Variadic Templates Function](src/variadic_templates.cpp)
@@ -241,7 +242,7 @@ read more [here](https://ros-developer.com/2017/11/08/docker/)
241242
* [Return Type Resolver](docs/return_type_resolver.md)
242243
* [Resource Acquisition Is Initialization (RAII)](docs/RAII.md)
243244
* [Rule of 5](docs/rule_of_5.md)
244-
* [Substitution failure is not an error (SFINAE)](src/SFINAE.cpp)
245+
* [Substitution failure is not an error (SFINAE)](docs/SFINAE.md)
245246
* [Stack overflow](docs/stack_overflow.md)
246247
* [Stack Unwinding](src/stack_unwinding.cpp)
247248
* [Type Erasure](docs/type_erasure.md)

docs/RAII.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ In this example, `FileHandler` is a custom class that manages a file resource. T
7474

7575

7676

77-
Certainly! Let's create some more practical examples of RAII in C++ to illustrate how it can be applied in real-world scenarios.
77+
Let's create some more practical examples of RAII in C++ to illustrate how it can be applied in real-world scenarios.
7878

7979
### Example 1: Database Connection Handler
8080
Imagine you're working on an application that requires database interactions. You can use RAII to manage database connections.

docs/RTTI.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Run-Time Type Information (RTTI) is a feature provided by some programming langu
1313

1414
5. **Controversy and Alternatives**: While RTTI provides dynamic type information capabilities, its use is sometimes debated among developers. Some argue that excessive use of RTTI may indicate a design problem in the application. Alternatives like visitor patterns, type tags, and dynamic interfaces are often used in place of RTTI to achieve similar functionality with potentially less overhead or more controlled type-handling mechanisms.
1515

16-
Certainly! A common scenario where RTTI is useful involves polymorphic class hierarchies, where you need to perform specific operations based on the actual type of the object at runtime. Let's consider a classic example in C++ involving a base class and multiple derived classes.
16+
A common scenario where RTTI is useful involves polymorphic class hierarchies, where you need to perform specific operations based on the actual type of the object at runtime. Let's consider a classic example in C++ involving a base class and multiple derived classes.
1717

1818
### Scenario:
1919
Imagine we have a class hierarchy for different types of media content, like `Audio`, `Video`, and `Image`, all derived from a base class `Media`. We have a function that takes a pointer to `Media` and needs to perform certain actions depending on whether the actual object is `Audio`, `Video`, or `Image`.

docs/SFINAE.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# SFINAE
2+
SFINAE, which stands for "Substitution Failure Is Not An Error," is a concept in C++ template programming. It's a rule that applies during the template instantiation process. The idea is that if a substitution of template parameters into a template results in an invalid code, this is not in itself an error. Instead, the invalid template is simply discarded from the set of potential templates to use.
3+
4+
This concept is particularly useful for creating template specializations that are only valid for certain types or conditions, enabling more flexible and powerful template designs.
5+
6+
### Basic Example of SFINAE
7+
8+
Here's a simple example to illustrate SFINAE:
9+
10+
```cpp
11+
#include <iostream>
12+
#include <type_traits>
13+
14+
// Base template
15+
template <typename T>
16+
typename std::enable_if<std::is_integral<T>::value, bool>::type isIntegral(T) {
17+
return true;
18+
}
19+
20+
// Template specialization for non-integral types
21+
template <typename T>
22+
typename std::enable_if<!std::is_integral<T>::value, bool>::type isIntegral(T) {
23+
return false;
24+
}
25+
26+
int main() {
27+
std::cout << std::boolalpha;
28+
std::cout << "isIntegral(10): " << isIntegral(10) << std::endl; // Outputs: true
29+
std::cout << "isIntegral(3.14): " << isIntegral(3.14) << std::endl; // Outputs: false
30+
31+
return 0;
32+
}
33+
```
34+
35+
In this example, there are two versions of the `isIntegral` function template. The first version is enabled (via `std::enable_if`) only for integral types, while the second version is enabled for non-integral types. When you call `isIntegral` with an integer, the first version is instantiated. If you call it with a non-integer, the second version is instantiated.
36+
37+
### Explanation
38+
39+
- `std::enable_if`: This is a standard library utility that provides a member typedef `type` if the given boolean constant is true. If the boolean is false, there's no member typedef. This utility is commonly used for controlling template instantiation.
40+
41+
- `std::is_integral`: This is a type trait that checks if a type is an integral type (like int, char, etc.).
42+
43+
### How SFINAE Comes Into Play
44+
45+
In the example, if `T` is an integral type, the `std::enable_if<std::is_integral<T>::value, bool>::type` becomes `bool`, so the first `isIntegral` function template is valid. If `T` is not an integral type, this substitution fails, but due to SFINAE, this failure is not an error; instead, the first `isIntegral` template is simply discarded, and the compiler looks for other templates (in this case, the second `isIntegral`).
46+
47+
SFINAE allows for powerful metaprogramming techniques in C++, enabling the creation of templates that can adapt to different types and conditions at compile time, leading to more efficient and tailored code.

0 commit comments

Comments
 (0)