DAW JSON Link
Loading...
Searching...
No Matches
daw_json_iostream.h
Go to the documentation of this file.
1// Copyright (c) Darrell Wright
2//
3// Distributed under the Boost Software License, Version 1.0. (See accompanying
4// file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)
5//
6// Official repository: https://github.com/beached/daw_json_link
7//
8
9#pragma once
10
11#include "impl/version.h"
12
13#include "daw_json_link.h"
14
15#include <daw/daw_traits.h>
16
17#include <iostream>
18#include <type_traits>
19
20namespace daw::json {
21 inline namespace DAW_JSON_VER {
22 namespace json_details {
24 is_opted_into_json_iostreams_v,
26
27 template<typename, typename = void>
28 inline constexpr bool is_container_opted_into_json_iostreams_v = false;
29
30 template<typename Container>
31 inline constexpr bool is_container_opted_into_json_iostreams_v<
32 Container, std::void_t<typename Container::value_type>> =
33 is_opted_into_json_iostreams_v<typename Container::value_type>;
34
35 } // namespace json_details
36 } // namespace DAW_JSON_VER
37} // namespace daw::json
38
40template<typename T DAW_JSON_ENABLEIF(
41 daw::json::json_details::is_opted_into_json_iostreams_v<T> )>
42DAW_JSON_REQUIRES( daw::json::json_details::is_opted_into_json_iostreams_v<T> )
43std::ostream &operator<<( std::ostream &os, T const &value ) {
44 return daw::json::to_json( value, os );
45}
46
49template<typename Container DAW_JSON_ENABLEIF(
50 daw::json::json_details::is_container_opted_into_json_iostreams_v<
51 Container> )>
53 daw::json::json_details::is_container_opted_into_json_iostreams_v<Container> )
54std::ostream &
55operator<<( std::ostream &os, Container const &c ) {
56 return daw::json::to_json_array( c, os );
57}
std::ostream & operator<<(std::ostream &os, T const &value)
An opt in ostream interface for types that have JSON mappings.
#define DAW_JSON_MAKE_REQ_TYPE_ALIAS_TRAIT(Name,...)
#define DAW_JSON_ENABLEIF(...)
#define DAW_JSON_REQUIRES(...)
std::string to_json(Value const &value, options::output_flags_t< PolicyFlags... > flgs)
Definition daw_to_json.h:77
std::string to_json_array(Container const &c, options::output_flags_t< PolicyFlags... > flgs)
Customization point traits.
Mapping class for JSON data structures to C++. It must be specialized in order to parse to a user cla...
#define DAW_JSON_VER
The version string used in namespace definitions. Must be a valid namespace name.
Definition version.h:20