]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/pfr/example/get.cpp
1 // Copyright 2016-2020 Antony Polukhin
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See the accompanying file LICENSE_1_0.txt
5 // or a copy at <http://www.boost.org/LICENSE_1_0.txt>.)
9 The following example shows how to access structure fields by index using [funcref boost::pfr::get].
11 Let's define some structure:
13 #include <boost/pfr/core.hpp>
15 struct foo
{ // defining structure
21 We can access fields of that structure by index:
24 auto& r1
= boost::pfr::get
<0>(f
); // accessing field with index 0, returns reference to `foo::some_integer`
25 auto& r2
= boost::pfr::get
<1>(f
); // accessing field with index 1, returns reference to `foo::c`
26 //] [/pfr_example_get]
30 if (r1
!= 777) return 1;
31 if (r2
!= '!') return 2;
36 if (r1
!= 42) return 3;
37 if (r2
!= 'A') return 4;
38 if (f
.some_integer
!= 42) return 5;
39 if (f
.c
!= 'A') return 6;