mirror of
https://github.com/boostorg/pfr.git
synced 2026-01-19 04:22:13 +00:00
Return std::array<std::string_view, 0> type for boost::pfr::names_as_array(empty_struct{}) (fixes #195)
This commit is contained in:
@@ -83,8 +83,7 @@ auto
|
|||||||
names_as_array() noexcept {
|
names_as_array() noexcept {
|
||||||
return detail::make_stdarray_from_tietuple(
|
return detail::make_stdarray_from_tietuple(
|
||||||
detail::tie_as_names_tuple<T>(),
|
detail::tie_as_names_tuple<T>(),
|
||||||
detail::make_index_sequence< tuple_size_v<T> >(),
|
detail::make_index_sequence< tuple_size_v<T> >()
|
||||||
1L
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,29 +12,18 @@
|
|||||||
#include <boost/pfr/detail/sequence_tuple.hpp>
|
#include <boost/pfr/detail/sequence_tuple.hpp>
|
||||||
|
|
||||||
#if !defined(BOOST_PFR_INTERFACE_UNIT)
|
#if !defined(BOOST_PFR_INTERFACE_UNIT)
|
||||||
#include <utility> // metaprogramming stuff
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <type_traits> // for std::common_type_t
|
#include <string_view>
|
||||||
#include <cstddef>
|
#include <utility> // metaprogramming stuff
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace boost { namespace pfr { namespace detail {
|
namespace boost { namespace pfr { namespace detail {
|
||||||
|
|
||||||
template <class... Types>
|
|
||||||
constexpr auto make_stdarray(const Types&... t) noexcept {
|
|
||||||
return std::array<std::common_type_t<Types...>, sizeof...(Types)>{t...};
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class T, std::size_t... I>
|
template <class T, std::size_t... I>
|
||||||
constexpr auto make_stdarray_from_tietuple(const T& t, std::index_sequence<I...>, int) noexcept {
|
constexpr auto make_stdarray_from_tietuple(const T& t, std::index_sequence<I...>) noexcept {
|
||||||
return detail::make_stdarray(
|
return std::array<std::string_view, sizeof...(I)>{
|
||||||
boost::pfr::detail::sequence_tuple::get<I>(t)...
|
boost::pfr::detail::sequence_tuple::get<I>(t)...
|
||||||
);
|
};
|
||||||
}
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
constexpr auto make_stdarray_from_tietuple(const T&, std::index_sequence<>, long) noexcept {
|
|
||||||
return std::array<std::nullptr_t, 0>{};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}}} // namespace boost::pfr::detail
|
}}} // namespace boost::pfr::detail
|
||||||
|
|||||||
@@ -131,6 +131,13 @@ void test_names_as_array_for_empty() {
|
|||||||
BOOST_TEST_EQ(value.empty(), true);
|
BOOST_TEST_EQ(value.empty(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_names_as_array_iteration_for_empty() {
|
||||||
|
const auto names = boost::pfr::names_as_array<empty>();
|
||||||
|
for (std::string_view name : names) {
|
||||||
|
BOOST_ERROR("`names` must be empty");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace testing
|
} // namespace testing
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
@@ -141,6 +148,7 @@ int main() {
|
|||||||
testing::test_names_as_array();
|
testing::test_names_as_array();
|
||||||
testing::test_names_as_array_without_linkage();
|
testing::test_names_as_array_without_linkage();
|
||||||
testing::test_names_as_array_for_empty();
|
testing::test_names_as_array_for_empty();
|
||||||
|
testing::test_names_as_array_iteration_for_empty();
|
||||||
|
|
||||||
return boost::report_errors();
|
return boost::report_errors();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user