nfx-serialization 0.3.0
Cross-platform C++ JSON serialization library with extensible trait capabilities
Loading...
Searching...
No Matches
Concepts.h
Go to the documentation of this file.
1/*
2 * MIT License
3 *
4 * Copyright (c) 2025 nfx
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
35
36#pragma once
37
38#include <concepts>
39#include <type_traits>
40
41namespace nfx::serialization::json
42{
43 //=====================================================================
44 // Type traits for JSON nested classes
45 //=====================================================================
46
47 class Document;
48
54 template <typename T>
55 struct is_json_container : std::false_type
56 {
57 };
58
62 template <>
63 struct is_json_container<Document> : std::true_type
64 {
65 };
66
70 template <typename T>
72
73 //=====================================================================
74 // C++20 Concepts for JSON value types
75 //=====================================================================
76
81 template <typename T>
82 concept JsonPrimitive =
83 std::is_same_v<std::decay_t<T>, std::string> ||
84 std::is_same_v<std::decay_t<T>, char> ||
85 std::is_same_v<std::decay_t<T>, bool> ||
86 (std::is_integral_v<std::decay_t<T>> && !std::is_same_v<std::decay_t<T>, bool> && !std::is_same_v<std::decay_t<T>, char>) ||
87 std::is_floating_point_v<std::decay_t<T>>;
88
94 template <typename T>
95 concept JsonValue =
98
103 template <typename T>
105
110 template <typename T>
113 ( is_json_container_v<T> && !std::is_same_v<std::decay_t<T>, Document> );
114} // namespace nfx::serialization::json
constexpr bool is_json_container_v
Helper variable template.
Definition Concepts.h:71
Type trait to identify JSON container types (Object, Array).
Definition Concepts.h:56
Generic JSON document abstraction for serialization.
Definition Document.h:59
Concept for JSON-compatible primitive types.
Definition Concepts.h:82
Concept for all JSON-compatible value types.
Definition Concepts.h:95
Concept for JSON container types only.
Definition Concepts.h:104
Concept for types that can be checked with is<T>().
Definition Concepts.h:111