map_category

Conversion category for maps.

Synopsis

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

struct map_category;

Description

Maps are represented in JSON as objects. Such representation limits this category to 1-to-1 maps (as opposed to 1-to-many e.g. std::multimap) with string keys.

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

  • is_sequence_like<T>::value is true; and

  • given type It denoting decltype(std::begin(t)), and types K and M, std::iterator_traits<It>::value_type denotes std::pair<K, M>; and

  • std::is_string_like<K>::value is true; and

  • given v, a glvalue of type V, and E, the type denoted by decltype(t.emplace(v)), std::is_tuple_like<E>::value is true.

The restriction for t.emplace() return type ensures that the container does not allow duplicate keys.

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

namespace boost {
namespace json {

template <>
struct conversion_category_for<your::map>
{
    using type = map_category;
};

} // namespace boost
} // namespace json

Matching Types

Convenience header <boost/json.hpp>.