Explain C++ code

Paste modern C++ and Vibe explains the templates, smart pointers and object lifetimes in it.

documents.cpp

Up to 1,500 characters (about 60 lines). Your code is sent to Unvibe and Anthropic to write the explanation. Don't paste keys or passwords. Common key formats are refused.

Vibe25 lines selected

Press Explain it for the sample, or paste your own code first.

What this C++ sample shows

templates
largest is written once for any T that can be copied and compared with >. largest(std::vector<int>{3, 9, 4}) makes the compiler generate an int version, which returns 9.
RAII
Document prints closing in its destructor. The destructor runs on its own when the unique_ptr that owns the document is destroyed at the end of main, so cleanup can't be forgotten.
move semantics
std::move(open.front()) hands ownership to current. The pointer left in the vector is now null, so the last line prints true notes.txt.
pointers
std::unique_ptr is a pointer that owns its object: one owner at a time, deleted automatically, and it can be moved but not copied.

Good to know

  • items.at(0) throws std::out_of_range on an empty vector, where items[0] would be undefined behavior.
  • explicit stops a plain std::string from turning into a Document by accident, for example when passed to a function that takes a Document.
  • The vector still holds one element after the move. It is an empty unique_ptr, and dereferencing it is undefined behavior.

Watch out: closing notes.txt prints once, after everything else. The document is destroyed exactly once, by whichever unique_ptr owns it when main ends, here current.

Explain C++ code beside your editor

Unvibe is a free app for Mac and Windows. In the app there is no pasting: select code in any app and press Control+U (Ctrl+Alt+U on Windows).

Install on Mac

curl -fsSL https://unvibe.site/install.sh | bash

Paste into Terminal. Unvibe isn't notarized by Apple yet, so this is the smooth path.

No install warning? Use Unvibe in your browser

Opening the .dmg the first time
  1. Open the .dmg and drag Unvibe to Applications.
  2. Open it once; macOS says it can't verify it. Click Done.
    macOS dialog: Unvibe Not Opened, with Done and Move to Trash
    Real screen, macOS 15
  3. System Settings › Privacy & Security › Open Anyway. Confirm, then enter your Mac password. The button shows for about an hour after you try to open Unvibe.
    macOS Privacy & Security, Security section: Unvibe was blocked to protect your Mac, with the Open Anyway button
    Real screen, macOS 15

The Terminal line checks the download against the published SHA-256 and Unvibe's self-signed signature before it installs anything. More help with the first open