Skip to content

Commit

Permalink
updated docs & examples
Browse files Browse the repository at this point in the history
  • Loading branch information
fktn-k committed Jan 14, 2025
1 parent 1b24ba4 commit 0967aee
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
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

0 comments on commit 0967aee

Please sign in to comment.