From 41d73e45d4d5a51eb9deeb5d9c0068d1dff8189b Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Sun, 1 Oct 2017 21:57:27 +0300 Subject: [PATCH] Added one more example and some tests --- README.md | 26 +++++++++++++++++++++++++- test/Jamfile.v2 | 2 ++ test/precise/motivating_example0.cpp | 16 ++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 test/precise/motivating_example0.cpp diff --git a/README.md b/README.md index 27812a5..38a9e99 100644 --- a/README.md +++ b/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: | [![Build Status](https://travis-ci.org/apolukhin/magic_get.svg?branch=develop)](https://travis-ci.org/apolukhin/magic_get) | [![Coverage Status](https://coveralls.io/repos/github/apolukhin/magic_get/badge.png?branch=develop)](https://coveralls.io/github/apolukhin/magic_get?branch=develop) | Master: | [![Build Status](https://travis-ci.org/apolukhin/magic_get.svg?branch=master)](https://travis-ci.org/apolukhin/magic_get) | [![Coverage Status](https://coveralls.io/repos/github/apolukhin/magic_get/badge.png?branch=master)](https://coveralls.io/github/apolukhin/magic_get?branch=master) | +### Motivating Example #0 +```c++ +// requires: C++14 +#include +#include +#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++ diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 5e4471e..14184d6 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -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 ] diff --git a/test/precise/motivating_example0.cpp b/test/precise/motivating_example0.cpp new file mode 100644 index 0000000..ed4466c --- /dev/null +++ b/test/precise/motivating_example0.cpp @@ -0,0 +1,16 @@ +// requires: C++14 +#include +#include +#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); +}