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

Add function for_each_field_with_name (#171)

This commit is contained in:
Lena
2024-09-13 10:57:49 +02:00
committed by GitHub
parent e1e908e804
commit 3d090e7c6f
6 changed files with 111 additions and 1 deletions

View File

@@ -0,0 +1,31 @@
// Copyright (c) 2016-2024 Lena Bertho
//
// 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 <map>
#include <string>
#include <boost/pfr/core_name.hpp>
#include <boost/core/lightweight_test.hpp>
struct SimpleStruct {
char c;
std::string str;
};
int main () {
std::map<std::string, std::string> m;
auto fill = [&m](std::string_view name, const auto& value){
m[std::string(name)] = value;
};
boost::pfr::for_each_field_with_name(SimpleStruct{ 'e', "test"}, fill);
BOOST_TEST_EQ(m.size(), 2);
BOOST_TEST_EQ(m["c"], "e");
BOOST_TEST_EQ(m["str"], "test");
return boost::report_errors();
}