2
0
mirror of https://github.com/boostorg/pfr.git synced 2026-01-27 19:12:13 +00:00

Compare commits

..

13 Commits

Author SHA1 Message Date
Denis Mikhailov
5f857d5503 Get rid of cast_to_layout_compatible (#154) 2024-02-17 16:47:03 +03:00
Antony Polukhin
9b90f2f6bb CI fixes (#161) 2024-02-16 08:41:05 +03:00
Antony Polukhin
8f3b819b1e Allow throwing exceptions from pfr::structure_to_tuple (fixes #155) … (#160)
…and fix some warnings
2024-02-15 10:10:46 +03:00
Antony Polukhin
4a973c5eb4 Update docs by not using is_aggregate (fixes #158) and by describing the get_name implementation (fixes #150) 2024-02-14 21:00:23 +03:00
Antony Polukhin
4c15f217f4 Merge pull request #152 from schaumb/get_name
Addressing the limitation of get_name
2024-01-28 11:52:57 +03:00
Antony Polukhin
e969c57be5 Docs update 2024-01-07 13:14:25 +03:00
Antony Polukhin
16d771f498 Update copyright years 2024-01-07 13:12:44 +03:00
bela
16a97bb1f5 Fix sample compilation 2023-11-30 11:41:58 +01:00
bela
8a0447b486 Fix missing ; 2023-11-30 11:31:06 +01:00
bela
b674d728be revert field_name and SimpleAggregate comment 2023-11-30 10:14:01 +01:00
bela
5b55480c65 Addressing the limitation of get_name 2023-11-30 10:09:09 +01:00
Denis Mikhailov
98789f610a Fix get_name on clang for MSVC (#149) 2023-11-29 09:32:30 +03:00
Denis Mikhailov
c695aa0b32 Improve diagnostic for attempt to use get_name with non-external (#146)
Co-authored-by: Antony Polukhin <antoshkka@gmail.com>
2023-11-26 11:52:17 +03:00
91 changed files with 310 additions and 182 deletions

View File

@@ -17,6 +17,9 @@ jobs:
fail-fast: false
matrix:
include:
- toolset: gcc-13
cxxstd: "03,11,14,17,20"
os: ubuntu-22.04
- toolset: gcc-12 # Do not remove! It is the only toolset that tests misc/strip_boost_namespace.sh
cxxstd: "03,11,14,17,2a"
os: ubuntu-22.04
@@ -41,10 +44,7 @@ jobs:
cxxflags: "cxxflags=--coverage -fsanitize=address,leak,undefined -fno-sanitize-recover=undefined"
linkflags: "linkflags=--coverage -lasan -lubsan"
gcov_tool: "gcov-9"
- toolset: clang-14
cxxstd: "03,11,14,17,20"
os: ubuntu-22.04
- toolset: clang-13
- toolset: clang-15
cxxstd: "03,11,14,17,20"
os: ubuntu-22.04
# - toolset: clang
@@ -145,6 +145,10 @@ jobs:
addrmd: 64
os: windows-2022
threads: "-j1"
- toolset: clang-win
cxxstd: "14,17,2a,latest"
addrmd: 32,64
os: windows-2022
runs-on: ${{matrix.os}}

View File

@@ -1,7 +1,7 @@
[library Boost.PFR
[quickbook 1.6]
[version 2.2]
[copyright 2016-2023 Antony Polukhin]
[copyright 2016-2024 Antony Polukhin]
[category Language Features Emulation]
[license
Distributed under the Boost Software License, Version 1.0.
@@ -161,7 +161,7 @@ void Write(Writer& writer, int value);
void Write(Writer& writer, std::string_view value);
template <typename T>
std::enable_if_t<std::is_aggregate_v<T>> Write(Writer& writer, const T& value) {
std::enable_if_t<boost::pfr::is_implicitly_reflectable_v<T>> Write(Writer& writer, const T& value) {
boost::pfr::for_each_field(
value, [&writer](const auto& field) { Write(writer, field); });
}
@@ -490,9 +490,7 @@ struct aggregate : empty { // not a SimpleAggregate
```
The library may work with aggregates that don't satisfy the requirements of `SimpleAggregate`, but the behavior tends to be non-portable.
Boost.PFRs extraction of field name works with a `SimpleAggregate` with non-internal linkage (with aggregats that could be used as `extern T t;`).
Do not use this functionality with anonymous structures, local structures
or a structure defined inside anonymous namespace as the behavior tends to be non-portable.
Boost.PFRs extraction of field name works with only `SimpleAggregate` types.
[h2 Configuration Macro]
@@ -553,6 +551,8 @@ parameters provided to `BOOST_PFR_CORE_NAME_PARSING` macro [*and] the initial ou
[section How it works]
[h2 Fields count detection and getting references to members]
Short description:
# at compile-time: use aggregate initialization to detect fields count in user-provided structure
@@ -579,6 +579,17 @@ Long description of some basics: [@https://youtu.be/UlNUNxLtBI0 Antony Polukhin:
Long description of some basics of C++14 with [link boost_pfr.limitations_and_configuration [*BOOST_PFR_USE_LOOPHOLE == 0]]: [@https://youtu.be/abdeAew3gmQ Antony Polukhin: C++14 Reflections Without Macros, Markup nor External Tooling].
Description of the [*BOOST_PFR_USE_LOOPHOLE == 1] technique by its inventor Alexandr Poltavsky [@http://alexpolt.github.io/type-loophole.html in his blog].
[h2 Field name retrieval]
# at compile-time:
* Get references to members of an object of type `T` in `constexpr` function
* Feed the reference from previous as a template parameter to a `constexpr` function with `template <auto member_ptr>`.
That function returns `__PRETTY_FUNCTION__` or some other vendor specific macro that prints the whole name of a function
along with the template arguments.
* The returned value from previous step contains the member name ([@https://godbolt.org/z/K4aWdcE9G godbolt example]). Do some
compiler specific parsing of the value and make a `std::string_view` that contains only the member name.
# at run-time: return the `std::string_view` with the member name.
[endsect]
[section Acknowledgements]

View File

@@ -1,4 +1,4 @@
// Copyright 2016-2023 Antony Polukhin
// Copyright 2016-2024 Antony Polukhin
// Distributed under the Boost Software License, Version 1.0.
// (See the accompanying file LICENSE_1_0.txt

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright 2016-2023 Antony Polukhin
// Copyright 2016-2024 Antony Polukhin
// Distributed under the Boost Software License, Version 1.0.
// (See the accompanying file LICENSE_1_0.txt
@@ -106,19 +106,23 @@ void test_examples() {
//]
}
// Disabled from testing since it's unportable
#if 0
// Disabling for MSVC as it gives a hard error on using local types:
//
// error C7631:
// 'boost::pfr::detail::do_not_use_PFR_with_local_types<test_examples::sample>':
// variable with internal linkage declared but not defined
#if BOOST_PFR_CORE_NAME_ENABLED && BOOST_PFR_USE_CPP17 && !defined(_MSC_VER)
{
//[pfr_quick_examples_get_name
// Get name of field by index
struct sample {
int f1;
long f2;
int f_int;
long f_long;
};
std::cout << boost::pfr::get_name<0, sample>()
<< boost::pfr::get_name<1, sample>(); // Outputs: f1 f2
<< boost::pfr::get_name<1, sample>(); // Outputs: f_int f_long
//]
}
#endif

View File

@@ -1,4 +1,4 @@
// Copyright 2016-2023 Antony Polukhin
// Copyright 2016-2024 Antony Polukhin
// Distributed under the Boost Software License, Version 1.0.
// (See the accompanying file LICENSE_1_0.txt

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
// Copyright (c) 2022 Denis Mikhailov
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
@@ -113,7 +113,7 @@
#ifndef BOOST_PFR_CORE_NAME_PARSING
# if defined(_MSC_VER)
# if defined(_MSC_VER) && !defined(__clang__)
# define BOOST_PFR_CORE_NAME_PARSING (sizeof("auto __cdecl boost::pfr::detail::name_of_field_impl<") - 1, sizeof(">(void) noexcept") - 1, backward("->"))
# elif defined(__clang__)
# define BOOST_PFR_CORE_NAME_PARSING (sizeof("auto boost::pfr::detail::name_of_field_impl() [MsvcWorkaround = ") - 1, sizeof("}]") - 1, backward("."))

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -140,7 +140,7 @@ using tuple_element_t = typename tuple_element<I, T>::type;
/// assert(get<0>(t) == 10);
/// \endcode
template <class T>
constexpr auto structure_to_tuple(const T& val) noexcept {
constexpr auto structure_to_tuple(const T& val) {
return detail::make_stdtuple_from_tietuple(
detail::tie_as_tuple(val),
detail::make_index_sequence< tuple_size_v<T> >()

View File

@@ -1,75 +0,0 @@
// Copyright (c) 2016-2023 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_PFR_DETAIL_CAST_TO_LAYOUT_COMPATIBLE_HPP
#define BOOST_PFR_DETAIL_CAST_TO_LAYOUT_COMPATIBLE_HPP
#pragma once
#include <boost/pfr/detail/config.hpp>
#include <type_traits>
#include <utility> // metaprogramming stuff
#include <boost/pfr/detail/rvalue_t.hpp>
namespace boost { namespace pfr { namespace detail {
template <class T, class U>
constexpr void static_assert_layout_compatible() noexcept {
static_assert(
std::alignment_of<T>::value == std::alignment_of<U>::value,
"====================> Boost.PFR: Alignment check failed, probably your structure has user-defined alignment for the whole structure or for some of the fields."
);
static_assert(sizeof(T) == sizeof(U), "====================> Boost.PFR: Size check failed, probably your structure has bitfields or user-defined alignment.");
}
/// @cond
#ifdef __GNUC__
#define MAY_ALIAS __attribute__((__may_alias__))
#else
#define MAY_ALIAS
#endif
/// @endcond
template <class To, class From>
MAY_ALIAS const To& cast_to_layout_compatible(const From& val) noexcept {
MAY_ALIAS const To* const t = reinterpret_cast<const To*>( std::addressof(val) );
detail::static_assert_layout_compatible<To, From>();
return *t;
}
template <class To, class From>
MAY_ALIAS const volatile To& cast_to_layout_compatible(const volatile From& val) noexcept {
MAY_ALIAS const volatile To* const t = reinterpret_cast<const volatile To*>( std::addressof(val) );
detail::static_assert_layout_compatible<To, From>();
return *t;
}
template <class To, class From>
MAY_ALIAS volatile To& cast_to_layout_compatible(volatile From& val) noexcept {
MAY_ALIAS volatile To* const t = reinterpret_cast<volatile To*>( std::addressof(val) );
detail::static_assert_layout_compatible<To, From>();
return *t;
}
template <class To, class From>
MAY_ALIAS To& cast_to_layout_compatible(From& val) noexcept {
MAY_ALIAS To* const t = reinterpret_cast<To*>( std::addressof(val) );
detail::static_assert_layout_compatible<To, From>();
return *t;
}
#ifdef BOOST_PFR_DETAIL_STRICT_RVALUE_TESTING
template <class To, class From>
To&& cast_to_layout_compatible(rvalue_t<From> val) noexcept = delete;
#endif
#undef MAY_ALIAS
}}} // namespace boost::pfr::detail
#endif // BOOST_PFR_DETAIL_CAST_TO_LAYOUT_COMPATIBLE_HPP

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
// Copyright (c) 2022 Denis Mikhailov
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,5 +1,5 @@
// Copyright (c) 2017-2018 Alexandr Poltavsky, Antony Polukhin.
// Copyright (c) 2019-2023 Antony Polukhin.
// Copyright (c) 2019-2024 Antony Polukhin.
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -27,7 +27,6 @@
#include <type_traits>
#include <utility>
#include <boost/pfr/detail/cast_to_layout_compatible.hpp> // still needed for enums
#include <boost/pfr/detail/offset_based_getter.hpp>
#include <boost/pfr/detail/fields_count.hpp>
#include <boost/pfr/detail/make_flat_tuple_of_references.hpp>

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
// Copyright (c) 2023 Denis Mikhailov
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying

View File

@@ -167,7 +167,7 @@ consteval auto name_of_field() noexcept {
&& std::string_view{
detail::name_of_field_impl<
core_name_skip, detail::make_clang_wrapper(std::addressof(
fake_object<core_name_skip>.size_at_begin
detail::fake_object<core_name_skip>().size_at_begin
))
>().data()
} == "size_at_begin",
@@ -187,7 +187,7 @@ consteval auto name_of_field() noexcept {
template <class T, std::size_t I>
inline constexpr auto stored_name_of_field = detail::name_of_field<T,
detail::make_clang_wrapper(std::addressof(detail::sequence_tuple::get<I>(
detail::tie_as_tuple(detail::fake_object<T>)
detail::tie_as_tuple(detail::fake_object<T>())
)))
>();

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -14,12 +14,44 @@
#include <boost/pfr/detail/config.hpp>
#ifdef __clang__
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wundefined-internal"
# pragma clang diagnostic ignored "-Wundefined-var-template"
#elif defined(__GNUC__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wundefined-var-template"
#endif
namespace boost { namespace pfr { namespace detail {
// This class has external linkage while T has not sure.
template <class T>
extern const T fake_object;
struct wrapper {
const T value;
};
// This variable servers as a link-time assert.
// If linker requires it, then `fake_object()` is used at runtime.
template <class T>
extern const wrapper<T> do_not_use_PFR_with_local_types;
// For returning non default constructible types, it's exclusively used in member name retrieval.
//
// Neither std::declval nor boost::pfr::detail::unsafe_declval are usable there.
// This takes advantage of C++20 features, while boost::pfr::detail::unsafe_declval works
// with the former standards.
template <class T>
constexpr const T& fake_object() noexcept {
return do_not_use_PFR_with_local_types<T>.value;
}
}}} // namespace boost::pfr::detail
#ifdef __clang__
# pragma clang diagnostic push
#elif defined(__GNUC__)
# pragma GCC diagnostic pop
#endif
#endif // BOOST_PFR_DETAIL_FAKE_OBJECT_HPP

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,5 +1,5 @@
// Copyright (c) 2018 Sergei Fedorov
// Copyright (c) 2019-2023 Antony Polukhin
// Copyright (c) 2019-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,5 +1,5 @@
// Copyright (c) 2017-2018 Chris Beck
// Copyright (c) 2019-2023 Antony Polukhin
// Copyright (c) 2019-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -17,7 +17,7 @@
namespace boost { namespace pfr { namespace detail {
template <class T, std::size_t... I>
constexpr auto make_stdtuple_from_tietuple(const T& t, std::index_sequence<I...>) noexcept {
constexpr auto make_stdtuple_from_tietuple(const T& t, std::index_sequence<I...>) {
return std::make_tuple(
boost::pfr::detail::sequence_tuple::get<I>(t)...
);

View File

@@ -1,5 +1,5 @@
// Copyright (c) 2018 Adam Butcher, Antony Polukhin
// Copyright (c) 2019-2023 Antony Polukhin
// Copyright (c) 2019-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2019-2023 Antony Polukhin.
// Copyright (c) 2019-2024 Antony Polukhin.
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,6 +1,6 @@
<!DOCTYPE html>
<!--
Copyright (c) 2014-2023 Antony Polukhin
Copyright (c) 2014-2024 Antony Polukhin
antoshkka at gmail dot com
Distributed under the Boost Software License,
@@ -31,7 +31,7 @@ boost-no-inspect
<a href="../../doc/html/boost_pfr.html">../../doc/html/boost_pfr.html</a>
</p>
<p>
&copy; 2014-2023 Antony Polukhin
&copy; 2014-2024 Antony Polukhin
</p>
</body>
</html>

View File

@@ -1,6 +1,6 @@
#!/usr/bin/python
# Copyright (c) 2016-2023 Antony Polukhin
# Copyright (c) 2016-2024 Antony Polukhin
# Copyright (c) 2023 Denis Mikhailov
#
# Distributed under the Boost Software License, Version 1.0. (See accompanying
@@ -15,7 +15,7 @@ import string
ascii_letters = string.ascii_letters.replace("o", "").replace("O", "").replace("i", "").replace("I", "").replace("T", "")
WORKAROUND_CAST_EXPRESSIONS_LIMIT_PER_LINE = 3
PROLOGUE = """// Copyright (c) 2016-2023 Antony Polukhin
PROLOGUE = """// Copyright (c) 2016-2024 Antony Polukhin
// Copyright (c) 2023 Denis Mikhailov
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
# Copyright (C) 2016-2023 Antony Polukhin.
# Copyright (C) 2016-2024 Antony Polukhin.
#
# Use, modification and distribution is subject to the Boost Software License,
# Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2018-2023 Antony Polukhin
// Copyright (c) 2018-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2018-2023 Antony Polukhin
// Copyright (c) 2018-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2018-2023 Antony Polukhin
// Copyright (c) 2018-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2018-2023 Antony Polukhin
// Copyright (c) 2018-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2018-2023 Antony Polukhin
// Copyright (c) 2018-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2020-2023 Antony Polukhin
// Copyright (c) 2020-2024 Antony Polukhin
// Copyright (c) 2020 Richard Hodges
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2018-2023 Antony Polukhin
// Copyright (c) 2018-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2018-2023 Antony Polukhin
// Copyright (c) 2018-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2020-2023 Antony Polukhin
// Copyright (c) 2020-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2018-2023 Antony Polukhin
// Copyright (c) 2018-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2020-2023 Antony Polukhin
// Copyright (c) 2020-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,5 +1,5 @@
// Copyright (c) 2019 Ilya Kiselev
// Copyright (c) 2019-2023 Antony Polukhin
// Copyright (c) 2019-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,5 +1,5 @@
// Copyright (c) 2018 Adam Butcher, Antony Polukhin
// Copyright (c) 2019-2023 Antony Polukhin
// Copyright (c) 2019-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2018-2023 Antony Polukhin
// Copyright (c) 2018-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2018-2023 Antony Polukhin
// Copyright (c) 2018-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2020-2023 Antony Polukhin
// Copyright (c) 2020-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2020-2023 Antony Polukhin
// Copyright (c) 2020-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2020-2023 Antony Polukhin
// Copyright (c) 2020-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2018-2023 Antony Polukhin
// Copyright (c) 2018-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2018-2023 Antony Polukhin
// Copyright (c) 2018-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2018-2023 Antony Polukhin
// Copyright (c) 2018-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2018-2023 Antony Polukhin
// Copyright (c) 2018-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2018-2023 Antony Polukhin
// Copyright (c) 2018-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2018-2023 Antony Polukhin
// Copyright (c) 2018-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2018-2023 Antony Polukhin
// Copyright (c) 2018-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2020-2023 Antony Polukhin
// Copyright (c) 2020-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -0,0 +1,91 @@
// Copyright (c) 2020-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <boost/core/lightweight_test.hpp>
#include <boost/pfr/core.hpp>
namespace some {
struct struct1{ int i; };
struct struct2{ int i; short s; };
}
void test_single_field() {
{
some::struct1 s{1};
auto s_tuple = boost::pfr::structure_to_tuple(s);
BOOST_TEST_EQ(std::get<0>(s_tuple), 1);
static_assert(std::is_same<
std::tuple<int>, decltype(s_tuple)
>::value, "");
}
{
const some::struct1 s{1};
auto s_tuple = boost::pfr::structure_to_tuple(s);
BOOST_TEST_EQ(std::get<0>(s_tuple), 1);
static_assert(std::is_same<
std::tuple<int>, decltype(s_tuple)
>::value, "");
}
}
void test_two_fields() {
{
some::struct2 s{1, 2};
auto s_tuple = boost::pfr::structure_to_tuple(s);
BOOST_TEST_EQ(std::get<0>(s_tuple), 1);
BOOST_TEST_EQ(std::get<1>(s_tuple), 2);
static_assert(std::is_same<
std::tuple<int, short>, decltype(s_tuple)
>::value, "");
}
{
const some::struct2 s{1, 2};
auto s_tuple = boost::pfr::structure_to_tuple(s);
BOOST_TEST_EQ(std::get<0>(s_tuple), 1);
BOOST_TEST_EQ(std::get<1>(s_tuple), 2);
static_assert(std::is_same<
std::tuple<int, short>, decltype(s_tuple)
>::value, "");
}
}
// Test from https://github.com/boostorg/pfr/issues/155
void test_throwing_field() {
#if BOOST_PFR_USE_CPP17 || BOOST_PFR_USE_LOOPHOLE
struct throw_on_copy {
throw_on_copy() = default;
throw_on_copy(const throw_on_copy&){ throw 42; }
};
struct throwing_struct {
int i;
throw_on_copy s;
};
throwing_struct s {10, {}};
try {
std::tuple<int, throw_on_copy> t = boost::pfr::structure_to_tuple(s);
BOOST_TEST(false); // the above line should throw
(void)t;
} catch (...) {}
#endif
}
int main() {
test_single_field();
test_two_fields();
test_throwing_field();
return boost::report_errors();
}

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2019-2023 Antony Polukhin.
// Copyright (c) 2019-2024 Antony Polukhin.
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2019-2023 Antony Polukhin
// Copyright (c) 2019-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2019-2023 Antony Polukhin
// Copyright (c) 2019-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2020-2023 Antony Polukhin
// Copyright (c) 2020-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2020-2023 Antony Polukhin
// Copyright (c) 2020-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Antony Polukhin
// Copyright (c) 2016-2024 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -29,7 +29,7 @@ using namespace boost::pfr;
template <class T, std::size_t I>
inline constexpr auto no_check_stored_name_of_field = detail::name_of_field_impl<T,
detail::make_clang_wrapper(std::addressof(detail::sequence_tuple::get<I>(
detail::tie_as_tuple(detail::fake_object<T>)
detail::tie_as_tuple(detail::fake_object<T>())
)))
>();

View File

@@ -34,6 +34,19 @@ struct A {
struct empty {};
namespace {
struct inside_unnamed_ns {
int hidden;
};
}
struct {
int unnamed_first;
float unnamed_second;
} unnamed{};
typedef typename std::remove_reference<decltype(unnamed)>::type unnamed_t;
void test_get_name_by_id() {
BOOST_TEST_EQ( ((boost::pfr::get_name<0, Aggregate>())), "member1");
BOOST_TEST_EQ( ((boost::pfr::get_name<1, Aggregate>())), "this_is_a_name");
@@ -44,6 +57,26 @@ void test_get_name_by_id() {
BOOST_TEST_EQ( ((boost::pfr::get_name<1, A>())), "second");
}
void test_get_name_by_id_without_linkage() {
// Disabling for MSVC as it gives a hard error on using local types:
///
// error C7631:
// 'boost::pfr::detail::do_not_use_PFR_with_local_types<testing::unnamed_t>':
// variable with internal linkage declared but not defined
#ifndef _MSC_VER
struct function_local {
int val;
};
BOOST_TEST_EQ( ((boost::pfr::get_name<0, unnamed_t>())), "unnamed_first");
BOOST_TEST_EQ( ((boost::pfr::get_name<1, unnamed_t>())), "unnamed_second");
BOOST_TEST_EQ( ((boost::pfr::get_name<0, inside_unnamed_ns>())), "hidden");
BOOST_TEST_EQ( ((boost::pfr::get_name<0, function_local>())), "val");
#endif
}
void test_get_name_by_type() {
// FIXME: implement this
// using char_ref = std::reference_wrapper<char>;
@@ -52,6 +85,13 @@ void test_get_name_by_type() {
// BOOST_TEST_EQ( ((boost::pfr::get_name<char_ref, Aggregate>())), "c");
}
void test_get_name_by_type_without_linkage() {
// FIXME: implement this
// BOOST_TEST_EQ( ((boost::pfr::get_name<int, unnamed_t>())), "unnamed_first");
// BOOST_TEST_EQ( ((boost::pfr::get_name<float, unnamed_t>())), "unnamed_second");
// BOOST_TEST_EQ( ((boost::pfr::get_name<int, inside_unnamed_ns>())), "hidden");
}
void test_names_as_array() {
const auto expected = std::array<std::string_view, 4>{
"member1",
@@ -66,6 +106,25 @@ void test_names_as_array() {
}
}
void test_names_as_array_without_linkage() {
// Disabling for MSVC as it gives a hard error on using local types:
///
// error C7631:
// 'boost::pfr::detail::do_not_use_PFR_with_local_types<testing::unnamed_t>':
// variable with internal linkage declared but not defined
#ifndef _MSC_VER
const auto expected = std::array<std::string_view, 2>{
"unnamed_first",
"unnamed_second"
};
const auto value = boost::pfr::names_as_array<unnamed_t>();
BOOST_TEST_EQ(expected.size(), value.size());
for (std::size_t i=0;i<expected.size();++i) {
BOOST_TEST_EQ(value[i], expected[i]);
}
#endif
}
void test_names_as_array_for_empty() {
const auto value = boost::pfr::names_as_array<empty>();
BOOST_TEST_EQ(value.size(), 0);
@@ -76,8 +135,11 @@ void test_names_as_array_for_empty() {
int main() {
testing::test_get_name_by_id();
testing::test_get_name_by_id_without_linkage();
testing::test_get_name_by_type();
testing::test_get_name_by_type_without_linkage();
testing::test_names_as_array();
testing::test_names_as_array_without_linkage();
testing::test_names_as_array_for_empty();
return boost::report_errors();