Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ target_link_libraries(boost_fusion
Boost::type_traits
Boost::typeof
Boost::utility
Boost::pfr
Boost::mp11
)
2 changes: 2 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ install:
- git submodule init libs/type_traits
- git submodule init libs/typeof
- git submodule init libs/utility
- git submodule init libs/pfr
- git submodule init libs/mp11

- git submodule init libs/headers tools/boost_install tools/build
- git submodule update
Expand Down
139 changes: 139 additions & 0 deletions doc/algorithm.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Copyright (C) 2001-2011 Joel de Guzman
Copyright (C) 2006 Dan Marsden
Copyright (C) 2010 Christopher Schmidt
Copyright (c) 2022 Denis Mikhailov

Use, modification and distribution is subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Expand Down Expand Up @@ -139,6 +140,96 @@ Linear, exactly `__result_of_size__<Sequence>::value`.

[endsect]

[section pfr]

[caution This function requires at least C++14! Pre C++14 compilers (C++11, C++03...) are not supported.]
[important Also, please read __boost_pfr_lims__ before using this function. Pay special attention to the SimpleAggregate concept.]

[heading Description]

`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__.

[heading Synopsis]
template<
typename SequenceOrSimpleAggregate
>
typename __result_of_pfr__<SequenceOrSimpleAggregate>::type pfr(
SequenceOrSimpleAggregate& val);

template<
typename SequenceOrSimpleAggregate
>
typename __result_of_pfr__<SequenceOrSimpleAggregate const>::type pfr(
SequenceOrSimpleAggregate const& val);

[table Parameters
[[Parameter][Requirement][Description]]
[[`val`][A model of Sequence, or a model of SimpleAggregate][Operation's argument]]
]

[heading Expression Semantics]
__pfr__(val);

[*Return type]:

* A model of __forward_sequence__ if `val` is a __forward_sequence__
else, __bidirectional_sequence__ if `val` is a __bidirectional_sequence__
else, __random_access_sequence__ if `val` is a __random_access_sequence__ or SimpleAggregate.
* A model of __associative_sequence__ if `val` implements the __associative_sequence__ model.

[*Semantics]: Returns a sequence with all elements of `SequenceOrSimpleAggregate`.

[heading Complexity]
Constant.

[heading Header]

#include <boost/fusion/algorithm/auxiliary/pfr.hpp>
#include <boost/fusion/include/pfr.hpp>

[note This algorithm won't defined by inclusion of 'boost/fusion/algorithm/auxiliary.hpp' or 'boost/fusion/algorithm.hpp'. ]

[heading Example]

struct some_person { // SimpleAggregate
std::string name;
unsigned birth_year;
};

some_person val{"Edgar Allan Poe", 1809};
std::cout << __pfr__(val) << std::endl; // (Edgar Allan Poe 1809)

[heading Example]

struct empty { // SimpleAggregate
};

struct aggregate : empty { // not a SimpleAggregate, not a Sequence
std::string name;
int age;
boost::uuids::uuid uuid;
};

aggregate val{"Edgar Allan Poe", 1809, {}};
__pfr__(val); // non-portable behavior

[heading Example]

using some_person = __vector__< // not a SimpleAggregate, but Sequence
std::string
, unsigned
>;

some_person val("Edgar Allan Poe", 1809);
std::cout << __pfr__(val) << std::endl; // (Edgar Allan Poe 1809)

[heading See also]

__boost_pfr__

[endsect]

[endsect]

[section Metafunctions]
Expand Down Expand Up @@ -215,6 +306,54 @@ Constant.

[endsect]

[section pfr]

[caution This metafunction requires at least C++14! Pre C++14 compilers (C++11, C++03...) are not supported.]
[important Also, please read __boost_pfr_lims__ before using this metafunction. Pay special attention to the SimpleAggregate concept.]

[heading Description]
A metafunction returning the result type of applying __pfr__.

[heading Synopsis]
template <typename SequenceOrSimpleAggregate>
struct pfr
{
typedef __unspecified__ type;
};

[table Parameters
[[Parameter] [Requirement] [Description]]
[[`SequenceOrSimpleAggregate`] [Model of Fusion __sequence__ or model of SimpleAggregate from __boost_pfr__] [Operation's argument]]
]

[heading Expression Semantics]
result_of::pfr<SequenceOrSimpleAggregate>::type

[*Return type]:

* A model of __forward_sequence__ if `val` is a __forward_sequence__
else, __bidirectional_sequence__ if `val` is a __bidirectional_sequence__
else, __random_access_sequence__ if `val` is a __random_access_sequence__ or SimpleAggregate.
* A model of __associative_sequence__ if `val` implements the __associative_sequence__ model.

[*Semantics]: Returns a sequence with all elements of `SequenceOrSimpleAggregate`.

[heading Complexity]
Constant.

[heading Header]

#include <boost/fusion/algorithm/auxiliary/pfr.hpp>
#include <boost/fusion/include/pfr.hpp>

[note This algorithm won't defined by inclusion of 'boost/fusion/algorithm/auxiliary.hpp' or 'boost/fusion/algorithm.hpp'. ]

[heading See also]

__boost_pfr__

[endsect]

[endsect]

[endsect]
Expand Down
6 changes: 6 additions & 0 deletions doc/fusion.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
[def __boost_func_forward__ [@http://www.boost.org/libs/functional/forward Boost.Functional/Forward Library]]
[def __boost_func_factory__ [@http://www.boost.org/libs/functional/factory Boost.Functional/Factory Library]]
[def __boost_func_hash__ [@http://www.boost.org/doc/html/hash.html Boost.ContainerHash Library]]
[def __boost_pfr__ [@http://www.boost.org/doc/html/boost_pfr.html Boost.PFR Library]]
[def __boost_pfr_lims__ [@http://www.boost.org/doc/html/boost_pfr/limitations_and_configuration.html Boost.PFR Limitations and Configuration]]
[def __boost_pfr_simple_aggregate__ [@http://www.boost.org/doc/html/boost_pfr/limitations_and_configuration.html SimpleAggregate]]
[def __std_pair_doc__ [@http://en.cppreference.com/w/cpp/utility/pair `std::pair`]]
[def __std_tuple_doc__ [@http://en.cppreference.com/w/cpp/utility/tuple `std::tuple`]]
[def __std_plus_doc__ [@http://en.cppreference.com/w/cpp/utility/functional/plus `std::plus`]]
Expand Down Expand Up @@ -131,6 +134,7 @@
[def __zip_view__ [link fusion.view.zip_view `zip_view`]]
[def __flatten_view__ [link fusion.view.flatten_view `flatten_view`]]
[def __identity_view__ [link fusion.view.identity_view `identity_view`]]
[def __pfr_view__ [link fusion.view.pfr_view `pfr_view`]]

[def __array__ [link fusion.adapted.array array]]
[def __std_pair__ [link fusion.adapted.std__pair `std::pair`]]
Expand Down Expand Up @@ -229,6 +233,8 @@
[def __result_of_copy__ [link fusion.algorithm.auxiliary.metafunctions.copy `result_of::copy`]]
[def __move__ [link fusion.algorithm.auxiliary.functions.move `move`]]
[def __result_of_move__ [link fusion.algorithm.auxiliary.metafunctions.move `result_of::move`]]
[def __pfr__ [link fusion.algorithm.auxiliary.functions.pfr `pfr`]]
[def __result_of_pfr__ [link fusion.algorithm.auxiliary.metafunctions.pfr `result_of::pfr`]]
[def __fold__ [link fusion.algorithm.iteration.functions.fold `fold`]]
[def __result_of_fold__ [link fusion.algorithm.iteration.metafunctions.fold `result_of::fold`]]
[def __reverse_fold__ [link fusion.algorithm.iteration.functions.reverse_fold `reverse_fold`]]
Expand Down
1 change: 1 addition & 0 deletions doc/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
<dt><span class="section"><a href="fusion/view/transform_view.html">transform_view</a></span></dt>
<dt><span class="section"><a href="fusion/view/reverse_view.html">reverse_view</a></span></dt>
<dt><span class="section"><a href="fusion/view/identity_view.html">identity_view</a></span></dt>
<dt><span class="section"><a href="fusion/view/pfr_view.html">pfr_view</a></span></dt>
<dt><span class="section"><a href="fusion/view/nview.html">nview</a></span></dt>
<dt><span class="section"><a href="fusion/view/repetitive_view.html">repetitive_view</a></span></dt>
<dt><span class="section"><a href="fusion/view/flatten_view.html">flatten_view</a></span></dt>
Expand Down
1 change: 1 addition & 0 deletions doc/organization.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ link against.
* transform_view
* zip_view
* identity_view
* pfr_view
* container
* deque
* list
Expand Down
4 changes: 4 additions & 0 deletions doc/sequence.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ For any Forward Sequence s the following invariants always hold:
* __reverse_view__
* __zip_view__
* __identity_view__
* __pfr_view__

[endsect]

Expand Down Expand Up @@ -203,6 +204,7 @@ are not defined in __forward_sequence__.
* __transform_view__ (where adapted sequence is a Bidirectional Sequence)
* __zip_view__ (where adapted sequences are models of Bidirectional Sequence)
* __identity_view__ (where adapted sequence is a Bidirectional Sequence)
* __pfr_view__ (where adapted type is a Bidirectional Sequence or a __boost_pfr_simple_aggregate__)

[endsect]

Expand Down Expand Up @@ -292,6 +294,7 @@ are not defined in __bidirectional_sequence__.
* __transform_view__ (where adapted sequence is a Random Access Sequence)
* __zip_view__ (where adapted sequences are models of Random Access Sequence)
* __identity_view__ (where adapted sequence is a Random Access Sequence)
* __pfr_view__ (where adapted type is a Random Access Sequence or a __boost_pfr_simple_aggregate__)

[endsect]

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

[endsect]

Expand Down
99 changes: 99 additions & 0 deletions doc/view.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -721,4 +721,103 @@ defined in the implemented models.

[endsect]

[section pfr_view]

[caution This view requires at least C++14! Pre C++14 compilers (C++11, C++03...) are not supported.]
[important Also, please read __boost_pfr_lims__ before using this view. Pay special attention to the SimpleAggregate concept.]

[heading Description]

`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__.

[heading Header]

#include <boost/fusion/view/pfr_view.hpp>
#include <boost/fusion/include/pfr_view.hpp>

[note This view won't defined by inclusion of 'boost/fusion/view.hpp'. ]

[heading Synopsis]

template <typename SequenceOrSimpleAggregate>
struct pfr_view;

[heading Template parameters]

[table
[[Parameter] [Description] [Default]]
[[`SequenceOrSimpleAggregate`] [A fusion __sequence__ or an user defined structure, satisfied 'SimpleAggregate' concept] []]
]

[heading Model of]

* A model of __forward_sequence__ if underlying type is a __forward_sequence__
else, __bidirectional_sequence__ if underlying type is a __bidirectional_sequence__
else, __random_access_sequence__ if underlying type is a __random_access_sequence__ or SimpleAggregate.
* __associative_sequence__ if underlying type implements the __associative_sequence__ model.

[variablelist Notation
[[`P`] [A `pfr_view` type]]
[[`p`, `p2`] [Instances of `pfr_view`]]
[[`a`] [An instance of `SimpleAggregate`]]
[[`s`] [An instance of `Sequence`]]
]

[heading Expression Semantics]

Semantics of an expression is defined only where it differs from, or is not
defined in __random_access_sequence__.

[table
[[Expression] [Semantics]]
[[`P(a)`] [Creates a `pfr_view` from simple aggregate `a`.]]
[[`P(s)`] [Creates a `pfr_view` from sequence `s`.]]
[[`P(p)`] [Copy constructs a `pfr_view` from another `pfr_view`, `p`.]]
[[`p = p2`] [Assigns to a `pfr_view`, `p`, from another `pfr_view`, `p2`.]]
]

[heading Example]

struct some_person { // SimpleAggregate
std::string name;
unsigned birth_year;
};

some_person val{"Edgar Allan Poe", 1809};
__pfr_view__<some_person> view(val);
std::cout << view << std::endl; // (Edgar Allan Poe 1809)

[heading Example]

struct empty { // SimpleAggregate
};

struct aggregate : empty { // not a SimpleAggregate
std::string name;
int age;
boost::uuids::uuid uuid;
};

aggregate val{"Edgar Allan Poe", 1809, {}};
__pfr_view__<aggregate> view(val); // non-portable behavior

[heading Example]

using some_person = __vector__< // not a SimpleAggregate, but Sequence
std::string
, unsigned
>;

some_person val("Edgar Allan Poe", 1809);
__pfr_view__<some_person> view(val);
std::cout << view << std::endl; // (Edgar Allan Poe 1809)

[heading See also]

__boost_pfr__

[endsect]

[endsect]
8 changes: 8 additions & 0 deletions include/boost/fusion/algorithm/auxiliary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,12 @@
#include <boost/fusion/algorithm/auxiliary/move.hpp>
#endif

// Unfortunately, there is no way to determine the compatibility of the pfr library with the current compiler.
// The "boost/fusion/algorithm/auxiliary/pfr.hpp" include has been commented out to ensure backward compatibility
// Please include it manually in your project

// #if !defined(BOOST_FUSION_NO_PFR)
// #include <boost/fusion/algorithm/auxiliary/pfr.hpp>
// #endif

#endif
Loading