optional_category

Conversion category for optionals.

Synopsis

Defined in header <boost/json/conversion.hpp>.

struct optional_category;

Description

Optionals are represented in JSON as null if unengaged (i.e. doesn’t have a value), or as the stored type otherwise.

By default a type T is considered an optional if given t, a glvalue of type T,

  • decltype( t.value() ) is well-formed and isn’t a void type; and

  • t.reset() is well-formed.

Users can specialize conversion_category_for for their own types if they want them to be treated as optionals. For example:

namespace boost {
namespace json {

template <>
struct conversion_category_for<your::optional>
{
    using type = optional_category;
};

} // namespace boost
} // namespace json

Matching Types

Convenience header <boost/json.hpp>.