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
12
14
15#include <daw/daw_cpp_feature_check.h>
16#include <daw/daw_enable_requires.h>
17#include <daw/daw_traits.h>
18
19#include <iostream>
20#include <type_traits>
21
22namespace daw::json {
23 inline namespace DAW_JSON_VER {
24 namespace json_details {
26 is_opted_into_json_iostreams_v,
28
29#if defined( DAW_HAS_CPP20_CONCEPTS )
30 template<typename Container>
31 concept is_container_opted_into_json_iostreams_v = requires {
32 typename Container::value_type;
33 }
34 and is_opted_into_json_iostreams_v<typename Container::value_type>;
35#else
36 template<typename, typename = void>
37 inline constexpr bool is_container_opted_into_json_iostreams_v = false;
38
39 template<typename Container>
40 inline constexpr bool is_container_opted_into_json_iostreams_v<
41 Container, std::void_t<typename Container::value_type>> =
42 is_opted_into_json_iostreams_v<typename Container::value_type>;
43#endif
44 } // namespace json_details
45 } // namespace DAW_JSON_VER
46} // namespace daw::json
47
49template<typename T DAW_ENABLEIF(
50 daw::json::json_details::is_opted_into_json_iostreams_v<T> )>
51DAW_REQUIRES( daw::json::json_details::is_opted_into_json_iostreams_v<T> )
52std::ostream &operator<<( std::ostream &os, T const &value ) {
53 return daw::json::to_json( value, os );
54}
55
58template<typename Container DAW_ENABLEIF(
59 daw::json::json_details::is_container_opted_into_json_iostreams_v<
60 Container> )>
62 daw::json::json_details::is_container_opted_into_json_iostreams_v<Container> )
63std::ostream &
64operator<<( std::ostream &os, Container const &c ) {
65 return daw::json::to_json_array( c, os );
66}
DAW_REQUIRES(daw::json::json_details::is_container_opted_into_json_iostreams_v< Container >) std
An opt in ostream interface for containers of types that have JSON mappings.
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,...)
DAW_CPP20_CX_ALLOC std::string to_json(Value const &value, options::output_flags_t< PolicyFlags... > flgs)
Definition daw_to_json.h:78
DAW_CPP20_CX_ALLOC 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