nfx-json 1.5.2
Modern C++20 JSON library with schema validation and generation
Loading...
Searching...
No Matches
Concepts.h
Go to the documentation of this file.
1/*
2 * MIT License
3 *
4 * Copyright (c) 2026 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 <string>
40#include <type_traits>
41
42namespace nfx::json
43{
44 class Document;
45
46 //----------------------------------------------
47 // Type traits for JSON nested classes
48 //----------------------------------------------
49
55 template <typename T>
56 struct is_json_container : std::false_type
57 {
58 };
59
63 template <>
64 struct is_json_container<Document> : std::true_type
65 {
66 };
67
71 template <typename T>
73
74 //----------------------------------------------
75 // C++20 Concepts for JSON value types
76 //----------------------------------------------
77
82 template <typename T>
83 concept Primitive = std::is_same_v<std::decay_t<T>, std::string> || std::is_same_v<std::decay_t<T>, char> ||
84 std::is_same_v<std::decay_t<T>, bool> ||
85 (std::is_integral_v<std::decay_t<T>> && !std::is_same_v<std::decay_t<T>, bool> &&
86 !std::is_same_v<std::decay_t<T>, char>) ||
87 std::is_floating_point_v<std::decay_t<T>>;
88
93 template <typename T>
95
100 template <typename T>
102
107 template <typename T>
108 concept Checkable = Primitive<T> || ( is_json_container_v<T> && !std::is_same_v<std::decay_t<T>, Document> );
109} // namespace nfx::json
constexpr bool is_json_container_v
Helper variable template.
Definition Concepts.h:72
Type trait to identify JSON container types (Object, Array).
Definition Concepts.h:57
Low-level JSON value storage type.
Definition Document.h:108
Concept for JSON-compatible primitive types.
Definition Concepts.h:83
Concept for all JSON-compatible value types.
Definition Concepts.h:94
Concept for JSON container types only.
Definition Concepts.h:101
Concept for types that can be checked with is<T>().
Definition Concepts.h:108