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

Merge remote-tracking branch 'upstream/develop' into INHERITED_DETECTOR

Conflicts:
	include/boost/pfr/detail/fields_count.hpp
This commit is contained in:
denzor200
2021-03-25 23:40:16 +04:00
2 changed files with 49 additions and 2 deletions

View File

@@ -55,9 +55,9 @@ using ubiq_lref_constructor = ubiq_lref_constructor_<>;
template<class T=void>
struct ubiq_rref_constructor_ {
std::size_t ignore;
template <class Type> /*constexpr*/ operator Type&&() const && noexcept { // Allows initialization of rvalue reference fields and move-only types
template <class Type> /*constexpr*/ operator Type() const && noexcept { // Allows initialization of rvalue reference fields and move-only types
static_assert_non_inherited<T, Type>();
return detail::unsafe_declval<Type&&>();
return detail::unsafe_declval<Type>();
};
};
using ubiq_rref_constructor = ubiq_rref_constructor_<>;
@@ -225,6 +225,7 @@ constexpr std::size_t fields_count() noexcept {
"====================> Boost.PFR: Attempt to get fields count on a reference. This is not allowed because that could hide an issue and different library users expect different behavior in that case."
);
#ifndef __cpp_guaranteed_copy_elision
static_assert(
std::is_copy_constructible<std::remove_all_extents_t<type>>::value || (
std::is_move_constructible<std::remove_all_extents_t<type>>::value
@@ -232,6 +233,7 @@ constexpr std::size_t fields_count() noexcept {
),
"====================> Boost.PFR: Type and each field in the type must be copy constructible (or move constructible and move assignable)."
);
#endif // #ifndef __cpp_guaranteed_copy_elision
static_assert(
!std::is_polymorphic<type>::value,

45
test/run/non_movable.cpp Normal file
View File

@@ -0,0 +1,45 @@
// Copyright (c) 2018-2021 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/pfr/tuple_size.hpp>
#include <boost/core/lightweight_test.hpp>
struct X {
X() = default;
X(X&&) = delete;
X(const X&) = delete;
X& operator=(X&&) = delete;
X& operator=(const X&) = delete;
};
struct S { X x0; X x1; int x2; X x3; };
int main() {
#ifdef __cpp_guaranteed_copy_elision
static_assert(boost::pfr::tuple_size_v<S> == 4, "");
struct S5_0 { int x0; int x1; int x2; int x3; X x4; };
static_assert(boost::pfr::tuple_size_v<S5_0> == 5, "");
struct S5_1 { X x0; int x1; int x2; int x3; int x4; };
static_assert(boost::pfr::tuple_size_v<S5_1> == 5, "");
struct S5_2 { int x0; int x1; X x2; int x3; int x4; };
static_assert(boost::pfr::tuple_size_v<S5_2> == 5, "");
struct S5_3 { int x0; int x1; X x2; int x3; X x4; };
static_assert(boost::pfr::tuple_size_v<S5_3> == 5, "");
struct S5_4 { X x0; X x1; X x2; X x3; X x4; };
static_assert(boost::pfr::tuple_size_v<S5_4> == 5, "");
struct S6 { X x0; X x1; X x2; X x3; X x4; X x5;};
static_assert(boost::pfr::tuple_size_v<S6> == 6, "");
#endif // #ifdef __cpp_guaranteed_copy_elision
return boost::report_errors();
}