Class compact_floating_point_policy

Synopsis

#include <include/type_safe/compact_optional.hpp>

template <typename FloatingPoint>
class compact_floating_point_policy

Description

A CompactPolicy for [ts::compact_optional_storage]() for floating point types.

NaN will be used to mark an empty optional. \module optional

Methods

invalid_value
is_invalid

Source

Lines 246-265 in include/type_safe/compact_optional.hpp.

template <typename FloatingPoint>
class compact_floating_point_policy
{
    static_assert(std::is_floating_point<FloatingPoint>::value, "must be a floating point");

public:
    using value_type   = FloatingPoint;
    using storage_type = FloatingPoint;

    static storage_type invalid_value() noexcept
    {
        return std::numeric_limits<value_type>::quiet_NaN();
    }

    static bool is_invalid(const storage_type& storage) noexcept
    {
        // NaN is not equal to anything
        return storage != storage;
    }
};





Add Discussion as Guest

Log in