mirror of
https://github.com/boostorg/pfr.git
synced 2026-01-19 04:22:13 +00:00
Merge pull request #152 from schaumb/get_name
Addressing the limitation of get_name
This commit is contained in:
@@ -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,19 @@ void test_get_name_by_id() {
|
||||
BOOST_TEST_EQ( ((boost::pfr::get_name<1, A>())), "second");
|
||||
}
|
||||
|
||||
void test_get_name_by_id_without_linkage() {
|
||||
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");
|
||||
}
|
||||
|
||||
void test_get_name_by_type() {
|
||||
// FIXME: implement this
|
||||
// using char_ref = std::reference_wrapper<char>;
|
||||
@@ -52,6 +78,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 +99,18 @@ void test_names_as_array() {
|
||||
}
|
||||
}
|
||||
|
||||
void test_names_as_array_without_linkage() {
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
void test_names_as_array_for_empty() {
|
||||
const auto value = boost::pfr::names_as_array<empty>();
|
||||
BOOST_TEST_EQ(value.size(), 0);
|
||||
@@ -76,8 +121,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();
|
||||
|
||||
Reference in New Issue
Block a user