Class option

Synopsis

#include <include/cpptoml.h>

template <class T>
class option

Description

No description yet.

Mentioned in

Methods

option overload
operator bool
operator*
operator->
value_or

Mentioned in

Source

Lines 58-98 in include/cpptoml.h.

template <class T>
class option
{
  public:
    option() : empty_{true}
    {
        // nothing
    }

    option(T value) : empty_{false}, value_(std::move(value))
    {
        // nothing
    }

    explicit operator bool() const
    {
        return !empty_;
    }

    const T& operator*() const
    {
        return value_;
    }

    const T* operator->() const
    {
        return &value_;
    }

    template <class U>
    T value_or(U&& alternative) const
    {
        if (!empty_)
            return value_;
        return static_cast<T>(std::forward<U>(alternative));
    }

  private:
    bool empty_;
    T value_;
};





Add Discussion as Guest

Log in