Skip to content

Commit

Permalink
add more cpp snippets. (#376)
Browse files Browse the repository at this point in the history
* add header guard.
* add casting expressions and auto function cpp.
* cpp : add description for cast. update header guards.
  • Loading branch information
GLaDOS-418 authored Jan 8, 2024
1 parent 53d3df2 commit 69a2c16
Showing 1 changed file with 53 additions and 5 deletions.
58 changes: 53 additions & 5 deletions snippets/cpp/cpp.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,9 @@
"prefix": "try",
"body": [
"try {",
"\t",
"\t$2",
"}",
"catch (const std::exception&) {",
"\t$1",
"catch (${1:const std::exception&}) {",
"}"
],
"description": "Code snippet for try catch"
Expand Down Expand Up @@ -244,12 +243,12 @@
},
"#inc": {
"prefix": "#inc",
"body": ["#include \"$0\""],
"body": ["#include \"$1\"$2"],
"description": "Code snippet for #include \" \""
},
"#inc<": {
"prefix": "#inc<",
"body": ["#include <$0>"],
"body": ["#include <$1>$2"],
"description": "Code snippet for #include < >"
},
"#def": {
Expand All @@ -266,5 +265,54 @@
"}"
],
"description": "A standard main function for a C++ program"
},
"#guard": {
"prefix": "#guard",
"body": [
"#ifndef INCLUDE${TM_DIRECTORY/.*[\\\/](.*)/_${1:/upcase}/}${TM_FILENAME_BASE/(.*)/_${1:/upcase}/}${TM_FILENAME/.*\\.(.*)/_${1:/upcase}/}_",
"#define INCLUDE${TM_DIRECTORY/.*[\\\/](.*)/_${1:/upcase}/}${TM_FILENAME_BASE/(.*)/_${1:/upcase}/}${TM_FILENAME/.*\\.(.*)/_${1:/upcase}/}_",
"",
"$0",
"",
"#endif // INCLUDE${TM_DIRECTORY/.*[\\\/](.*)/_${1:/upcase}/}${TM_FILENAME_BASE/(.*)/_${1:/upcase}/}${TM_FILENAME/.*\\.(.*)/_${1:/upcase}/}_"
],
"description": "header guard. format :\n\tINCLUDE_<dirname>_<filename>_<extension>_"
},
"sca": {
"prefix": "sca",
"body": [
"static_cast<${1:unsigned}>(${2:expr})$3"
],
"description": "static_cast<type>(expression)"
},
"dca": {
"prefix": "dca",
"body": [
"dynamic_cast<${1:unsigned}>(${2:expr})$3"
],
"description": "dynamic_cast<type>(expression)"
},
"rca": {
"prefix": "rca",
"body": [
"reinterpret_cast<${1:unsigned}>(${2:expr})$3"
],
"description": "reinterpret_cast<type>(expression)"
},
"cca": {
"prefix": "cca",
"body": [
"const_cast<${1:unsigned}>(${2:expr})$3"
],
"description": "const_cast<type>(expression)"
},
"af": {
"prefix": "af",
"body": [
"auto ${1:name}( ${2:void} ) -> ${3:auto} {",
"\t${5}",
"}"
],
"description": "auto function and trailing return"
}
}

0 comments on commit 69a2c16

Please sign in to comment.