This is the header only library to work with aggregate types and tuple-like objects (std::tuple
, std::pair
and std::array
).
Features:
-
Get struct from tuple-like object
struct Person { std::string name; int age; double weight; }; ... std::tuple<std::string, int, double> tuple {"Peter", 10, 20}; Person person = flow::tul::from_tuple<Person>(tuple);
person
will contain valuesPeter
,10
,20
-
Write tuple-like objects to ostream
std::tuple<std::string, int, double> tuple {"Peter", 10, 20}; std::cout << flow::tul::io(tuple);
Output
("Peter", 10, 20)
-
Write tuple-like object to ostream using custom separator
std::tuple<std::string, char> tuple {"Peter", 'k'}; std::cout << flow::tul::io(tuple, " * ");
Output
"Peter" * 'k'
-
Put values from istream to tuple-like object (also supports custom separator)
std::tuple<std::string, int> tuple; std::cin >> flow::tul::io(tuple); std::cout << flow::tul::io(tuple);
Input
("Hello", 5)
Output
("Hello", 5)
-
For each cycle for tuple-like object elements
void mult_by_3(int& n) { n *= 3; } ... std::tuple<int, int, int> tuple {1, 2, 3}; flow::tul::for_each(tuple, mult_by_3); std::cout << flow::tul::io(tuple);
Output
(3, 6, 9)
-
Get aggregate type fields count (since C++20)
std::cout << flow::tul::aggregate_size_v<Person>;
or
std::cout << flow::tul::aggregate_size<Person>::value;
Output
3
Put directory flow
to your project and include tul.hpp
header. Nothing to build
googletest
is required for run tests.
To run tests follow this steps:
-
If you already have
googletest
downloaded and built, then you can just put it to thetests
directory and go to the next step.If you don't have
googletest
, then clone repository using this commandgit clone --recurse-submodules https://github.com/RifeX-LA/tul.git
or if you already cloned this repository you need to clone googletest repository to the
tests
directory using this commandgit clone https://github.com/google/googletest.git
-
To build tests in the
tests
directory:mkdir build cd build cmake ..
On *nix system run
make
On Windows system you can build project using Visual Studio
-
Run
Google_Tests_run
file to start the tests
- C++17 (C++20 for
flow::tul::aggregate_size
) boost
librarygoogletest
for run tests