-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add function for_each_field_with_name
To be able to iterate over the fields name and value of an aggregate
- Loading branch information
Showing
6 changed files
with
111 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |