Reply to thread

PFR 101

[CODE]// Increment each field of the variable on 1 and

// output the content of the variable.


#include <cassert>

#include <boost/pfr.hpp>

#include <boost/type_index.hpp>

#include <iostream>


struct test {

    int f1;

    long f2;

};


test var{ 42, 43 };


boost::pfr::for_each_field(var, [](auto& field) {

    field += 1;

    });


// Outputs: {43, 44}

std::cout << boost::pfr::io(var);[/CODE]


Back
Top Bottom