Moved write to header, added read, seperated test and started using flint
This commit is contained in:
61
test/src/test.cpp
Normal file
61
test/src/test.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
#include <io.h>
|
||||
|
||||
#include <vector>
|
||||
#include <array>
|
||||
#include <fstream>
|
||||
|
||||
struct A {
|
||||
int b;
|
||||
};
|
||||
|
||||
namespace io {
|
||||
template <>
|
||||
void write(std::ostream& os, A value) {
|
||||
write<int>(os, value.b);
|
||||
}
|
||||
|
||||
template <>
|
||||
A read(std::istream& is) {
|
||||
return A{read<int>(is)};
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
{
|
||||
std::ofstream f("test.bin");
|
||||
io::write(f, 80085);
|
||||
io::write<size_t>(f, 123456);
|
||||
|
||||
io::write(f, "test");
|
||||
|
||||
std::array<char, 2> a = {'a', 'b'};
|
||||
io::write(f, a);
|
||||
|
||||
std::array<std::string, 2> b = {"Hello", "World"};
|
||||
io::write(f, b);
|
||||
|
||||
io::write(f, A{4});
|
||||
}
|
||||
|
||||
{
|
||||
std::ifstream f("test.bin");
|
||||
std::cout << io::read<int>(f) << '\n';
|
||||
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);
|
||||
for (auto& v : a) {
|
||||
std::cout << v << ' ';
|
||||
}
|
||||
std::cout << '\n';
|
||||
|
||||
auto b = io::read<std::vector<std::string>>(f);
|
||||
for (auto& v : b) {
|
||||
std::cout << v << ' ';
|
||||
}
|
||||
std::cout << '\n';
|
||||
|
||||
std::cout << io::read<A>(f).b << '\n';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user