Snippets·Free
C and C++ snippets
14 C++ snippets (range for, lambdas, unique_ptr, optional, structured bindings, threads, chrono) and 6 for C (include guard, malloc check, fgets loop, linked list node). The C ones appear in .c and .h files.
Free to install.
If PocketCode is installed on your Android device, this opens the page in the app.
Preview
5 of 20
main with argumentsmainargs
Entry point that checks the argument count and prints usage
#include <iostream>
int main(int argc, char* argv[]) {
if (argc < ${1:2}) {
std::cerr << "usage: " << argv[0] << " ${2:<file>}\n";
return 1;
}
$0
return 0;
}Range-based forforr
Loop over a container by const reference
for (const auto& ${1:item} : ${2:items}) {
$0
}Sort with a lambdasortl
std::sort with a custom comparison
std::sort(${1:v}.begin(), ${1:v}.end(), [](const auto& a, const auto& b) {
return a.${2:value} < b.${2:value};
});unique_ptruptr
Owning pointer created with make_unique
auto ${1:ptr} = std::make_unique<${2:Widget}>($3);Class with a constructorctor
Class with an explicit constructor, a getter and a private member
class ${1:Widget} {
public:
explicit ${1:Widget}(${2:int value}) : ${3:value_}(${4:value}) {}
${5:int} ${6:value}() const { return ${3:value_}; }
private:
${5:int} ${3:value_};
};Changes in 1.0.0
First version.