Helper classes ============== Chemfiles contains C++11 implementations of various goodies from more recent versions of the language, or support libraries. Here is a small documentation on how to use these types. ``optional`` --------------- .. cpp:class:: template chemfiles::optional A class representing optional values. Basic usage example is given here, you can also refer to the documentation for ``std::optional`` on `cppreference`_. For most purposes, one can use an ``optional`` value as if it was a pointer ``T*``, with ``nullopt`` indicating the absence of a value. .. code-block:: cpp // nullopt is used to indicate the optional data is missing chemfiles::optional optional = nullopt; if (optional) { // chemfiles::optional is convertible to bool } // setting a value optional = 78.0; // extracting the value double a = *optional; double b = optional.value(); // specifying a default value to be used if data is missing double c = optional.value_or(-1); .. _cppreference: https://en.cppreference.com/w/cpp/utility/optional ``span`` ----------- .. cpp:class:: template chemfiles::span A ``span`` is a view inside a ``std::vector`` providing all the operations of a vector except for memory allocation. The idea and implementation comes from the `GSL`_ library. .. code-block:: cpp // you should never need to create a span yourself chemfiles::span span = /* ... */; // span supports range-based iteration for (auto a: span) { // ... } // but also the usual indexing for (size_t i=0; i