Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 98ddffc

Browse files
committed
Fixed Usage to accommodate to new guidelines
1 parent 4638879 commit 98ddffc

File tree

8 files changed

+44
-2
lines changed

8 files changed

+44
-2
lines changed

‎snippets/cpp/array-manipulation/filter-vector.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,11 @@ auto filter(const std::vector<T>& vec, P&& predicate) {
1515
| std::views::filter(std::forward<P>(predicate))
1616
| std::ranges::to<std::vector<T>>();
1717
}
18+
19+
20+
21+
// Usage:
22+
std::vector<int> vec = {1, 2, 3, 4, 5};
23+
std::vector<int> filtered = filter(vec, [](int i){ return i % 2 == 0; });
24+
// filtered contains 2 and 4
1825
```

‎snippets/cpp/array-manipulation/transform-vector.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,11 @@ auto transform(const std::vector<T>& vec, F&& transformer) {
1616
| std::views::transform(std::forward<F>(transformer))
1717
| std::ranges::to<std::vector<U>>();
1818
}
19+
20+
21+
22+
// Usage:
23+
std::vector<int> vec = {1, 2, 3, 4, 5};
24+
std::vector<int> transformed = transform(vec, [](int i){ return i * 2; });
25+
// transformed containes 2, 4, 6, 8, 10
1926
```

‎snippets/cpp/file-handling/find-files-recursive.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ std::vector<std::filesystem::path> find_files_recursive(const std::string& path,
3232
}
3333

3434

35-
// usage:
35+
36+
// Usage:
37+
3638
// Find all files with size greater than 10MB
3739
auto files = find_files_recursive("Path", [](const auto& p) {
3840
return std::filesystem::file_size(p) > 10 * 1024 * 1024;

‎snippets/cpp/file-handling/find-files.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ std::vector<std::filesystem::path> find_files(const std::string& path, P&& predi
3232
}
3333

3434

35-
// usage:
35+
36+
// Usage:
37+
3638
// Find all files with size greater than 10MB
3739
auto files = find_files("Path", [](const auto& p) {
3840
return std::filesystem::file_size(p) > 10 * 1024 * 1024;

‎snippets/cpp/file-handling/list-directories.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,9 @@ std::vector<std::filesystem::path> list_directories(const std::string& path) {
2929

3030
return files;
3131
}
32+
33+
34+
35+
// Usage:
36+
auto directories = list_directories("Path");
3237
```

‎snippets/cpp/string-manipulation/filter.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,11 @@ std::string filter(const std::string& str, P&& predicate) {
1515
| std::ranges::views::filter(std::forward<P>(predicate))
1616
| std::ranges::to<std::string>();
1717
}
18+
19+
20+
21+
// Usage:
22+
std::string str = "Hello, World!";
23+
std::string filtered = filter(str, [](char c){ return std::isalpha(c); });
24+
std::cout << filtered << std::endl; // HelloWorld
1825
```

‎snippets/cpp/string-manipulation/palindrome.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,9 @@ bool is_palindrome(const std::string& str) {
1818

1919
return std::ranges::equal(sanitized_string, sanitized_string | std::views::reverse);
2020
}
21+
22+
23+
24+
// Usage:
25+
bool pal = is_palindrome("A man, a plan, a canal, Panama"); // true
2126
```

‎snippets/cpp/string-manipulation/transform.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,11 @@ std::string transform(const std::string& str, F&& transformer) {
1515
| std::ranges::views::transform(std::forward<F>(transformer))
1616
| std::ranges::to<std::string>();
1717
}
18+
19+
20+
21+
// Usage:
22+
std::string str = "Hello, World!";
23+
std::string transformed = transform(str, [](char c){ return std::toupper(c); });
24+
std::cout << transformed << std::endl; // HELLO, WORLD!
1825
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /