Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boost PFR as implicit fallback #266

Open
wants to merge 24 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
81ff974
[pfr_implicit_explicit] Docs [skip ci]
denzor200 Dec 24, 2022
45d9be9
[pfr_implicit_explicit] Add important notes for the docs [skip ci]
denzor200 Dec 30, 2022
d002a70
[pfr_implicit_explicit] Add Boost PFR implicit and explicit adapters
denzor200 Dec 30, 2022
85be88d
[pfr_implicit_explicit] Add regular test for Boost PFR adapter
denzor200 Dec 30, 2022
e26c017
[pfr_implicit_explicit] Add test for Boost PFR explicit adapter && fi…
denzor200 Dec 30, 2022
e5b2344
[pfr_implicit_explicit] Just more tests
denzor200 Dec 30, 2022
bc1415e
[pfr_implicit_explicit] Add pfr dependency
denzor200 Dec 30, 2022
cd54084
[pfr_implicit_explicit] Fix warning static_assert with no message
denzor200 Dec 30, 2022
aed0503
[pfr_implicit_explicit] Force pfr implicit reflection in cxx14 mode
denzor200 Jan 11, 2023
a7bb2c7
[pfr_implicit_explicit] Update copyright years
denzor200 Jan 15, 2023
40dfa11
[pfr_implicit_explicit] Fix for 'config.hpp' && Comment for 'adapted.…
denzor200 Jan 15, 2023
e016b09
[pfr_implicit_explicit] First successful step for regression tests
denzor200 Jan 22, 2023
7307754
[pfr_implicit_explicit] Regression tests for 'sequence' group
denzor200 Jan 22, 2023
ff05040
[pfr_implicit_explicit] Rest of regression tests
denzor200 Jan 22, 2023
aff77c4
[pfr_implicit_explicit] Fix for old compilers building
denzor200 Jan 23, 2023
01defe1
[pfr_implicit_explicit] Fix for C++11 build
denzor200 Jan 24, 2023
4686805
[pfr_implicit_explicit] Fix for clang-3.5 build
denzor200 Jan 26, 2023
4906f32
[pfr_implicit_explicit] One with_or_without_fallback.hpp
denzor200 Jan 27, 2023
403ae44
[pfr_implicit_explicit] Force macroes documented as acceptable in old…
denzor200 Jan 27, 2023
c4547ce
[pfr_implicit_explicit] Diagnostics improvement
denzor200 Jan 27, 2023
073e9b2
[pfr_implicit_explicit] Tests improved a lot
denzor200 Jan 28, 2023
62545d4
[pfr_implicit_explicit] Fix typename cannot be used outside a templat…
denzor200 Jan 28, 2023
8f0ab4b
[pfr_implicit_explicit] Fix invalid application of 'sizeof'
denzor200 Jan 28, 2023
aff0c59
[pfr_implicit_explicit] Lot of fixes
denzor200 Jan 28, 2023
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 .github/workflows/ci.yml
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ jobs:
git submodule init libs/utility
git submodule init libs/describe
git submodule init libs/mp11
git submodule init libs/pfr
git submodule init libs/headers tools/boost_install tools/build
git submodule update
rm -rf libs/fusion
Expand Down Expand Up @@ -456,6 +457,7 @@ jobs:
git submodule init libs/utility
git submodule init libs/describe
git submodule init libs/mp11
git submodule init libs/pfr
git submodule init libs/headers tools/boost_install tools/build
git submodule update
rm -rf libs/fusion
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ target_link_libraries(boost_fusion
Boost::functional
Boost::describe
Boost::mp11
Boost::pfr
)
1 change: 1 addition & 0 deletions appveyor.yml
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ install:
- git submodule init libs/utility
- git submodule init libs/describe
- git submodule init libs/mp11
- git submodule init libs/pfr

- git submodule init libs/headers tools/boost_install tools/build
- git submodule update
Expand Down
299 changes: 299 additions & 0 deletions doc/adapted.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
denzor200 marked this conversation as resolved.
Show resolved Hide resolved

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 All @@ -23,6 +24,20 @@ various data structures, non-intrusively, as full fledged Fusion sequences.
#include <boost/fusion/adapted.hpp>
#include <boost/fusion/include/adapted.hpp>

[caution
You may get compiler errors when your environment doesn't support __boost_pfr_library__ and this
lack of support doesn't detect automatically. If this happens, define macro
`BOOST_FUSION_PFR_ENABLED` as 0 to suppress the inclusion
of __boost_pfr_implicit_adapter__ and __boost_pfr_explicit_adapter__ in this module.
]

[caution
You may get compiler errors when your program utilizes __tag_of__, __is_sequence__ or
__is_view__ with an incomplete type. If this happens, define macro
`BOOST_FUSION_PFR_ENABLE_IMPLICIT_REFLECTION` as 0 to suppress the inclusion
of __boost_pfr_implicit_adapter__ in this module.
]

[section:array Array]

This module provides adapters for arrays. Including the module
Expand Down Expand Up @@ -208,6 +223,84 @@ __boost_tuple_library__

[endsect]

[section:boost_pfr_implicit boost::pfr]

[caution This module requires at least C++14! Pre C++14 compilers (C++11, C++03...) are not supported.]

This module provides reflection from `boost::pfr` as fallback when another reflection not found for a passed type,
the module can be used when you want to pass an user defined structure into Fusion, the module more preferable to use than
__adapt_struct__ macro, because the module does not require boilerplate code from an user defined structure.
Note that the module expects a passed type satisfies __simple_aggregate__.

[heading Header]

#include <boost/fusion/adapted/boost_pfr.hpp>
#include <boost/fusion/include/boost_pfr.hpp>

[heading Model of]

* __random_access_sequence__

[heading Example]

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

some_person val{"Edgar Allan Poe", 1809};
std::cout << *__begin__(val) << '\n';
std::cout << *__next__(__begin__(val)) << '\n';

[note See __force_pfr_nonreflectable__ or __force_pfr_nonreflectable_tpl__ if your type falsely determines as "reflectable via PFR" and you need to workaround it.]
[note Define macro `BOOST_FUSION_PFR_ENABLE_IMPLICIT_REFLECTION` as 0 if you hit by lots of non-effective choices made by implicit reflection(or if you even hit by compiler errors, when your program utilizes __tag_of__, __is_sequence__ or __is_view__ with an incomplete type) and you need to change for explicit reflection. See __boost_pfr_explicit__ for more details.]
[note Define macro `BOOST_FUSION_PFR_ENABLED` as 0 if you get compiler errors when your program includes __adapted__ and you need to suppress the inclusion of __boost_pfr_implicit__ in __adapted__ module.]
[note This module can't adapt a passed type as fully conforming __mpl__ sequences.]

[heading See also]

__boost_pfr_library__

[endsect]

[section:boost_pfr_explicit boost::pfr (explicit)]

[caution This module requires at least C++14! Pre C++14 compilers (C++11, C++03...) are not supported.]

This module provides reflection from `boost::pfr`. If you want to use the module, you should specify
all reflectable types manually using one of the macro below. The module can't decide to use PFR for a passed type
automatically, unlike __boost_pfr_implicit__.

[heading Header]

#include <boost/fusion/adapted/boost_pfr_explicit.hpp>
#include <boost/fusion/include/boost_pfr_explicit.hpp>

[heading Model of]

* __random_access_sequence__

[heading Example]

struct some_person { // SimpleAggregate
std::string name;
unsigned birth_year = 0;
};
__force_pfr_reflectable__(some_person)

some_person val{"Edgar Allan Poe", 1809};
std::cout << *__begin__(val) << '\n';
std::cout << *__next__(__begin__(val)) << '\n';

[note Define macro `BOOST_FUSION_PFR_ENABLED` as 0 if you get compiler errors when your program includes __adapted__ and you need to suppress the inclusion of __boost_pfr_explicit__ in __adapted__ module.]
[note This module can't adapt a passed type as fully conforming __mpl__ sequences.]

[heading See also]

__boost_pfr_library__, __force_pfr_reflectable__, __force_pfr_nonreflectable__, __force_pfr_reflectable_tpl__, __force_pfr_nonreflectable_tpl__

[endsect]

[section:adapt_struct BOOST_FUSION_ADAPT_STRUCT]

[heading Description]
Expand Down Expand Up @@ -276,6 +369,10 @@ namespace qualified name of the struct to be adapted.
(auto, age)
)

[heading See also]

__boost_pfr_implicit__ (might be a better alternative to using this macro)

[endsect]

[section:adapt_tpl_struct BOOST_FUSION_ADAPT_TPL_STRUCT]
Expand Down Expand Up @@ -357,6 +454,10 @@ namespace qualified name of the struct to be adapted.
age,
employment_timestamp)

[heading See also]

__boost_pfr_implicit__ (might be a better alternative to using this macro)

[endsect]

[section:adapt_struct_named BOOST_FUSION_ADAPT_STRUCT_NAMED]
Expand Down Expand Up @@ -1500,4 +1601,202 @@ defined in __random_access_sequence__ and __associative_sequence__.

[endsect]

[section:force_pfr_reflectable BOOST_FUSION_FORCE_PFR_REFLECTABLE]

[caution This macro requires at least C++14! Pre C++14 compilers (C++11, C++03...) are not supported.]

[heading Description]
BOOST_FUSION_FORCE_PFR_REFLECTABLE is a macro that can be used to specify an
arbitrary struct as a pfr-reflectable type for Fusion, and thus to make the struct
possible to be a model of __random_access_sequence__.
The macro intended to be used with __boost_pfr_explicit_adapter__, when you don't need __boost_pfr_implicit_adapter__.

[heading Synopsis]
BOOST_FUSION_FORCE_PFR_REFLECTABLE(aggregate_name)

[heading Semantics]

The above macro specializes `boost::pfr::is_reflectable` for `aggregate_name` with `boost::pfr::boost_fusion_tag` as positive.

The macro should be used at global scope, and `aggregate_name` should be the fully
namespace qualified name of the struct satisfying __simple_aggregate__ to be specifyed.

[heading Header]

#include <boost/fusion/adapted/boost_pfr.hpp>
#include <boost/fusion/include/boost_pfr.hpp>
#include <boost/fusion/adapted/boost_pfr_explicit.hpp>
#include <boost/fusion/include/boost_pfr_explicit.hpp>

[heading Example: BOOST_FUSION_FORCE_PFR_REFLECTABLE ]
namespace demo
{
struct employee
{
std::string name;
int age;
};
}

// demo::employee is now a pfr-reflectable type for Fusion
BOOST_FUSION_FORCE_PFR_REFLECTABLE(demo::employee)

[note This macro affects only Fusion, see PFR docs if you want to know how to specify type as pfr-reflectable everywhere.]

[heading See also]

__boost_pfr_library__

[endsect]

[section:force_pfr_nonreflectable BOOST_FUSION_FORCE_PFR_NONREFLECTABLE]

[caution This macro requires at least C++14! Pre C++14 compilers (C++11, C++03...) are not supported.]

[heading Description]
BOOST_FUSION_FORCE_PFR_NONREFLECTABLE is a macro that can be used to declare a Fusion-side prohibition
for an arbitrary struct to be pfr-reflectable, and thus to make the struct
impossible to be a model of fusion sequence.
The macro intended to be used with __boost_pfr_implicit_adapter__, when you need to workaround erroneous
decision that defines a type as pfr-reflectable.

[heading Synopsis]
BOOST_FUSION_FORCE_PFR_NONREFLECTABLE(type_name)

[heading Semantics]

The above macro specializes `boost::pfr::is_reflectable` for `type_name` with `boost::pfr::boost_fusion_tag` as negative.

The macro should be used at global scope, and `type_name` should be the fully
namespace qualified name of any type that you wish to be specifyed.

[heading Header]

#include <boost/fusion/adapted/boost_pfr.hpp>
#include <boost/fusion/include/boost_pfr.hpp>
#include <boost/fusion/adapted/boost_pfr_explicit.hpp>
#include <boost/fusion/include/boost_pfr_explicit.hpp>

[heading Example: BOOST_FUSION_FORCE_PFR_NONREFLECTABLE ]
namespace demo
{
struct employee
{
std::string name;
int age;
};
}

// demo::employee is now forbidden to be a pfr-reflectable type for Fusion
BOOST_FUSION_FORCE_PFR_NONREFLECTABLE(demo::employee)

[note This macro affects only Fusion, see PFR docs if you want to know how to forbid pfr-reflection for a type everywhere.]

[heading See also]

__boost_pfr_library__

[endsect]

[section:force_pfr_reflectable_tpl BOOST_FUSION_FORCE_PFR_REFLECTABLE_TPL]

[caution This macro requires at least C++14! Pre C++14 compilers (C++11, C++03...) are not supported.]

[heading Description]
BOOST_FUSION_FORCE_PFR_REFLECTABLE_TPL is a macro that can be used to specify an
arbitrary template struct as a pfr-reflectable type for Fusion, and thus to make the struct
possible to be a model of __random_access_sequence__.
The macro intended to be used with __boost_pfr_explicit_adapter__, when you don't need __boost_pfr_implicit_adapter__.

[heading Synopsis]
BOOST_FUSION_FORCE_PFR_REFLECTABLE_TPL(aggregate_name)

[heading Semantics]

The above macro specializes `boost::pfr::is_reflectable` for `aggregate_name` with `boost::pfr::boost_fusion_tag` as positive.

The macro should be used at global scope, and `aggregate_name` should be the fully
namespace qualified name of the template struct satisfying __simple_aggregate__ to be specifyed.

[heading Header]

#include <boost/fusion/adapted/boost_pfr.hpp>
#include <boost/fusion/include/boost_pfr.hpp>
#include <boost/fusion/adapted/boost_pfr_explicit.hpp>
#include <boost/fusion/include/boost_pfr_explicit.hpp>

[heading Example: BOOST_FUSION_FORCE_PFR_REFLECTABLE_TPL ]
namespace demo
{
template<typename Name, typename Age>
struct employee
{
Name name;
Age age;
int employment_timestamp;
};
}

// Any instantiated demo::employee is now a pfr-reflectable type for Fusion
BOOST_FUSION_FORCE_PFR_REFLECTABLE_TPL(demo::employee)

[note This macro affects only Fusion, see PFR docs if you want to know how to specify type as pfr-reflectable everywhere.]

[heading See also]

__boost_pfr_library__

[endsect]

[section:force_pfr_nonreflectable_tpl BOOST_FUSION_FORCE_PFR_NONREFLECTABLE_TPL]

[caution This macro requires at least C++14! Pre C++14 compilers (C++11, C++03...) are not supported.]

[heading Description]
BOOST_FUSION_FORCE_PFR_NONREFLECTABLE_TPL is a macro that can be used to declare a Fusion-side prohibition
for an arbitrary template struct to be pfr-reflectable, and thus to make the struct
impossible to be a model of fusion sequence.
The macro intended to be used with __boost_pfr_implicit_adapter__, when you need to workaround erroneous
decision that defines a type as pfr-reflectable.

[heading Synopsis]
BOOST_FUSION_FORCE_PFR_NONREFLECTABLE_TPL(type_name)

[heading Semantics]

The above macro specializes `boost::pfr::is_reflectable` for `type_name` with `boost::pfr::boost_fusion_tag` as negative.

The macro should be used at global scope, and `type_name` should be the fully
namespace qualified name of any type that you wish to be specifyed.

[heading Header]

#include <boost/fusion/adapted/boost_pfr.hpp>
#include <boost/fusion/include/boost_pfr.hpp>
#include <boost/fusion/adapted/boost_pfr_explicit.hpp>
#include <boost/fusion/include/boost_pfr_explicit.hpp>

[heading Example: BOOST_FUSION_FORCE_PFR_NONREFLECTABLE_TPL ]
namespace demo
{
template<typename Name, typename Age>
struct employee
{
Name name;
Age age;
int employment_timestamp;
};
}

// Any instantiated demo::employee is now forbidden to be a pfr-reflectable type for Fusion
BOOST_FUSION_FORCE_PFR_NONREFLECTABLE_TPL(demo::employee)

[note This macro affects only Fusion, see PFR docs if you want to know how to forbid pfr-reflection for a type everywhere.]

[heading See also]

__boost_pfr_library__

[endsect]

[endsect]
Loading