Skip to content

Latest commit

 

History

History
377 lines (275 loc) · 5.35 KB

reference.md

File metadata and controls

377 lines (275 loc) · 5.35 KB

Documentation

In this documentation, $1 represents the first tabbed input, all the way to $n. $0 represents the last place you end up in after you're done tabbing. If there are two $n, e.g. $1 f($1), then that means whatever you input will be put in those two places. If you see ${2:$1} then that means that you can input part of $2 first, in this case $1, and then tab over to the whole expression, which in this case is $2.

To activate a snippet just type the trigger and then press tab.

Although the snippets show up as having four spaces in the reference, in the actual snippet it will substitute it with your preference.

Table of Contents

Loops

A collection of loop auto completions.

Trigger: do_

do {
    $0
} while ($1);

Trigger: while

while($1) {
    $0
}

Trigger: for_

for(unsigned $2 = 0; $2 < $1; ${3:++$2}) {
    $0
}

Trigger: forrange

for(auto&& $1 : $2) {
    $0
}

Utilities

Small simple stuff that can help with some typing.

Trigger: forw

std::forward<$1>($2)

Trigger: declv

std::declval<$1>()

Trigger: returns

-> decltype($1) {
    return $1;
}

Trigger: name

namespace $1 {
$0
} // $1

Trigger: usingt

template<typename $1>
using $2 = $3;

Trigger: usings

using $1 = $2;

Trigger: tem

template<typename $1>

Trigger: try

try {
    $1
}
catch($2) {
    $0
}

Trigger: mitl

A snippet that generates an MIT License with input choices for your name and year.

Conditional Statements

Trigger: if_

if($1) {
    $0
}

Trigger: ifelse

if($1) {
    $2
}
else {
    $0
}

Trigger: ifelif

if($1) {
    $2
}
else if($3) {
    $4
}
else {
    $0
}

Preprocessor

Trigger: ifnd

#ifndef $1
#define $1

$0

#endif // $1

This snippet defaults to inserting the filename in all caps. e.g. myheader.hpp would generate MYHEADER_HPP.

Trigger: clanggreater

Checks for Clang version definition greater than or equal to version specified (version $1.$2).

defined(__clang__) && ((__clang_major__ > $1) || (__clang_major__ == $1) && (__clang_minor__ >= $2))

Trigger: clangless

Checks for Clang version definition less than or equal to version specified (version $1.$2).

defined(__clang__) && ((__clang_major__ < $1) || (__clang_major__ == $1) && (__clang_minor__ <= $2))

Trigger: gccgreater

Checks for GCC version definition greater than or equal to version specified (version $1.$2.0)

defined(__GNUC__) && ((__GNUC__ > $1) || ((__GNUC__ == $1) && (__GNUC_MINOR__ >= $2)))

Trigger: gccless

Checks for GCC version definition less than or equal to version specified (version $1.$2.0)

defined(__GNUC__) && ((__GNUC__ < $1) || ((__GNUC__ == $1) && (__GNUC_MINOR__ <= $2)))

Trigger: ifelifpre

#if $1
$2
#elif $3
$4
#else
$0
#endif

Trigger: ifelsepre

#if $1
$2
#else
$0
#endif

Classes

Trigger: struct_

struct $1 {
    $0
};

Trigger: structtemp

template<typename $1>
struct $2 {
    $0
};

Trigger: class_

class $1 {
private:
    $2
public:
    $1($3) $4
};

Trigger: classtemp

template<typename $1>
class $2 {
private:
    $3
public:
    $2($4) $5
};

Trigger: excep

Creates an exception derived from an std::exception entity.

class $1 : public $2 {
public:
    $1(const std::string& str): $2($3) {}
};

Functions

Regular functions

Trigger: funct

$1 $2($3) {
    $0
}

There is a constexpr variation:

Trigger: confunct

constexpr $1 $2($3) {
    return $0;
}

Templated Functions

Trigger: tempfunc

template<typename $1>
$2 $3($4) noexcept {
    $0
}

Trigger: tempfunca

This snippet doesn't use the same input for the return type and decltype specifier. If you want that, use tempcfunc instead.

template<typename $1>
auto $2($3) -> decltype($4) {
    $0
}

Trigger: tempcfunc

template<typename $1>
constexpr $2 $3($4) {
    return $5;
}

Trigger: tempcfunca

template<typename $1>
constexpr auto $2($3) noexcept -> decltype($4) {
    return $4;
}

Functors

Trigger: functor

struct $1 {
    $2 operator()($3) const noexcept {
        $0
    }
};

There are also templated variations of functors:

Trigger: tempfunctor

struct $1 {
    template<typename T>
    constexpr auto operator()(T&& t) const noexcept -> decltype($2) {
        return $2;
    }
};

Trigger: bintempfunctor

struct $1 {
    template<typename T, typename U>
    constexpr auto operator()(T&& t, U&& u) const noexcept -> decltype($2) {
        return $2;
    }
};