|
2 | 2 | Copyright (C) 2001-2011 Joel de Guzman |
3 | 3 | Copyright (C) 2006 Dan Marsden |
4 | 4 | Copyright (C) 2010 Christopher Schmidt |
| 5 | + Copyright (c) 2022 Denis Mikhailov |
5 | 6 |
|
6 | 7 | Use, modification and distribution is subject to the Boost Software |
7 | 8 | License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
@@ -139,6 +140,95 @@ Linear, exactly `__result_of_size__<Sequence>::value`. |
139 | 140 |
|
140 | 141 | [endsect] |
141 | 142 |
|
| 143 | +[section pfr] |
| 144 | + |
| 145 | +[caution This function requires at least C++14! Pre C++14 compilers (C++11, C++03...) are not supported.] |
| 146 | +[important Also, please read __boost_pfr_lims__ before using this function. Pay special attention to the SimpleAggregate concept.] |
| 147 | + |
| 148 | +[heading Description] |
| 149 | + |
| 150 | +`pfr` is a generic version of __pfr_fields__. For a `val` conforming Fusion __sequence__, `pfr` returns it sequence unchanged. Otherwise, for a `val` like SimpleAggregate, `pfr` returns a new sequence with elements extracted by using __boost_pfr__. |
| 151 | + |
| 152 | +[heading Synopsis] |
| 153 | + template< |
| 154 | + typename SequenceOrSimpleAggregate |
| 155 | + > |
| 156 | + typename __result_of_pfr__<SequenceOrSimpleAggregate>::type pfr( |
| 157 | + SequenceOrSimpleAggregate& val); |
| 158 | + |
| 159 | + template< |
| 160 | + typename SequenceOrSimpleAggregate |
| 161 | + > |
| 162 | + typename __result_of_pfr__<SequenceOrSimpleAggregate const>::type pfr( |
| 163 | + SequenceOrSimpleAggregate const& val); |
| 164 | + |
| 165 | +[table Parameters |
| 166 | + [[Parameter][Requirement][Description]] |
| 167 | + [[`val`][A model of Sequence, or a model of SimpleAggregate][Operation's argument]] |
| 168 | +] |
| 169 | + |
| 170 | +[heading Expression Semantics] |
| 171 | + __pfr__(val); |
| 172 | + |
| 173 | +[*Return type]: |
| 174 | + |
| 175 | +* A model of __forward_sequence__ if `val` is a __forward_sequence__ |
| 176 | +else, __bidirectional_sequence__ if `val` is a __bidirectional_sequence__ |
| 177 | +else, __random_access_sequence__ if `val` is a __random_access_sequence__ or SimpleAggregate. |
| 178 | +* A model of __associative_sequence__ if `val` implements the __associative_sequence__ model. |
| 179 | + |
| 180 | +[*Semantics]: Returns a sequence with all elements of `SequenceOrSimpleAggregate`. |
| 181 | + |
| 182 | +[heading Complexity] |
| 183 | +Constant. |
| 184 | + |
| 185 | +[heading Header] |
| 186 | + |
| 187 | + #include <boost/fusion/algorithm/auxiliary/pfr.hpp> |
| 188 | + #include <boost/fusion/include/pfr.hpp> |
| 189 | + |
| 190 | +[note This algorithm won't defined by inclusion of 'boost/fusion/algorithm/auxiliary.hpp' or 'boost/fusion/algorithm.hpp'. ] |
| 191 | + |
| 192 | +[heading Example] |
| 193 | + |
| 194 | + struct some_person { // SimpleAggregate |
| 195 | + std::string name; |
| 196 | + unsigned birth_year; |
| 197 | + }; |
| 198 | + |
| 199 | + some_person val{"Edgar Allan Poe", 1809}; |
| 200 | + std::cout << __pfr__(val) << std::endl; // (Edgar Allan Poe 1809) |
| 201 | + |
| 202 | +[heading Example] |
| 203 | + |
| 204 | + struct empty { // SimpleAggregate |
| 205 | + }; |
| 206 | + |
| 207 | + struct aggregate : empty { // not a SimpleAggregate, not a Sequence |
| 208 | + std::string name; |
| 209 | + int age; |
| 210 | + boost::uuids::uuid uuid; |
| 211 | + }; |
| 212 | + |
| 213 | + aggregate val{"Edgar Allan Poe", 1809, {}}; |
| 214 | + __pfr__(val); // non-portable behavior |
| 215 | + |
| 216 | +[heading Example] |
| 217 | + |
| 218 | + using some_person = __vector__< // not a SimpleAggregate, but Sequence |
| 219 | + std::string |
| 220 | + , unsigned |
| 221 | + >; |
| 222 | + |
| 223 | + some_person val("Edgar Allan Poe", 1809); |
| 224 | + std::cout << __pfr__(val) << std::endl; // (Edgar Allan Poe 1809) |
| 225 | + |
| 226 | +[heading See also] |
| 227 | + |
| 228 | +__boost_pfr__ |
| 229 | + |
| 230 | +[endsect] |
| 231 | + |
142 | 232 | [endsect] |
143 | 233 |
|
144 | 234 | [section Metafunctions] |
@@ -215,6 +305,54 @@ Constant. |
215 | 305 |
|
216 | 306 | [endsect] |
217 | 307 |
|
| 308 | +[section pfr] |
| 309 | + |
| 310 | +[caution This metafunction requires at least C++14! Pre C++14 compilers (C++11, C++03...) are not supported.] |
| 311 | +[important Also, please read __boost_pfr_lims__ before using this metafunction. Pay special attention to the SimpleAggregate concept.] |
| 312 | + |
| 313 | +[heading Description] |
| 314 | +A metafunction returning the result type of applying __pfr__. |
| 315 | + |
| 316 | +[heading Synopsis] |
| 317 | + template <typename SequenceOrSimpleAggregate> |
| 318 | + struct pfr |
| 319 | + { |
| 320 | + typedef __unspecified__ type; |
| 321 | + }; |
| 322 | + |
| 323 | +[table Parameters |
| 324 | + [[Parameter] [Requirement] [Description]] |
| 325 | + [[`SequenceOrSimpleAggregate`] [Model of Fusion __sequence__ or model of SimpleAggregate from __boost_pfr__] [Operation's argument]] |
| 326 | +] |
| 327 | + |
| 328 | +[heading Expression Semantics] |
| 329 | + result_of::pfr<SequenceOrSimpleAggregate>::type |
| 330 | + |
| 331 | +[*Return type]: |
| 332 | + |
| 333 | +* A model of __forward_sequence__ if `val` is a __forward_sequence__ |
| 334 | +else, __bidirectional_sequence__ if `val` is a __bidirectional_sequence__ |
| 335 | +else, __random_access_sequence__ if `val` is a __random_access_sequence__ or SimpleAggregate. |
| 336 | +* A model of __associative_sequence__ if `val` implements the __associative_sequence__ model. |
| 337 | + |
| 338 | +[*Semantics]: Returns a sequence with all elements of `SequenceOrSimpleAggregate`. |
| 339 | + |
| 340 | +[heading Complexity] |
| 341 | +Constant. |
| 342 | + |
| 343 | +[heading Header] |
| 344 | + |
| 345 | + #include <boost/fusion/algorithm/auxiliary/pfr.hpp> |
| 346 | + #include <boost/fusion/include/pfr.hpp> |
| 347 | + |
| 348 | +[note This algorithm won't defined by inclusion of 'boost/fusion/algorithm/auxiliary.hpp' or 'boost/fusion/algorithm.hpp'. ] |
| 349 | + |
| 350 | +[heading See also] |
| 351 | + |
| 352 | +__boost_pfr__ |
| 353 | + |
| 354 | +[endsect] |
| 355 | + |
218 | 356 | [endsect] |
219 | 357 |
|
220 | 358 | [endsect] |
|
0 commit comments