map_category

Conversion category for maps.

Synopsis

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

using map_category = std::integral_constant< conversion_category, conversion_category::map >;

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; and

  • given It, the type denoted by decltype(std::begin(t)), std::iterator_traits<It>::iterator_category is well-formed and denotes a type; and

  • decltype(std::end(t)) also denotes the type It; and

  • std::iterator_traits<It>::value_type is not T; and

  • given types K and M, std::iterator_traits<It>::value_type denotes std::pair<K, M>; and

  • conversion_category_of<K>::value is conversion_category::string; and

  • given v, a value of type std::iterator_traits<It>::value_type, std::tuple_size< decltype(t.emplace(v)) >::value is a positive number.

Less formally, T should be a sequence of std::pairs with unique string-like keys.

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

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

namespace boost { namespace json {

template <>
struct is_map_like<your::map> : map_category
{ };

} }

Matching Types

Convenience header <boost/json.hpp>.