mkdocs: encode required C++ standard in example files

This commit is contained in:
Florian Albrechtskirchinger 2022-07-31 09:16:49 +02:00
parent 9ab874c2ac
commit e2bd7abb33
No known key found for this signature in database
GPG Key ID: 19618CE9B2D4BE6D
31 changed files with 27 additions and 24 deletions

View File

@ -9,15 +9,18 @@ all: create_output
# where are the example cpp files
EXAMPLES = $(wildcard examples/*.cpp)
cxx_standard = $(lastword c++11 $(filter c++%, $(subst ., ,$1)))
# create output from a stand-alone example file
%.output: %.cpp
$(MAKE) $(<:.cpp=) CPPFLAGS="-I $(SRCDIR)" CXXFLAGS="-std=c++11"
@echo "standard $(call cxx_standard $(<:.cpp=))"
$(MAKE) $(<:.cpp=) CPPFLAGS="-I $(SRCDIR)" CXXFLAGS="-std=$(call cxx_standard,$(<:.cpp=)) -Wno-deprecated-declarations"
./$(<:.cpp=) > $@
rm $(<:.cpp=)
# compare created output with current output of the example files
%.test: %.cpp
$(MAKE) $(<:.cpp=) CPPFLAGS="-I $(SRCDIR)" CXXFLAGS="-std=c++11"
$(MAKE) $(<:.cpp=) CPPFLAGS="-I $(SRCDIR)" CXXFLAGS="-std=$(call cxx_standard,$(<:.cpp=)) -Wno-deprecated-declarations"
./$(<:.cpp=) > $@
diff $@ $(<:.cpp=.output)
rm $(<:.cpp=) $@

View File

@ -158,13 +158,13 @@ Strong exception safety: if an exception occurs, the original value stays intact
exceptions that can be thrown.
```cpp
--8<-- "examples/at__keytype.cpp"
--8<-- "examples/at__keytype.c++17.cpp"
```
Output:
```json
--8<-- "examples/at__keytype.output"
--8<-- "examples/at__keytype.c++17.output"
```
??? example "Example: (3) access specified object element using string_view with bounds checking"
@ -173,13 +173,13 @@ Strong exception safety: if an exception occurs, the original value stays intact
that can be thrown.
```cpp
--8<-- "examples/at__keytype_const.cpp"
--8<-- "examples/at__keytype_const.c++17.cpp"
```
Output:
```json
--8<-- "examples/at__keytype_const.output"
--8<-- "examples/at__keytype_const.c++17.output"
```
??? example "Example: (4) access specified element via JSON Pointer"

View File

@ -88,13 +88,13 @@ Logarithmic in the size of the JSON object.
The example shows how `contains()` is used.
```cpp
--8<-- "examples/contains__keytype.cpp"
--8<-- "examples/contains__keytype.c++17.cpp"
```
Output:
```json
--8<-- "examples/contains__keytype.output"
--8<-- "examples/contains__keytype.c++17.output"
```
??? example "Example: (3) check with JSON pointer"

View File

@ -63,13 +63,13 @@ This method always returns `0` when executed on a JSON type that is not an objec
The example shows how `count()` is used.
```cpp
--8<-- "examples/count__keytype.cpp"
--8<-- "examples/count__keytype.c++17.cpp"
```
Output:
```json
--8<-- "examples/count__keytype.output"
--8<-- "examples/count__keytype.c++17.output"
```
## Version history

View File

@ -179,13 +179,13 @@ Strong exception safety: if an exception occurs, the original value stays intact
The example shows the effect of `erase()` for different JSON types using an object key.
```cpp
--8<-- "examples/erase__keytype.cpp"
--8<-- "examples/erase__keytype.c++17.cpp"
```
Output:
```json
--8<-- "examples/erase__keytype.output"
--8<-- "examples/erase__keytype.c++17.output"
```
??? example "Example: (5) remove element from a JSON array given an index"

View File

@ -67,13 +67,13 @@ This method always returns `end()` when executed on a JSON type that is not an o
The example shows how `find()` is used.
```cpp
--8<-- "examples/find__keytype.cpp"
--8<-- "examples/find__keytype.c++17.cpp"
```
Output:
```json
--8<-- "examples/find__keytype.output"
--8<-- "examples/find__keytype.c++17.output"
```
## See also

View File

@ -173,13 +173,13 @@ Strong exception safety: if an exception occurs, the original value stays intact
The example below shows how object elements can be read using the `[]` operator.
```cpp
--8<-- "examples/operator_array__keytype.cpp"
--8<-- "examples/operator_array__keytype.c++17.cpp"
```
Output:
```json
--8<-- "examples/operator_array__keytype.output"
--8<-- "examples/operator_array__keytype.c++17.output"
```
??? example "Example: (3) access specified object element using string_view (const)"
@ -187,13 +187,13 @@ Strong exception safety: if an exception occurs, the original value stays intact
The example below shows how object elements can be read using the `[]` operator.
```cpp
--8<-- "examples/operator_array__keytype_const.cpp"
--8<-- "examples/operator_array__keytype_const.c++17.cpp"
```
Output:
```json
--8<-- "examples/operator_array__keytype_const.output"
--8<-- "examples/operator_array__keytype_const.c++17.output"
```
??? example "Example: (4) access specified element via JSON Pointer"

View File

@ -62,13 +62,13 @@ Linear.
The example demonstrates comparing several JSON values.
```cpp
--8<-- "examples/operator_spaceship__const_reference.cpp"
--8<-- "examples/operator_spaceship__const_reference.c++20.cpp"
```
Output:
```json
--8<-- "examples/operator_spaceship__const_reference.output"
--8<-- "examples/operator_spaceship__const_reference.c++20.output"
```
??? example "Example: (2) comparing JSON values and scalars"
@ -76,13 +76,13 @@ Linear.
The example demonstrates comparing several JSON values and scalars.
```cpp
--8<-- "examples/operator_spaceship__scalartype.cpp"
--8<-- "examples/operator_spaceship__scalartype.c++20.cpp"
```
Output:
```json
--8<-- "examples/operator_spaceship__scalartype.output"
--8<-- "examples/operator_spaceship__scalartype.c++20.output"
```
## See also

View File

@ -124,13 +124,13 @@ changes to any JSON value.
The example below shows how object elements can be queried with a default value.
```cpp
--8<-- "examples/value__keytype.cpp"
--8<-- "examples/value__keytype.c++17.cpp"
```
Output:
```json
--8<-- "examples/value__keytype.output"
--8<-- "examples/value__keytype.c++17.output"
```
??? example "Example: (3) access specified object element via JSON Pointer with default value"