2
0
mirror of https://github.com/boostorg/pfr.git synced 2026-01-19 04:22:13 +00:00

Added info about reinterpret casts into the reference section. Improved formatting and added more examples

This commit is contained in:
Antony Polukhin
2017-01-05 20:54:08 +03:00
parent 6ea565dd6d
commit afd995e5dd
15 changed files with 161 additions and 30 deletions

View File

@@ -101,6 +101,9 @@ assert(r == 11);
#include <iostream>
#include <boost/type_index.hpp>
#include <unordered_set>
#include <set>
#include <boost/pfr.hpp>
namespace quick_examples_ns {
@@ -131,6 +134,44 @@ void test_examples() {
{
bar var{'A', {777, 3.141593}};
//[pfr_quick_examples_flat_functors_uset
// no `std::hash<bar>` or `bar::operator==(const bar&)` defined
std::unordered_set<bar, boost::pfr::flat_hash<bar>, boost::pfr::flat_equal_to<>> my_uset;
my_uset.insert(var);
//]
}
{
bar var{'A', {777, 3.141593}};
//[pfr_quick_examples_flat_functors_set
// no `bar::operator<(const bar&)` defined
std::set<bar, boost::pfr::flat_less<>> my_set;
my_set.insert(var);
//]
}
{
//[pfr_quick_examples_flat_ops
using namespace boost::pfr::flat_ops; // Defines comparisons
assert((var < bar{'Z', {}} && var.f == foo{777, 3.141593}));
//]
std::cout << "boost::pfr::flat_structure_tie(var) :\n" << var << '\n';
}
#if __cplusplus >= 201606L /* Oulu meeting, not the exact value */
{
//[pfr_quick_examples_ops
struct test { std::string f1; std::string_view f2; };
using namespace boost::pfr::ops; // Defines comparisons
assert((test{"abc", ""} > test{"aaa", "zomg"}));
//]
}
#endif
{
bar var{'A', {777, 3.141593}};
//[pfr_quick_examples_flat_for_each
// incrementing each field on 1:
boost::pfr::flat_for_each_field(var, [](auto& field) {