Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions doc/compile_time.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ your code with the `SIMDJSON_STATIC_REFLECTION` macro set:
The `simdjson::compile_time::parse_json` function parses a JSON document at **compile time** and returns a `constexpr` structure reflecting its content. We support the full range of JSON values, which are mapped to C++ types as in
the following table.

For convenience, you can also use the `""_json` user-defined literal operator, which is available in the `simdjson::literals` namespace:

```cpp
using namespace simdjson::literals;

constexpr auto cfg = R"(
{
"port": 8080,
"host": "localhost"
}
)"_json;
```

Alternatively, you can use the qualified name `simdjson::literals::operator""_json`.


| JSON type | C++ type |
|----------------|----------------------------------|
Expand Down Expand Up @@ -61,6 +76,8 @@ You can do so, at compile-time, as follows:


```cpp
using namespace simdjson::literals;

constexpr auto cfg = R"(

{
Expand All @@ -79,6 +96,8 @@ constexpr auto cfg = R"(
You can nest objects and arrays:

```cpp
using namespace simdjson::literals;

constexpr auto data = R"(

{
Expand All @@ -98,6 +117,8 @@ constexpr auto data = R"(
Top-level arrays are allowed:

```cpp
using namespace simdjson::literals;

constexpr auto arr = R"(

[1, 2, 3]
Expand All @@ -116,6 +137,8 @@ want to check that it conforms to your expectation. You can do so with concepts.
Let us consider this example:

```cpp
using namespace simdjson::literals;

constexpr auto config = R"(

[
Expand Down
5 changes: 4 additions & 1 deletion include/simdjson/compile_time_json.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,16 @@ namespace compile_time {
template <constevalutil::fixed_string json_str> consteval auto parse_json();

} // namespace compile_time
} // namespace simdjson

inline namespace literals {

template <simdjson::constevalutil::fixed_string str>
consteval auto operator ""_json() {
return simdjson::compile_time::parse_json<str>();
}

} // namespace literals
} // namespace simdjson

#endif // SIMDJSON_STATIC_REFLECTION
#endif // SIMDJSON_GENERIC_COMPILE_TIME_JSON_H
1 change: 1 addition & 0 deletions tests/compile_time/compile_time_json_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

using namespace std::string_view_literals;
using namespace simdjson;
using namespace simdjson::literals;

namespace compile_time_json_tests {
/**
Expand Down
Loading