Skip to content

Instantly share code, notes, and snippets.

View justephens's full-sized avatar

Justin Stephens justephens

  • Student at the Georgia Institute of Technology
  • Atlanta, GA, USA
View GitHub Profile
@justephens
justephens / this_is_probably_cursed.md
Created June 18, 2022 14:51
flex_ptr (unique_ptr with runtime ownership flag)

flex_ptr

This is a dumb idea.

It's literally just a unique_ptr with an owning flag. If owning is false when the destructor is called, it calls unique_ptr<>::release() to effectively skip deallocation.

  • Acts like a std::unique_ptr when given a managed object
  • Acts like a dumb pointer when given am unmanaged object

Use

// Constructed from unique_ptr, a flex_ptr is owning
@justephens
justephens / d_script_template.d
Created February 15, 2021 17:41
Template for well-documented D scripts that run under rdmd
#!/usr/bin/env rdmd
/++
+ d_script_template.d
+
+ This file serves as a basic template for creating well-documented scripts in
+ D running through rdmd (https://dlang.org/rdmd.html).
+
+ This template uses std.getopt for command line arguments, and parses its own
+ source to output the contents of the top-most documentation block comment