Skip to content

Commit b75cad1

Browse files
committed
[pfr_view_generic] Just docs
1 parent 23e78a5 commit b75cad1

6 files changed

Lines changed: 246 additions & 0 deletions

File tree

doc/algorithm.qbk

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Copyright (C) 2001-2011 Joel de Guzman
33
Copyright (C) 2006 Dan Marsden
44
Copyright (C) 2010 Christopher Schmidt
5+
Copyright (c) 2022 Denis Mikhailov
56

67
Use, modification and distribution is subject to the Boost Software
78
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`.
139140

140141
[endsect]
141142

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+
142232
[endsect]
143233

144234
[section Metafunctions]
@@ -215,6 +305,54 @@ Constant.
215305

216306
[endsect]
217307

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+
218356
[endsect]
219357

220358
[endsect]

doc/fusion.qbk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
[def __boost_func_forward__ [@http://www.boost.org/libs/functional/forward Boost.Functional/Forward Library]]
4949
[def __boost_func_factory__ [@http://www.boost.org/libs/functional/factory Boost.Functional/Factory Library]]
5050
[def __boost_func_hash__ [@http://www.boost.org/doc/html/hash.html Boost.ContainerHash Library]]
51+
[def __boost_pfr__ [@http://www.boost.org/doc/html/boost_pfr.html Boost.PFR Library]]
52+
[def __boost_pfr_lims__ [@http://www.boost.org/doc/html/boost_pfr/limitations_and_configuration.html Boost.PFR Limitations and Configuration]]
5153
[def __std_pair_doc__ [@http://en.cppreference.com/w/cpp/utility/pair `std::pair`]]
5254
[def __std_tuple_doc__ [@http://en.cppreference.com/w/cpp/utility/tuple `std::tuple`]]
5355
[def __std_plus_doc__ [@http://en.cppreference.com/w/cpp/utility/functional/plus `std::plus`]]
@@ -131,6 +133,7 @@
131133
[def __zip_view__ [link fusion.view.zip_view `zip_view`]]
132134
[def __flatten_view__ [link fusion.view.flatten_view `flatten_view`]]
133135
[def __identity_view__ [link fusion.view.identity_view `identity_view`]]
136+
[def __pfr_view__ [link fusion.view.pfr_view `pfr_view`]]
134137

135138
[def __array__ [link fusion.adapted.array array]]
136139
[def __std_pair__ [link fusion.adapted.std__pair `std::pair`]]
@@ -229,6 +232,8 @@
229232
[def __result_of_copy__ [link fusion.algorithm.auxiliary.metafunctions.copy `result_of::copy`]]
230233
[def __move__ [link fusion.algorithm.auxiliary.functions.move `move`]]
231234
[def __result_of_move__ [link fusion.algorithm.auxiliary.metafunctions.move `result_of::move`]]
235+
[def __pfr__ [link fusion.algorithm.auxiliary.functions.pfr `pfr`]]
236+
[def __result_of_pfr__ [link fusion.algorithm.auxiliary.metafunctions.pfr `result_of::pfr`]]
232237
[def __fold__ [link fusion.algorithm.iteration.functions.fold `fold`]]
233238
[def __result_of_fold__ [link fusion.algorithm.iteration.metafunctions.fold `result_of::fold`]]
234239
[def __reverse_fold__ [link fusion.algorithm.iteration.functions.reverse_fold `reverse_fold`]]

doc/html/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@
164164
<dt><span class="section"><a href="fusion/view/transform_view.html">transform_view</a></span></dt>
165165
<dt><span class="section"><a href="fusion/view/reverse_view.html">reverse_view</a></span></dt>
166166
<dt><span class="section"><a href="fusion/view/identity_view.html">identity_view</a></span></dt>
167+
<dt><span class="section"><a href="fusion/view/pfr_view.html">pfr_view</a></span></dt>
167168
<dt><span class="section"><a href="fusion/view/nview.html">nview</a></span></dt>
168169
<dt><span class="section"><a href="fusion/view/repetitive_view.html">repetitive_view</a></span></dt>
169170
<dt><span class="section"><a href="fusion/view/flatten_view.html">flatten_view</a></span></dt>

doc/organization.qbk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ link against.
6161
* transform_view
6262
* zip_view
6363
* identity_view
64+
* pfr_view
6465
* container
6566
* deque
6667
* list

doc/sequence.qbk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ For any Forward Sequence s the following invariants always hold:
134134
* __reverse_view__
135135
* __zip_view__
136136
* __identity_view__
137+
* __pfr_view__
137138

138139
[endsect]
139140

@@ -203,6 +204,7 @@ are not defined in __forward_sequence__.
203204
* __transform_view__ (where adapted sequence is a Bidirectional Sequence)
204205
* __zip_view__ (where adapted sequences are models of Bidirectional Sequence)
205206
* __identity_view__ (where adapted sequence is a Bidirectional Sequence)
207+
* __pfr_view__
206208

207209
[endsect]
208210

@@ -292,6 +294,7 @@ are not defined in __bidirectional_sequence__.
292294
* __transform_view__ (where adapted sequence is a Random Access Sequence)
293295
* __zip_view__ (where adapted sequences are models of Random Access Sequence)
294296
* __identity_view__ (where adapted sequence is a Random Access Sequence)
297+
* __pfr_view__
295298

296299
[endsect]
297300

@@ -365,6 +368,7 @@ you can use `__result_of_value_at_key__<S, K>`.]
365368
* __reverse_view__ (where adapted sequence is an __associative_sequence__ and a __bidirectional_sequence__)
366369
* __transform_view__ (where adapted sequence is an __associative_sequence__ and a __forward_sequence__)
367370
* __identity_view__ (where adapted sequence is an __associative_sequence__ and a __forward_sequence__)
371+
* __pfr_view__ (where adapted type is an __associative_sequence__ and a __forward_sequence__)
368372

369373
[endsect]
370374

doc/view.qbk

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,4 +721,101 @@ defined in the implemented models.
721721

722722
[endsect]
723723

724+
[section pfr_view]
725+
726+
[caution This view requires at least C++14! Pre C++14 compilers (C++11, C++03...) are not supported.]
727+
[important Also, please read __boost_pfr_lims__ before using this view. Pay special attention to the SimpleAggregate concept.]
728+
729+
[heading Description]
730+
731+
`pfr_view` is a generic version of __pfr_fields_view__. If underlying type is a conforming Fusion __sequence__, then it type will be presented unchanged. Otherwise, the underlying type must satisfy SimpleAggregate concept, because it type will be presented as a random access sequence by using __boost_pfr__.
732+
733+
[heading Header]
734+
735+
#include <boost/fusion/view/pfr_view.hpp>
736+
#include <boost/fusion/include/pfr_view.hpp>
737+
738+
[note This view won't defined by inclusion of 'boost/fusion/view.hpp'. ]
739+
740+
[heading Synopsis]
741+
742+
template <typename SequenceOrSimpleAggregate>
743+
struct pfr_view;
744+
745+
[heading Template parameters]
746+
747+
[table
748+
[[Parameter] [Description] [Default]]
749+
[[`SequenceOrSimpleAggregate`] [A fusion __sequence__ or an user defined structure, satisfied 'SimpleAggregate' concept] []]
750+
]
751+
752+
[heading Model of]
753+
754+
* A model of __forward_sequence__ if underlying type is a __forward_sequence__
755+
else, __bidirectional_sequence__ if underlying type is a __bidirectional_sequence__
756+
else, __random_access_sequence__ if underlying type is a __random_access_sequence__ or SimpleAggregate.
757+
* __associative_sequence__ if underlying type implements the __associative_sequence__ model.
758+
759+
[variablelist Notation
760+
[[`P`] [A `pfr_view` type]]
761+
[[`p`, `p2`] [Instances of `pfr_view`]]
762+
[[`a`] [An instance of `SimpleAggregate`]]
763+
[[`s`] [An instance of `Sequence`]]
764+
]
765+
766+
[heading Expression Semantics]
767+
768+
Semantics of an expression is defined only where it differs from, or is not
769+
defined in __random_access_sequence__.
770+
771+
[table
772+
[[Expression] [Semantics]]
773+
[[`P(a)`] [Creates a `pfr_view` from simple aggregate `a`.]]
774+
[[`P(a)`] [Creates a `pfr_view` from sequence `s`.]]
775+
[[`P(p)`] [Copy constructs a `pfr_view` from another `pfr_view`, `p`.]]
776+
[[`p = p2`] [Assigns to a `pfr_view`, `p`, from another `pfr_view`, `p2`.]]
777+
]
778+
779+
[heading Example]
780+
781+
struct some_person { // SimpleAggregate
782+
std::string name;
783+
unsigned birth_year;
784+
};
785+
786+
some_person val{"Edgar Allan Poe", 1809};
787+
__pfr_view__<some_person> view(val);
788+
std::cout << view << std::endl; // (Edgar Allan Poe 1809)
789+
790+
[heading Example]
791+
792+
struct empty { // SimpleAggregate
793+
};
794+
795+
struct aggregate : empty { // not a SimpleAggregate
796+
std::string name;
797+
int age;
798+
boost::uuids::uuid uuid;
799+
};
800+
801+
aggregate val{"Edgar Allan Poe", 1809, {}};
802+
__pfr_view__<aggregate> view(val); // non-portable behavior
803+
804+
[heading Example]
805+
806+
using some_person = __vector__< // not a SimpleAggregate, but Sequence
807+
std::string
808+
, unsigned
809+
>;
810+
811+
some_person val("Edgar Allan Poe", 1809);
812+
__pfr_view__<some_person> view(val);
813+
std::cout << view << std::endl; // (Edgar Allan Poe 1809)
814+
815+
[heading See also]
816+
817+
__boost_pfr__
818+
819+
[endsect]
820+
724821
[endsect]

0 commit comments

Comments
 (0)