Improved container support
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
|
||||
#include <vector>
|
||||
#include <array>
|
||||
#include <list>
|
||||
#include <fstream>
|
||||
#include <experimental/source_location>
|
||||
|
||||
struct A {
|
||||
int b;
|
||||
@@ -29,12 +31,25 @@ int main() {
|
||||
io::write(f, "test");
|
||||
|
||||
std::array<char, 2> a = {'a', 'b'};
|
||||
// Does not store length by default
|
||||
io::write(f, a);
|
||||
|
||||
std::array<std::string, 2> b = {"Hello", "World"};
|
||||
io::write(f, b);
|
||||
std::array b = {"Hello", "World"};
|
||||
// Explicitly store length
|
||||
io::write(f, b, true);
|
||||
|
||||
std::vector<int> c = {1, 2, 3, 4, 5};
|
||||
// Stores length by default
|
||||
io::write(f, c);
|
||||
|
||||
std::list d = {6, 7, 8, 9};
|
||||
// Stores length by default
|
||||
io::write(f, d);
|
||||
|
||||
io::write(f, A{4});
|
||||
|
||||
std::array e = {A{1}, A{5}, A{3}};
|
||||
io::write(f, e, true);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -43,19 +58,39 @@ int main() {
|
||||
std::cout << io::read<size_t>(f) << '\n';
|
||||
std::cout << io::read<std::string>(f) << '\n';
|
||||
|
||||
// auto v = io::read<std::array<char, 2>>(f);
|
||||
auto a = io::read<std::vector<char>>(f);
|
||||
// Length is implied by the array
|
||||
auto a = io::read<std::array<char,2>>(f);
|
||||
for (auto& v : a) {
|
||||
std::cout << v << ' ';
|
||||
}
|
||||
std::cout << '\n';
|
||||
|
||||
// Length is read from file (optionally can be provided as parameter)
|
||||
auto b = io::read<std::vector<std::string>>(f);
|
||||
for (auto& v : b) {
|
||||
std::cout << v << ' ';
|
||||
}
|
||||
std::cout << '\n';
|
||||
|
||||
auto c = io::read<std::vector<int>>(f);
|
||||
for (auto& v : c) {
|
||||
std::cout << v << ' ';
|
||||
}
|
||||
std::cout << '\n';
|
||||
|
||||
auto d = io::read<std::list<int>>(f);
|
||||
for (auto& v : d) {
|
||||
std::cout << v << ' ';
|
||||
}
|
||||
std::cout << '\n';
|
||||
|
||||
std::cout << io::read<A>(f).b << '\n';
|
||||
|
||||
auto e = io::read<std::list<int>>(f);
|
||||
for (auto& v : e) {
|
||||
std::cout << v << ' ';
|
||||
}
|
||||
std::cout << '\n';
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user