Skip to content
| Marketplace
Sign in
Visual Studio Code>Snippets>C++ Ultimate SnippetsNew to Visual Studio Code? Get it now.
C++ Ultimate Snippets

C++ Ultimate Snippets

Snippington

|
1 install
| (0) | Free
Comprehensive Modern C++ snippets covering basic, intermediate, and advanced patterns (C++11 through C++23).
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Snippington C++ Ultimate

Visual Studio Code extension for Modern C++ code snippets.

Covers 302 snippets across C++11 through C++23, organized into basic, intermediate, and advanced levels.

All snippets use the prefix cpp: — just type it in any .cpp file to explore.


Basic Snippets

Program Structure

Prefix Description
cpp: hello Hello World program
cpp: main Main function entry point
cpp: main-args Main function with command-line arguments
cpp: inc Include a standard library header
cpp: inc-local Include a local header file
cpp: header-guard Header guard with ifndef/define/endif
cpp: pragma-once Pragma once header guard
cpp: namespace Namespace declaration
cpp: using-std Using namespace std directive
cpp: using Using declaration for a specific symbol
cpp: type-alias Modern type alias with using keyword

Variables & Types

Prefix Description
cpp: var Variable declaration with initialization
cpp: auto Auto type deduction variable
cpp: const Const variable declaration
cpp: constexpr-var Compile-time constant variable
cpp: static-var Static variable declaration
cpp: ref Reference variable declaration
cpp: const-ref Const reference variable declaration
cpp: ptr Pointer variable declaration
cpp: array std::array declaration
cpp: c-array C-style array declaration
cpp: string std::string variable declaration
cpp: string-view std::string_view declaration (C++17)
cpp: pair std::pair declaration
cpp: tuple std::tuple creation
cpp: optional std::optional declaration (C++17)
cpp: optional-value-or Get optional value or default
cpp: variant std::variant declaration (C++17)
cpp: any std::any usage (C++17)

Enums & Structs

Prefix Description
cpp: enum Traditional enum declaration
cpp: enum-class Scoped enum class (C++11)
cpp: enum-class-typed Scoped enum class with underlying type
cpp: struct Struct declaration
cpp: structured-binding Structured binding declaration (C++17)
cpp: typedef Typedef declaration

Control Flow

Prefix Description
cpp: if If statement
cpp: if-else If-else statement
cpp: if-elseif If-else if-else chain
cpp: if-init If with initializer statement (C++17)
cpp: ternary Ternary conditional operator
cpp: switch Switch statement
cpp: switch-init Switch with initializer (C++17)
cpp: for Traditional for loop
cpp: for-range Range-based for loop
cpp: for-range-mut Mutable range-based for loop
cpp: for-range-idx Range-based for with index counter
cpp: while While loop
cpp: do-while Do-while loop
cpp: loop-infinite Infinite loop

Functions

Prefix Description
cpp: fn Function definition
cpp: fn-decl Function declaration/prototype
cpp: fn-constexpr Constexpr function
cpp: fn-inline Inline function
cpp: fn-nodiscard Function with [[nodiscard]] attribute
cpp: fn-noexcept Noexcept function
cpp: fn-overload Function overload example
cpp: fn-default-params Function with default parameters
cpp: lambda Basic lambda expression
cpp: lambda-ret Lambda with explicit return type
cpp: lambda-inline Inline lambda expression

I/O & Formatting

Prefix Description
cpp: cout Print to stdout with cout
cpp: cout-nl Print to stdout with newline char
cpp: cout-multi Print label and variable
cpp: cerr Print to stderr
cpp: cin Read input from stdin
cpp: getline Read a full line from stdin
cpp: file-read Read from file line by line
cpp: file-write Write to file
cpp: file-append Append to file
cpp: print std::print (C++23)
cpp: println std::println (C++23)
cpp: format std::format string (C++20)

Error Handling & Assertions

Prefix Description
cpp: try-catch Try-catch block
cpp: try-catch-all Try-catch with catch-all clause
cpp: throw Throw an exception
cpp: static-assert Compile-time assertion
cpp: assert Runtime assertion

Casts & Utilities

Prefix Description
cpp: cast-static static_cast expression
cpp: cast-dynamic dynamic_cast expression
cpp: cast-reinterpret reinterpret_cast expression
cpp: cast-const const_cast expression
cpp: sizeof sizeof operator
cpp: decltype decltype type deduction
cpp: nullptr-check Nullptr check
cpp: swap Swap two values
cpp: minmax Get min and max of two values

Comments & Documentation

Prefix Description
cpp: comment-block Block comment
cpp: doxygen-fn Doxygen function comment
cpp: doxygen-class Doxygen class comment
cpp: todo TODO comment
cpp: fixme FIXME comment

Preprocessor

Prefix Description
cpp: ifdef Preprocessor ifdef block
cpp: ifndef Preprocessor ifndef block
cpp: define Preprocessor macro definition
cpp: define-fn Preprocessor function-like macro

Intermediate Snippets

Classes & OOP

Prefix Description
cpp: class Basic class with constructor and destructor
cpp: class-rule5 Class following the Rule of Five
cpp: class-rule0 Class following the Rule of Zero
cpp: class-inherit Derived class with public inheritance
cpp: class-abstract Abstract class / interface
cpp: class-final Final class that cannot be inherited
cpp: virtual Pure virtual method declaration
cpp: override Override virtual method
cpp: friend Friend function declaration
cpp: getter Const getter method
cpp: setter Setter method

Constructors

Prefix Description
cpp: ctor-init Constructor with member initializer list
cpp: ctor-explicit Explicit single-argument constructor
cpp: ctor-delegate Delegating constructor
cpp: ctor-copy Copy constructor
cpp: ctor-move Move constructor

Operator Overloading

Prefix Description
cpp: op-copy-assign Copy assignment operator
cpp: op-move-assign Move assignment operator
cpp: op-stream Stream insertion operator overload
cpp: op-equal Equality operator overload
cpp: op-spaceship Three-way comparison operator (C++20)
cpp: op-subscript Subscript operator overload
cpp: op-functor Function call operator (functor)

Templates

Prefix Description
cpp: template-fn Template function
cpp: template-class Template class
cpp: template-multi Template with multiple type parameters
cpp: template-variadic Variadic template function
cpp: template-specialize Template full specialization
cpp: template-partial-specialize Template partial specialization
cpp: template-alias Template type alias
cpp: sfinae-enable-if SFINAE with enable_if

Smart Pointers

Prefix Description
cpp: unique-ptr Create unique_ptr with make_unique
cpp: shared-ptr Create shared_ptr with make_shared
cpp: weak-ptr Weak pointer from shared_ptr
cpp: weak-ptr-lock Lock weak_ptr to shared_ptr
cpp: unique-ptr-deleter unique_ptr with custom deleter

STL Containers

Prefix Description
cpp: vector std::vector declaration
cpp: vector-reserve Vector with reserve
cpp: vector-push Push element to vector
cpp: vector-emplace Emplace element at back of vector
cpp: map std::map declaration
cpp: unordered-map std::unordered_map declaration
cpp: map-insert Insert element into map
cpp: map-find Find element in map (C++17 if-init)
cpp: map-contains Check if map contains key (C++20)
cpp: set std::set declaration
cpp: unordered-set std::unordered_set declaration
cpp: deque std::deque declaration
cpp: stack std::stack declaration
cpp: queue std::queue declaration
cpp: priority-queue std::priority_queue (max-heap)
cpp: priority-queue-min Min-heap priority queue
cpp: list std::list declaration
cpp: forward-list std::forward_list declaration
cpp: span std::span view (C++20)

STL Algorithms

Prefix Description
cpp: sort Sort container
cpp: sort-custom Sort with custom comparator
cpp: find Find element in container
cpp: find-if Find element with predicate
cpp: for-each Apply function to each element
cpp: transform Transform elements to output container
cpp: accumulate Accumulate/sum elements
cpp: reduce Reduce elements with binary operation (C++17)
cpp: count-if Count elements matching predicate
cpp: any-of Check if any element matches predicate
cpp: all-of Check if all elements match predicate
cpp: none-of Check if no element matches predicate
cpp: copy-if Copy elements matching predicate
cpp: erase-remove Remove-erase idiom
cpp: erase-if std::erase_if (C++20)
cpp: unique Remove consecutive duplicates
cpp: binary-search Binary search on sorted container
cpp: lower-bound Lower bound on sorted container
cpp: max-element Find max element in container
cpp: min-element Find min element in container
cpp: iota Fill container with incrementing values
cpp: generate Generate values with generator function
cpp: partition Partition container by predicate

Lambdas (Advanced)

Prefix Description
cpp: lambda-ref Lambda capturing all by reference
cpp: lambda-val Lambda capturing all by value
cpp: lambda-mutable Mutable lambda with state
cpp: lambda-generic Generic lambda (C++14)
cpp: lambda-recursive Recursive lambda using std::function

Error Handling (Advanced)

Prefix Description
cpp: exception-custom Custom exception class
cpp: expected std::expected declaration (C++23)
cpp: fn-expected Function returning std::expected (C++23)
cpp: error-code Error code pattern

Iterators

Prefix Description
cpp: iter-loop Iterator-based loop
cpp: iter-reverse Reverse iterator loop
cpp: iterator-class Custom forward iterator class

Strings & Regex

Prefix Description
cpp: stringstream String stream usage
cpp: stoi String to integer conversion
cpp: to-string Number to string conversion
cpp: regex-match Regex match
cpp: regex-search Regex search
cpp: regex-replace Regex replace

Utilities

Prefix Description
cpp: chrono-duration Measure execution time with chrono
cpp: random Random number generation
cpp: random-float Random floating-point number generation
cpp: fs-path Filesystem path (C++17)
cpp: fs-exists Check if path exists (C++17)
cpp: fs-iterate Iterate directory entries (C++17)
cpp: fn-ptr Function pointer declaration
cpp: std-function std::function wrapper
cpp: callback Callback type alias and registration
cpp: scope-guard Simple scope guard pattern
cpp: raii RAII resource wrapper class

Advanced Snippets

Concepts (C++20)

Prefix Description
cpp: concept Concept definition
cpp: concept-arithmetic Simple concept with type trait
cpp: concept-compound Compound concept with multiple requirements
cpp: concept-fn Concept-constrained function
cpp: requires-clause Function with requires clause
cpp: concept-auto Abbreviated function template with concept
cpp: requires-expr Requires expression

Ranges (C++20/23)

Prefix Description
cpp: ranges-view Ranges pipeline with filter and transform
cpp: ranges-filter Ranges filter view
cpp: ranges-transform Ranges transform view
cpp: ranges-take Ranges take first N elements
cpp: ranges-drop Ranges drop first N elements
cpp: ranges-iota Ranges iota view
cpp: ranges-sort Ranges sort algorithm
cpp: ranges-find Ranges find algorithm
cpp: ranges-for-each Ranges for_each algorithm
cpp: ranges-zip Ranges zip view (C++23)
cpp: ranges-enumerate Ranges enumerate view (C++23)
cpp: ranges-chunk Ranges chunk view (C++23)
cpp: ranges-to Ranges to container conversion (C++23)

Concurrency

Prefix Description
cpp: thread Basic thread with lambda
cpp: thread-detach Detached thread
cpp: jthread std::jthread with stop token (C++20)
cpp: mutex-lock Mutex with lock_guard
cpp: scoped-lock Scoped lock for multiple mutexes (C++17)
cpp: unique-lock Unique lock (for condition variables)
cpp: shared-mutex Shared mutex reader/writer pattern (C++17)
cpp: condvar Condition variable pattern
cpp: async std::async with future
cpp: promise Promise and future communication
cpp: atomic Atomic variable
cpp: atomic-ops Atomic operations with memory ordering
cpp: thread-pool Simple thread pool implementation
cpp: semaphore Counting semaphore (C++20)
cpp: latch std::latch synchronization (C++20)
cpp: barrier std::barrier synchronization (C++20)

Coroutines (C++20)

Prefix Description
cpp: coroutine-generator Coroutine generator
cpp: coroutine-task Coroutine task
cpp: co-await co_await expression
cpp: co-yield co_yield expression

Modules (C++20)

Prefix Description
cpp: module Module declaration
cpp: module-import Module import
cpp: module-partition Module partition

CRTP & Static Polymorphism

Prefix Description
cpp: crtp Curiously Recurring Template Pattern
cpp: crtp-mixin CRTP mixin for comparison operators
cpp: static-poly Static polymorphism via CRTP
cpp: mixin Mixin pattern with variadic inheritance

Move Semantics & Forwarding

Prefix Description
cpp: move std::move
cpp: forward Perfect forwarding factory function
cpp: universal-ref Universal/forwarding reference function

Metaprogramming

Prefix Description
cpp: fold Fold expression (C++17)
cpp: fold-binary Binary fold expression with init value (C++17)
cpp: fold-print Fold expression for printing variadic args
cpp: if-constexpr Compile-time if constexpr (C++17)
cpp: if-consteval if consteval (C++23)
cpp: fn-consteval Immediate function (C++20)
cpp: constinit constinit variable (C++20)
cpp: type-trait Static assert with type trait
cpp: type-trait-custom Custom type trait with specialization
cpp: tag-dispatch Tag dispatch pattern
cpp: variadic-print Variadic template print function
cpp: tuple-foreach Apply function to each tuple element
cpp: index-sequence Index sequence for tuple iteration

Compile-Time Programming

Prefix Description
cpp: constexpr-map Compile-time lookup map
cpp: constexpr-string Compile-time fixed string (NTTP helper)
cpp: constexpr-fib Compile-time Fibonacci with constexpr
cpp: constexpr-hash Compile-time string hash function
cpp: constexpr-array Compile-time generated lookup table

Design Patterns

Prefix Description
cpp: singleton Thread-safe Meyers Singleton
cpp: factory Factory method pattern
cpp: observer Observer/Subject pattern
cpp: builder Builder pattern with method chaining
cpp: strategy Strategy pattern
cpp: visitor Visitor pattern with std::variant
cpp: state-machine Simple state machine pattern
cpp: pimpl-header Pimpl idiom header declaration
cpp: pimpl-impl Pimpl idiom implementation
cpp: type-erasure Type erasure pattern
cpp: policy Policy-based design pattern
cpp: event-system Type-safe event/signal system

C++20/23 Features

Prefix Description
cpp: deducing-this Deducing this (C++23)
cpp: op-multidim-subscript Multidimensional subscript operator (C++23)
cpp: designated-init Designated initializers (C++20)
cpp: spaceship-custom Custom three-way comparison operator
cpp: source-location std::source_location for logging (C++20)
cpp: compare-three-way Three-way comparison result handling
cpp: expected-chain std::expected monadic operations (C++23)
cpp: optional-chain std::optional monadic operations (C++23)
cpp: overloaded Overloaded pattern for std::visit
cpp: strong-typedef Strong typedef / named type pattern
cpp: udl User-defined literal operator
cpp: flat-map Flat map with ranges (transform + join)
cpp: span-subspan Static subspan extraction

Attributes

Prefix Description
cpp: attr-likely Branch prediction hint [[likely]] (C++20)
cpp: attr-unlikely Branch prediction hint [[unlikely]] (C++20)
cpp: attr-no-unique-addr [[no_unique_address]] attribute (C++20)
cpp: attr-deprecated [[deprecated]] attribute

Parallel Algorithms

Prefix Description
cpp: parallel-transform Parallel transform with execution policy (C++17)
cpp: parallel-sort Parallel sort with execution policy
cpp: parallel-for-each Parallel for_each with execution policy

C++ Standard Coverage

Standard Features Covered
C++11 Move semantics, lambdas, smart pointers, enum class, auto, range-for
C++14 Generic lambdas, return type deduction
C++17 Structured bindings, if-init, fold expressions, std::optional/variant/any, filesystem, parallel algorithms
C++20 Concepts, ranges, coroutines, modules, jthread, semaphore/latch/barrier, spaceship operator, designated initializers
C++23 std::expected, deducing this, std::print, ranges::zip/enumerate/chunk, ranges::to, if consteval, multidimensional subscript

Installation

From VS Code Marketplace

Search for "C++ Ultimate Snippets" in the Extensions panel.

From VSIX

code --install-extension snp-cpp-ultimate-0.1.0.vsix

Usage

  1. Open any .cpp file
  2. Type cpp: to see all available snippets
  3. Use Tab to expand and navigate through placeholders

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

License

MIT License - see LICENSE for details.

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2026 Microsoft