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

Snippets c++ #103

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

Merged
saminjay merged 21 commits into quicksnip-dev:main from majvax:snippets-c++
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e93bcac
[C++] added snippet
majvax Jan 1, 2025
2a6b1e2
Merge remote-tracking branch 'origin/snippets-c++' into snippets-c++
majvax Jan 1, 2025
aad3f79
[C++] added 3 snippets for string.
majvax Jan 1, 2025
f472a29
Added missing chrono header
majvax Jan 2, 2025
31b43b5
fixed tags
majvax Jan 2, 2025
29112d8
Merge remote-tracking branch 'origin/snippets-c++' into snippets-c++
majvax Jan 2, 2025
4638879
fixed exemple needing std=c++20
majvax Jan 2, 2025
98ddffc
Fixed Usage to accommodate to new guidelines
majvax Jan 2, 2025
aebefde
Fixed all tags + type
majvax Jan 3, 2025
d76dbfd
Revert "Fixed all tags + type"
majvax Jan 3, 2025
c188670
Merge remote-tracking branch 'upstream/main' into snippets-c++
majvax Jan 3, 2025
9364abb
Fixed type and all tags
majvax Jan 3, 2025
3a99176
fixed gh check failing
majvax Jan 3, 2025
c0d6f04
Update consolidated snippets
actions-user Jan 3, 2025
1dd6a8f
Merge branch 'dostonnabotov:main' into snippets-c++
majvax Jan 3, 2025
fce087f
Update consolidated snippets
actions-user Jan 3, 2025
a959e95
Update consolidated snippets
actions-user Jan 3, 2025
4708bd9
Merge remote-tracking branch 'origin/main' into snippets-c++
majvax Jan 4, 2025
112302e
Revert "Merge remote-tracking branch 'origin/main' into snippets-c++"
majvax Jan 6, 2025
60496ec
Merge remote-tracking branch 'origin/main' into snippets-c++
majvax Jan 6, 2025
812842f
Update consolidated snippets
actions-user Jan 6, 2025
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
Prev Previous commit
Next Next commit
[C++] added 3 snippets for string.
  • Loading branch information
majvax committed Jan 1, 2025
commit aad3f798991587209b9f0aee506ef5d1d5e499a0
18 changes: 18 additions & 0 deletions snippets/cpp/string-manipulation/filter.md
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: Filter
description: Filter a string with a predicate function
author: majvax
tags: cpp,string,utility,filtering
---

```cpp
#include <ranges>
#include <string>

template <typename P>
std::string filter(const std::string& str, P&& predicate) {
return str
| std::ranges::views::filter(std::forward<P>(predicate))
| std::ranges::to<std::string>();
}
```
21 changes: 21 additions & 0 deletions snippets/cpp/string-manipulation/palindrome.md
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
title: Palindrome
description: Check if a string is a palindrome or not.
author: majvax
tags: cpp,string,utility
---

```cpp
#include <string>
#include <ranges>
#include <algorithm>

bool is_palindrome(const std::string& str) {
std::string sanitized_string = str
| std::ranges::views::filter([](char c){ return std::isalnum(c); })
| std::ranges::views::transform([](char c){ return std::tolower(c); })
| std::ranges::to<std::string>();

return std::ranges::equal(sanitized_string, sanitized_string | std::views::reverse);
}
```
18 changes: 18 additions & 0 deletions snippets/cpp/string-manipulation/transform.md
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: Transform
description: Transform a string with a function
author: majvax
tags: cpp,string,utility,transform
---

```cpp
#include <ranges>
#include <string>

template <typename F>
std::string transform(const std::string& str, F&& transformer) {
return str
| std::ranges::views::transform(std::forward<F>(transformer))
| std::ranges::to<std::string>();
}
```
Loading

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /