Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add to_node() implementations for STL container types #465

Merged
merged 12 commits into from
Jan 14, 2025
4 changes: 4 additions & 0 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ jobs:
runs-on: ubuntu-latest
container: silkeh/clang:latest
strategy:
fail-fast: false
matrix:
cxx_standard: [ "11", "14", "17", "20", "23" ]
build_type: [ Debug, Release ]
Expand Down Expand Up @@ -169,6 +170,7 @@ jobs:
runs-on: ubuntu-latest
container: gcc:latest
strategy:
fail-fast: false
matrix:
cxx_standard: [ "11", "14", "17", "20", "23" ]
build_type: [ Debug, Release ]
Expand Down Expand Up @@ -199,6 +201,7 @@ jobs:
ci_test_clang_versions:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
compiler: [ "3.4", "3.5", "3.6", "3.7", "3.8", "3.9", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19" ]
build_type: [ Debug, Release ]
Expand Down Expand Up @@ -236,6 +239,7 @@ jobs:
ci_test_gcc_versions:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
compiler: [ "7", "8", "9", "10", "11", "12", "13", "14", latest ]
build_type: [ Debug, Release ]
Expand Down
8 changes: 8 additions & 0 deletions docs/docs/api/basic_node/constructor.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,16 @@ Available overloads are:
Template parameter `CompatibleType` includes, but not limited to, the following types:
* sequences:
* [`sequence_type`](sequence_type.md)
* container types which fulfills the following requirements, e.g., `std::vector` or `std::set`.
* Both `begin()` and `end()` are callable on a `CompatibleType` object.
* `CompatibleType` doesn't have both `key_type` and `mapped_type` member types.
* A [`string_type`](string_type.md) object is not constructible from a `CompatibleType` object.
* `std::pair` and `std::tuple`
* mappings
* [`mapping_type`](mapping_type.md)
* container types which fullfills the following requirements, e.g., `std::map` or `std::unordered_multimap`.
* Both `begin()` and `end()` are callable on a `CompatibleType` object.
* `CompatibleType` has both `key_type` and `mapped_type` member types.
* null
* [`std::nullptr_t`](https://en.cppreference.com/w/cpp/types/nullptr_t)
* booleans
Expand Down
27 changes: 24 additions & 3 deletions examples/apis/basic_node/constructor_6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,32 @@
// SPDX-License-Identifier: MIT

#include <iostream>
#include <list>
#include <tuple>
#include <unordered_map>
#include <fkYAML/node.hpp>

int main() {
double pi = 3.141592;
fkyaml::node n = pi;
std::cout << n << std::endl;
// create nodes from objects of various types.
fkyaml::node sequence0 = std::list<bool> {true, false, false};
fkyaml::node sequence1 = std::make_tuple<std::string, int, bool>("foo", 123, true);
std::unordered_map<int, float> map_val = {{123, 3.14f}, {-456, 1.41f}};
fkyaml::node mapping = std::move(map_val);
fkyaml::node null = nullptr;
fkyaml::node boolean = false;
fkyaml::node integer = 12345;
fkyaml::node floating_point = 3.141592;
const char str_chars[] = "test";
fkyaml::node string = str_chars;

// print node values
std::cout << sequence0 << std::endl;
std::cout << sequence1 << std::endl;
std::cout << mapping << std::endl;
std::cout << null << std::endl;
std::cout << boolean << std::endl;
std::cout << integer << std::endl;
std::cout << floating_point << std::endl;
std::cout << string << std::endl;
return 0;
}
15 changes: 15 additions & 0 deletions examples/apis/basic_node/constructor_6.output
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
- true
- false
- false

- foo
- 123
- true

-456: 1.41
123: 3.14

null
false
12345
3.14159
test
Loading
Loading