sparrow 0.3.0
Loading...
Searching...
No Matches
typed_array_high_level.cpp
Go to the documentation of this file.
1
5
6// #include <sparrow/array/array_data.hpp>
7
8
9/*void example_typed_array_of_floats(){
10 using value_type = float;
11 std::vector<value_type> data = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f};
12
13 // construct the array
14 auto array = sparrow::typed_array<value_type>(data);
15
16 // access the data
17 for (auto i = 0; i < array.size(); ++i) {
18
19 if (array[i].has_value()) {
20 std::cout << array[i].value() << std::endl;
21 } else {
22 std::cout << "missing value" << std::endl;
23 }
24 }
25}
26
27
28void example_typed_array_of_strings(){
29 using value_type = std::string;
30 std::vector<std::string> data = {
31 "one",
32 "two",
33 "three",
34 "four",
35 "five"
36 };
37
38 // construct the array
39 auto array = sparrow::typed_array<value_type>(data);
40
41 // access the data
42 for (auto i = 0; i <array.size(); ++i) {
43 if (array[i].has_value()) {
44 auto value = array[i].value();
45 std::cout << std::string(value.begin(), value.end()) << std::endl;
46 } else {
47 std::cout << "missing value" << std::endl;
48 }
49 }
50}
51
52void example_typed_array_of_strings_from_nullables(){
53
54 using value_type = std::string;
55 using nullable_type = sparrow::nullable<value_type>;
56
57 std::vector<nullable_type> data = {
58 nullable_type("one"),
59 nullable_type("two"),
60 nullable_type(),
61 nullable_type("four"),
62 nullable_type("five")
63 };
64
65 // construct the array
66 auto array = sparrow::typed_array<value_type>(data);
67
68 // access the data
69 for (auto i = 0; i <array.size(); ++i) {
70 if (array[i].has_value()) {
71 auto value = array[i].value();
72 std::cout << std::string(value.begin(), value.end()) << std::endl;
73 } else {
74 std::cout << "missing value" << std::endl;
75 }
76 }
77}*/
78int main()
79{
80 // example_typed_array_of_floats();
81 // example_typed_array_of_strings();
82 // example_typed_array_of_strings_from_nullables();
83 return 0;
84}
int main()