vim-snippets/snippets/cpp.snippets
2012-08-27 21:24:47 -07:00

112 lines
2.2 KiB
Plaintext

## STL Collections
# std::array
snippet array
std::array<${1:T}, ${2:N}> ${2};${3}
# std::vector
snippet vector
std::vector<${1:T}> ${2};${3}
# std::deque
snippet deque
std::deque<${1:T}> ${2};${3}
# std::forward_list
snippet flist
std::forward_list<${1:T}> ${2};${3}
# std::list
snippet list
std::list<${1:T}> ${2};${3}
# std::set
snippet set
std::set<${1:T}> ${2};{$3}
# std::map
snippet map
std::map<${1:Key}, ${2:T}> ${3};${4}
# std::multiset
snippet mset
std::multiset<${1:T}> ${2};${3}
# std::multimap
snippet mmap
std::multimap<${1:Key}, ${2:T}> ${3};${4}
# std::unordered_set
snippet uset
std::unordered_set<${1:T}> ${2};${3}
# std::unordered_map
snippet umap
std::unordered_map<${1:Key}, ${2:T}> ${3};${4}
# std::unordered_multiset
snippet umset
std::unordered_multiset<${1:T}> ${3};${4}
# std::unordered_multimap
snippet ummap
std::unordered_multimap<${1:Key}, ${2:T}> ${3};${4}
# std::stack
snippet stack
std::stack<${1:T}> ${2};${3}
# std::queue
snippet queue
std::queue<${1:T}> ${2};${3}
# std::priority_queue
snippet pqueue
std::priority_queue<${1:T}> ${2};${3}
# std::cout
snippet cout
std::cout << ${1} << std::endl;
# std::cin
snippet cin
std::cin >> ${1};
# class
snippet class
class ${1:`Filename('$1', 'name')`}
{
public:
$1(${2});
~$1();
private:
${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
for (int ${2:i} = 0; $2 < ${1:count}; $2${3:++}) {
${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
snippet itera
for (auto ${1:i} = $1.begin(); $1 != $1.end(); ++$1) {
${2:std::cout << *$1 << std::endl;}
}
# read file into vector
snippet readfile
std::vector<char> v;
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}