Skip to content
Open
Changes from all commits
Commits
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
127 changes: 83 additions & 44 deletions snippets/cpp.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
"for": {
"prefix": "for",
"body": [
"for (${size_t} ${i} = ${1:0}; ${i} < ${2:length}; ${i}++)",
"for (${1:size_t} ${2:i} = ${3:0}; ${2:i} < ${4:length}; ++${2:i})",
"{",
" $3",
"}"
"\t${5}",
"}$0"
],
"description": "Code snippet for 'for' loop"
},
"forr": {
"prefix": "forr",
"body": [
"for (int ${i} = ${1:length} - 1; ${i} >= ${2:0}; ${i}--)",
"for (int ${1:i} = ${2:length} - 1; ${1:i} >= ${3:0}; ${1:i}--)",
"{",
" $3",
"}"
"\t$4",
"}$0"
],
"description": "Code snippet for reverse 'for' loop"
},
Expand All @@ -24,7 +24,7 @@
"body": [
"do",
"{",
" $1",
"\t$1",
"} while($2);"
],
"description": "Code snippet for do...while loop"
Expand All @@ -34,17 +34,17 @@
"body": [
"while ($1)",
"{",
" $2",
"\t$2",
"}"
],
"description": "Code snippet for while loop"
},
"foreach": {
"prefix": "foreach",
"body": [
"for(auto ${var} : ${collection_to_loop})",
"for(${1|auto,auto&,auto const&|} ${2:var} : ${3:collection})",
"{",
" $1",
"\t$4",
"}"
],
"description": "Code snippet for range-based for loop (c++11) statement"
Expand All @@ -54,7 +54,7 @@
"body": [
"if ($1)",
"{",
" $2",
"\t$2",
"}"
],
"description": "Code snippet for if statement"
Expand All @@ -64,7 +64,7 @@
"body": [
"else",
"{",
" $1",
"\t$1",
"}"
],
"description": "Code snippet for else statement"
Expand All @@ -74,25 +74,28 @@
"body": [
"else if ($1)",
"{",
" $2",
"\t$2",
"}"
],
"description": "Code snippet for else-if statement"
},
"enum": {
"prefix": "enum",
"body": [
"enum ${MyEnum}",
"enum ${1:MyEnum}",
"{",
" $1",
"\t$2",
"};"
],
"description": "Code snippet for enum"
},
"enum class": {
"prefix": "enum class",
"body": [
"enum class ${MyClass} { };"
"enum class ${1:MyClass}",
"{",
"\t$2",
"};"
],
"description": "Code snippet for enum class (c++11)"
},
Expand All @@ -102,15 +105,15 @@
"class ${MyClass}",
"{",
"public:",
" ${MyClass}();",
" ${MyClass}(${MyClass} &&) = default;",
" ${MyClass}(const ${MyClass} &) = default;",
" ${MyClass} &operator=(${MyClass} &&) = default;",
" ${MyClass} &operator=(const ${MyClass} &) = default;",
" ~${MyClass}();",
"\t${MyClass}();",
"\t${MyClass}(${MyClass} &&) = default;",
"\t${MyClass}(const ${MyClass} &) = default;",
"\t${MyClass} &operator=(${MyClass} &&) = default;",
"\t${MyClass} &operator=(const ${MyClass} &) = default;",
"\t~${MyClass}();",
"",
"private:",
" $1",
"\t$1",
"};",
"",
"${MyClass}::${MyClass}()",
Expand All @@ -129,15 +132,15 @@
"class ${MyClass}",
"{",
"public:",
" ${MyClass}() = default;",
" ${MyClass}(${MyClass} &&) = default;",
" ${MyClass}(const ${MyClass} &) = default;",
" ${MyClass} &operator=(${MyClass} &&) = default;",
" ${MyClass} &operator=(const ${MyClass} &) = default;",
" ~${MyClass}() = default;",
"\t${MyClass}() = default;",
"\t${MyClass}(${MyClass} &&) = default;",
"\t${MyClass}(const ${MyClass} &) = default;",
"\t${MyClass} &operator=(${MyClass} &&) = default;",
"\t${MyClass} &operator=(const ${MyClass} &) = default;",
"\t~${MyClass}() = default;",
"",
"private:",
" $1",
"\t$1",
"};"
],
"description": "Code snippet for class with inline constructor/destructor"
Expand All @@ -147,7 +150,7 @@
"body": [
"__interface I${Interface}",
"{",
" $1",
"\t$1",
"};"
],
"description": "Code snippet for interface (Visual C++)"
Expand All @@ -157,7 +160,7 @@
"body": [
"namespace ${MyNamespace}",
"{",
" $1",
"\t$1",
"}"
],
"description": "Code snippet for namespace"
Expand Down Expand Up @@ -194,7 +197,7 @@
"body": [
"struct ${MyStruct}",
"{",
" $1",
"\t$1",
"};"
],
"description": "Code snippet for struct"
Expand All @@ -205,7 +208,7 @@
"switch (${switch_on})",
"{",
"default:",
" break;$1",
"\tbreak;$1",
"}"
],
"description": "Code snippet for switch statement"
Expand All @@ -215,11 +218,11 @@
"body": [
"try",
"{",
" ",
"\t",
"}",
"catch (const std::exception&)",
"catch (std::exception const& e)",
"{",
" $1",
"\t$1",
"}"
],
"description": "Code snippet for try catch"
Expand All @@ -229,15 +232,15 @@
"body": [
"union ${MyUnion}",
"{",
" $1",
"\t$1",
"};"
],
"description": "Code snippet for union"
},
"cout": {
"prefix": "cout",
"body": [
"std::cout << \"${1:/* message */}\" << std::endl;"
"std::cout << ${1:/* message */} << '\\n';"
],
"description": "Code snippet for printing to std::cout, provided the header is set"
},
Expand All @@ -258,17 +261,53 @@
"#def": {
"prefix": "#def",
"body": [
"#define \"$1\" \"$2\" "
],
"description": "Code snippet for #define \" \""
"#define $1 $2"
],
"description": "Code snippet for #define"
},
"main": {
"prefix": "main",
"body": [
"int main(int argc, const char** argv) {",
" return 0;",
"int main(int argc, const char** argv)",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is rather a preference change and not a "fix"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I just got notified after 4 years of PR? 😄

As for this change, you can see in all other snippets, { is placed on a new line, so should this one. return 0; is optional so I placed a placeholder for actual logic. You can tab complete and type it yourself, or type whatever logic. This project should be long dead anyways.

"{",
"$0",
"}"
],
"description": "Code snippet for main function"
},
"static_cast": {
"prefix": "static_cast",
"body": "static_cast<${1:Type}>(${2:expression})$0",
"description": "Code snippet for static_cast"
},
"dynamic_cast": {
"prefix": "dynamic_cast",
"body": "dynamic_cast<${1:Type}>(${2:expression})$0",
"description": "Code snippet for dynamic_cast"
},
"reinterpret_cast": {
"prefix": "reinterpret_cast",
"body": "reinterpret_cast<${1:Type}>(${2:expression})$0",
"description": "Code snippet for reinterpret_cast"
},
"const_cast": {
"prefix": "const_cast",
"body": "const_cast<${1:Type}>(${2:expression})$0",
"description": "Code snippet for const_cast"
},
"new": {
"prefix": "new",
"body": "new ${1:Type}${2:[${3:count}]}${4:(${5:initializer})};$0",
"description": "Code snippet for new operator"
},
"placement-new": {
"prefix": "placement new",
"body": "new(${1:place}) ${2:Type}${3:(${4:initializer})};$0",
"description": "Code snippet for placement new operator"
},
"delete": {
"prefix": "delete",
"body": "delete${1:[]} ${2:expression};$0",
"description": "Code snippet for delete operator"
}
}