Skip to content

Instantly share code, notes, and snippets.

@morrisonlevi
Last active August 29, 2015 14:06
Show Gist options
  • Save morrisonlevi/2994cfd0509a9601d384 to your computer and use it in GitHub Desktop.
Save morrisonlevi/2994cfd0509a9601d384 to your computer and use it in GitHub Desktop.
Features of C++11 that I think would be helpful in implementing a dynamic language.

These features of C++11 are ones that I think would be useful when implementing a dynamic language, such as PHP or Python.

  • Shared and unique pointers. These are provided by the standard library in C++11 making memory management easier and safer. I consider this to be the biggest feature of C++11 that would help when implementing a dynamic language.
  • Enum classes. Enum classes are scoped and strongly typed enums; you can also specify their underlying size.
  • Unions. C++11's unions are considerably more powerful than previous versions, notably unions can have member functions such as move constructors and move assignment operators. They can now contain complex types (such as shared pointers).
  • Rvalue references and move semantics. Rvalue references and move semantics are very useful for practically every C++ project and implementing a dynamic language is no exception; if you are not familiar with them you should go learn them.
  • Explicit operator overloading. It is useful to create bool and other cast operators to make it easier for calling code to 'unbox' a unioned type. However there is an issue with bool operator overloading known as the "safe bool problem" which allows C++ compilers to use the bool cast for arithmetic and equality operations, which is almost never intended. The explicit attribute added in C++11 allows you to easy solve this issue, instead of using the more complex and unintuitive "safe bool idiom".
  • Fized width integer sizes. These were already included in C99 and many compilers have the headers available even under C89; it's just nice that this is standardized for C++.
  • Threads and thread-local storage. If the interpreter needs to support threading, these are very nice.
  • Variadic templates. These allow you to do type-safe variadic features, such as printf with complex types or parameter parsing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment