[cpp] Reorganized snippets for consistency.

Added comments to snippets that didn't have any. Reordered snippets so
relevant snippets were close together. Removed cout/cin snippets for
consistency with other snippets in std namespace.
This commit is contained in:
Aaron Broder 2012-08-27 14:10:27 -07:00
parent 8108ecd980
commit 7fe10931b2

View File

@ -1,28 +1,17 @@
# Read File Into Vector # std::vector
snippet readfile snippet vector
std::vector<char> v; std::vector<${1:char}> ${2};
if (FILE *${2:fp} = fopen(${1:"filename"}, "r")) {
char buf[1024];
while (size_t len = fread(buf, 1, sizeof(buf), $2))
v.insert(v.end(), buf, buf + len);
fclose($2);
}${3}
# std::map # std::map
snippet map snippet map
std::map<${1:key}, ${2:value}> ${3}; std::map<${1:key}, ${2:value}> ${3};
# std::vector # std::cout
snippet vector snippet cout
std::vector<${1:char}> ${2}; std::cout << ${1} << std::endl;
# std::cin
# Namespace snippet cin
snippet ns std::cin >> ${1};
namespace ${1:`Filename('', 'my')`} { # class
${2}
} /* namespace $1 */
# Class
snippet class snippet class
class ${1:`Filename('$1', 'name')`} class ${1:`Filename('$1', 'name')`}
{ {
@ -34,38 +23,47 @@ snippet class
${3:/* data */} ${3:/* data */}
}; };
# member function implementations
snippet mfun
${4:void} ${1:`Filename('$1', 'ClassName')`}::${2:memberFunction}(${3}) {
${5:return};
}
# namespace
snippet ns
namespace ${1:`Filename('', 'my')`} {
${2}
} /* namespace $1 */
# for i loop
snippet fori snippet fori
for (int ${2:i} = 0; $2 < ${1:count}; $2${3:++}) { for (int ${2:i} = 0; $2 < ${1:count}; $2${3:++}) {
${4:/* code */} ${4:/* code */}
} }
# foreach
snippet fore
for (${1:auto} ${2:i} : ${3:container}) {
${4:/* code */}
}
# iterator
snippet iter
for (${1:std::vector}<${2:type}>::${3:const_iterator} ${4:i} = ${5:container}.begin(); $4 != $5.end(); ++$4) {
${6}
}
# auto iterator # auto iterator
snippet itera snippet itera
for (auto ${1:i} = $1.begin(); $1 != $1.end(); ++$1) { for (auto ${1:i} = $1.begin(); $1 != $1.end(); ++$1) {
${2:std::cout << *$1 << std::endl;} ${2:std::cout << *$1 << std::endl;}
} }
# iterator # read file into vector
snippet iter snippet readfile
for (${1:std::vector}<${2:type}>::${3:const_iterator} ${4:i} = ${5:container}.begin(); $4 != $5.end(); ++$4) { std::vector<char> v;
${6} if (FILE *${2:fp} = fopen(${1:"filename"}, "r")) {
} char buf[1024];
while (size_t len = fread(buf, 1, sizeof(buf), $2))
v.insert(v.end(), buf, buf + len);
fclose($2);
}${3}
# member function implementations
snippet mfun
${4:void} ${1:`Filename('$1', 'ClassName')`}::${2:memberFunction}(${3}) {
${5:return};
}
snippet scout
std::cout << ${1} << std::endl;
snippet cout
cout << ${1} << endl;
snippet scin
std::cin >> ${1};
snippet cin
cin >> ${1};
# foreach
snippet fore
for (${1:auto} ${2:i} : ${3:container}) {
${4:/* code */}
}