| 1 | // Copyright (c) 2016-2024 Antony Polukhin |
| 2 | // |
| 3 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 4 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 5 | |
| 6 | |
| 7 | //[pfr_motivating_example |
| 8 | #include <iostream> |
| 9 | #include <string> |
| 10 | |
| 11 | #include "boost/pfr.hpp" |
| 12 | |
| 13 | struct some_person { |
| 14 | std::string name; |
| 15 | unsigned birth_year; |
| 16 | }; |
| 17 | |
| 18 | int main() { |
| 19 | some_person val{.name: "Edgar Allan Poe" , .birth_year: 1809}; |
| 20 | |
| 21 | std::cout << boost::pfr::get<0>(val) // No macro! |
| 22 | << " was born in " << boost::pfr::get<1>(val); // Works with any aggregate initializables! |
| 23 | |
| 24 | std::cout << boost::pfr::io(value&: val); // Outputs: {"Edgar Allan Poe", 1809} |
| 25 | } |
| 26 | //] |
| 27 | |