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

make the result type of boost::pfr::get exactly match std::get #122

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions include/boost/pfr/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ constexpr auto get(T&, std::enable_if_t<!std::is_assignable<T, T>::value>* = nul

/// \overload get
template <std::size_t I, class T>
constexpr auto get(T&& val, std::enable_if_t< std::is_rvalue_reference<T&&>::value>* = nullptr) noexcept {
return std::move(detail::sequence_tuple::get<I>( detail::tie_as_tuple(val) ));
constexpr decltype(auto) get(T&& val, std::enable_if_t< std::is_rvalue_reference<T&&>::value>* = nullptr) noexcept {
return detail::sequence_tuple::get<I>( detail::tie_as_tuple(std::forward<T>(val)) );
}


Expand Down
12 changes: 11 additions & 1 deletion include/boost/pfr/detail/core17.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,20 @@ constexpr auto tie_as_tuple(T& val) noexcept {
!std::is_union<T>::value,
"====================> Boost.PFR: For safety reasons it is forbidden to reflect unions. See `Reflection of unions` section in the docs for more info."
);
typedef size_t_<boost::pfr::detail::fields_count<T>()> fields_count_tag;
typedef size_t_<boost::pfr::detail::fields_count< T >()> fields_count_tag;
return boost::pfr::detail::tie_as_tuple(val, fields_count_tag{});
}

template <class T>
constexpr auto tie_as_tuple(T&& val) noexcept {
static_assert(
!std::is_union<T>::value,
"====================> Boost.PFR: For safety reasons it is forbidden to reflect unions. See `Reflection of unions` section in the docs for more info."
);
typedef size_t_<boost::pfr::detail::fields_count< T >()> fields_count_tag;
return boost::pfr::detail::tie_as_tuple(std::forward<T>(val), fields_count_tag{});
}

template <class T, class F, std::size_t... I>
void for_each_field_dispatcher(T& t, F&& f, std::index_sequence<I...>) {
static_assert(
Expand Down
Loading