-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcpp.snippets
More file actions
97 lines (90 loc) · 1.87 KB
/
cpp.snippets
File metadata and controls
97 lines (90 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# #include <...>
snippet Inc
#include <${1:iostream}>${2}
# Header Include-Guard
snippet once
#ifndef TAJGA_${1:`substitute(toupper(Filename('$1', 'UNTITLED')), '-', '_', 'g')`}_H_
#define TAJGA_$1_H_
namespace ${2:tajga} {
${3}
} // namespace $2
#endif // TAJGA_$1_H_
# STL
snippet map
typedef std::map<${1:key}, ${2:T}> ${3:map_type};
$3 ${4:map_name};${5}
snippet vector
std::vector<${1:T}> ${2:name};${3}
snippet list
std::list<${1:T}> ${2:name};${3}
# Pointers
snippet up
std::unique_ptr<${1:T}> ${2:name};${3}
snippet sp
std::shared_ptr<${1:T}> ${2:name};${3}
snippet mu
std::make_unique<${1:T}>(${2})${3}
snippet ms
std::make_shared<${1:T}>(${2})${3}
# Namespace
snippet ns
namespace ${1:tajga} {
${2}
} // namespace $1
# Class
snippet cl
class ${1:`substitute(substitute(Filename('$1', 'UNTITLED'), '-', '_', 'g'), '\(\%(\<\l\+\)\%(_\)\@=\)\|_\(\l\)','\u\1\2','g')`}
{
$1($1 const &) = delete;
$1 & operator= ($1 const &) = delete;
public:
$1();
~$1();
${2}
}; // class $1
snippet en
enum class ${1:name} : ${2:int} {
${3:kInvalid} = 0,${4}
kCount
}; // enum class $1
# For Loop
snippet for
for (auto ${2:i} = 0; $2 < ${1:kCount}; ${3:++}$2) {
${4:// code}
}
# Custom For Loop
snippet forr
for (auto ${1:i} = ${2:0}; ${3:$1 < 10}; ${4:++}$1) {
${5:// code}
}
# For Each
snippet fore
for (${1:auto} ${2:i} : ${3:list}) {
${4:// code}
}
# Iteration
snippet iter
for (auto ${1:i} = begin(${2:list}); $1 != end($2); ++$1) {
${3:// code}
}
# Swap idiom
snippet swap
friend void swap(${1:T} & first, $1 & second)
{
using std::swap;
swap(first.${2:x}, second.$2);
swap(first.${3:y}, second.$3);
swap(first.${4:z}, second.$4);${5}
}
# Print
snippet Print
std::ostream & Print(std::ostream & os) const
{
${1}
return os;
}
snippet <<
std::ostream & operator<< (std::ostream & os, ${1:T} const & ${2:name})
{
return $2.Print(os);
}${3}