mirror of
https://github.com/boostorg/pfr.git
synced 2026-01-19 04:22:13 +00:00
Added one more example and some tests
This commit is contained in:
26
README.md
26
README.md
@@ -1,6 +1,6 @@
|
||||
# Precise and Flat Reflection (ex Magic Get, ex PODs Flat Reflection)
|
||||
|
||||
This C++14 library is meant for accessing structure elements by index and providing other std::tuple like methods for user defined types.
|
||||
This C++14 library is meant for accessing structure elements by index and providing other std::tuple like methods for user defined types without any macro or boilerplate code.
|
||||
|
||||
|
||||
[Latest documentation](http://apolukhin.github.com/magic_get/index.html)
|
||||
@@ -14,6 +14,30 @@ Branches | Build | Tests coverage | More info
|
||||
Develop: | [](https://travis-ci.org/apolukhin/magic_get) <!-- [](https://ci.appveyor.com/project/apolukhin/boost-dll/branch/develop) --> | [](https://coveralls.io/github/apolukhin/magic_get?branch=develop) | <!-- [details...](http://www.boost.org/development/tests/develop/developer/pfr.html)) -->
|
||||
Master: | [](https://travis-ci.org/apolukhin/magic_get) <!-- [](https://ci.appveyor.com/project/apolukhin/boost-dll/branch/master) --> | [](https://coveralls.io/github/apolukhin/magic_get?branch=master) | <!-- [details...](http://www.boost.org/development/tests/master/developer/pfr.html)) -->
|
||||
|
||||
### Motivating Example #0
|
||||
```c++
|
||||
// requires: C++14
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "boost/pfr.hpp"
|
||||
|
||||
struct some_person {
|
||||
std::string name;
|
||||
unsigned birth_year;
|
||||
};
|
||||
|
||||
int main() {
|
||||
some_person val{"Edgar Allan Poe", 1809};
|
||||
|
||||
std::cout << boost::pfr::get<0>(val)
|
||||
<< " was born in " << boost::pfr::get<1>(val);
|
||||
}
|
||||
```
|
||||
Outputs:
|
||||
```
|
||||
Edgar Allan Poe was born in 1809
|
||||
```
|
||||
|
||||
|
||||
### Motivating Example #1
|
||||
```c++
|
||||
|
||||
@@ -86,6 +86,7 @@ test-suite pfr
|
||||
[ run precise/tuple_size.cpp : : : : precise_tuple_size ]
|
||||
[ run precise/bitfields.cpp : : : : precise_tuple_size_on_bitfields ]
|
||||
[ run precise/for_each_field.cpp : : : : precise_for_each_field ]
|
||||
[ run precise/motivating_example0.cpp : : : : precise_motivating_example0 ]
|
||||
[ run precise/motivating_example.cpp : : : : precise_motivating_example ]
|
||||
[ run precise/motivating_example2.cpp : : : : precise_motivating_example2 ]
|
||||
[ compile-fail precise/non_aggregate.cpp : : precise_non_aggregate ]
|
||||
@@ -102,6 +103,7 @@ test-suite pfr
|
||||
[ run precise/tuple_size.cpp : : : $(LOOPHOLE_PREC_DEF) : precise_lh_tuple_size ]
|
||||
[ run precise/bitfields.cpp : : : $(LOOPHOLE_PREC_DEF) : precise_lh_tuple_size_on_bitfields ]
|
||||
[ run precise/for_each_field.cpp : : : $(LOOPHOLE_PREC_DEF) : precise_lh_for_each_field ]
|
||||
[ run precise/motivating_example0.cpp : : : $(LOOPHOLE_PREC_DEF) : precise_lh_motivating_example0 ]
|
||||
[ run precise/motivating_example.cpp : : : $(LOOPHOLE_PREC_DEF) : precise_lh_motivating_example ]
|
||||
[ run precise/motivating_example2.cpp : : : $(LOOPHOLE_PREC_DEF) : precise_lh_motivating_example2 ]
|
||||
[ compile-fail precise/non_aggregate.cpp : $(LOOPHOLE_PREC_DEF) : precise_lh_non_aggregate ]
|
||||
|
||||
16
test/precise/motivating_example0.cpp
Normal file
16
test/precise/motivating_example0.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
// requires: C++14
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "boost/pfr.hpp"
|
||||
|
||||
struct some_person {
|
||||
std::string name;
|
||||
unsigned birth_year;
|
||||
};
|
||||
|
||||
int main() {
|
||||
some_person val{"Edgar Allan Poe", 1809};
|
||||
|
||||
std::cout << boost::pfr::get<0>(val)
|
||||
<< " was born in " << boost::pfr::get<1>(val);
|
||||
}
|
||||
Reference in New Issue
Block a user