Skip to content

Commit a2fab03

Browse files
committed
Added vector manipulation in C++
1 parent 600723c commit a2fab03

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

public/data/cpp.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,45 @@
4141
"author": "saminjay"
4242
}
4343
]
44+
},
45+
{
46+
"categoryName": "Array Manipulation",
47+
"snippets": [
48+
{
49+
"title": "Transform Vector",
50+
"description": "Transforms a vector using a function",
51+
"code": [
52+
"#include <ranges>",
53+
"#include <vector>",
54+
"",
55+
"template <typename T, typename F>",
56+
"auto transform(const std::vector<T>& vec, F&& transformer) {",
57+
" using U = std::invoke_result_t<F, T>;",
58+
" return vec",
59+
" | std::views::transform(std::forward<F>(transformer))",
60+
" | std::ranges::to<std::vector<U>>();",
61+
"}"
62+
],
63+
"tags": ["cpp", "array", "transform", "utility"],
64+
"author": "majvax"
65+
},
66+
{
67+
"title": "Filter Vector",
68+
"description": "Filters a vector using a predicate function",
69+
"code": [
70+
"#include <ranges>",
71+
"#include <vector>",
72+
"",
73+
"template <typename T, typename P>",
74+
"auto filter(const std::vector<T>& vec, P&& predicate) {",
75+
" return vec",
76+
" | std::views::filter(std::forward<P>(predicate))",
77+
" | std::ranges::to<std::vector<T>>();",
78+
"}"
79+
],
80+
"tags": ["cpp", "array", "filter", "utility"],
81+
"author": "majvax"
82+
}
83+
]
4484
}
4585
]

0 commit comments

Comments
 (0)