Skip to content

Commit

Permalink
C++17: structured bindings to replace "std::tie(x,y,z) = f()" (ECP-Wa…
Browse files Browse the repository at this point in the history
…rpX#2644)

* use structured bindings

* std::ignore equivalent in structured bindings

Co-authored-by: Axel Huebl <[email protected]>
  • Loading branch information
lucafedeli88 and ax3l authored Dec 9, 2021
1 parent 583c78e commit f4dc5eb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 22 deletions.
21 changes: 7 additions & 14 deletions Source/Diagnostics/WarpXOpenPMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,8 +751,7 @@ WarpXOpenPMDPlot::SetupRealProperties (openPMD::ParticleSpecies& currSpecies,
//
auto const getComponentRecord = [&currSpecies](std::string const comp_name) {
// handle scalar and non-scalar records by name
std::string record_name, component_name;
std::tie(record_name, component_name) = detail::name2openPMD(comp_name);
const auto [record_name, component_name] = detail::name2openPMD(comp_name);
return currSpecies[record_name][component_name];
};
auto const real_counter = std::min(write_real_comp.size(), real_comp_names.size());
Expand All @@ -773,13 +772,11 @@ WarpXOpenPMDPlot::SetupRealProperties (openPMD::ParticleSpecies& currSpecies,
auto ii = m_NumAoSRealAttributes + idx; // jump over AoS names
if (write_real_comp[ii]) {
// handle scalar and non-scalar records by name
std::string record_name, component_name;
std::tie(record_name, component_name) = detail::name2openPMD(real_comp_names[ii]);
const auto [record_name, component_name] = detail::name2openPMD(real_comp_names[ii]);
auto currRecord = currSpecies[record_name];

// meta data for ED-PIC extension
bool newRecord = false;
std::tie(std::ignore, newRecord) = addedRecords.insert(record_name);
[[maybe_unused]] const auto [_, newRecord] = addedRecords.insert(record_name);
if( newRecord ) {
currRecord.setUnitDimension( detail::getUnitDimension(record_name) );
if( record_name == "weighting" )
Expand All @@ -797,13 +794,11 @@ WarpXOpenPMDPlot::SetupRealProperties (openPMD::ParticleSpecies& currSpecies,
auto ii = m_NumAoSIntAttributes + idx; // jump over AoS names
if (write_int_comp[ii]) {
// handle scalar and non-scalar records by name
std::string record_name, component_name;
std::tie(record_name, component_name) = detail::name2openPMD(int_comp_names[ii]);
const auto [record_name, component_name] = detail::name2openPMD(int_comp_names[ii]);
auto currRecord = currSpecies[record_name];

// meta data for ED-PIC extension
bool newRecord = false;
std::tie(std::ignore, newRecord) = addedRecords.insert(record_name);
[[maybe_unused]] const auto [_, newRecord] = addedRecords.insert(record_name);
if( newRecord ) {
currRecord.setUnitDimension( detail::getUnitDimension(record_name) );
currRecord.setAttribute( "macroWeighted", 0u );
Expand Down Expand Up @@ -843,8 +838,7 @@ WarpXOpenPMDPlot::SaveRealProperty (ParticleIter& pti,
for( auto idx=0; idx<m_NumAoSRealAttributes; idx++ ) {
if( write_real_comp[idx] ) {
// handle scalar and non-scalar records by name
std::string record_name, component_name;
std::tie(record_name, component_name) = detail::name2openPMD(real_comp_names[idx]);
const auto [record_name, component_name] = detail::name2openPMD(real_comp_names[idx]);
auto currRecord = currSpecies[record_name];
auto currRecordComp = currRecord[component_name];

Expand All @@ -864,8 +858,7 @@ WarpXOpenPMDPlot::SaveRealProperty (ParticleIter& pti,

auto const getComponentRecord = [&currSpecies](std::string const comp_name) {
// handle scalar and non-scalar records by name
std::string record_name, component_name;
std::tie(record_name, component_name) = detail::name2openPMD(comp_name);
const auto [record_name, component_name] = detail::name2openPMD(comp_name);
return currSpecies[record_name][component_name];
};

Expand Down
3 changes: 1 addition & 2 deletions Source/Laser/LaserProfilesImpl/LaserProfileFromTXYEFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ WarpXLaserProfiles::FromTXYEFileLaserProfile::fill_amplitude (
}

//Find left and right time indices
int idx_t_left, idx_t_right;
std::tie(idx_t_left, idx_t_right) = find_left_right_time_indices(t);
const auto [idx_t_left, idx_t_right] = find_left_right_time_indices(t);

if(idx_t_left < m_params.first_time_index){
Abort("Something bad has happened with the simulation time");
Expand Down
8 changes: 2 additions & 6 deletions Source/Utils/MsgLogger/MsgLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,7 @@ Logger::collective_gather_msgs_with_counter_and_ranks() const
// Find out who is the "gather rank" and how many messages it has
const auto my_msgs = get_msgs();
const auto how_many_msgs = my_msgs.size();
int gather_rank = 0;
std::int64_t gather_rank_how_many_msgs = 0;
std::tie(gather_rank, gather_rank_how_many_msgs) =
const auto [gather_rank, gather_rank_how_many_msgs] =
find_gather_rank_and_its_msgs(how_many_msgs);

// If the "gather rank" has zero messages there are no messages at all
Expand All @@ -273,9 +271,7 @@ Logger::collective_gather_msgs_with_counter_and_ranks() const
m_messages, is_gather_rank);

// Send back all the data to the "gather rank"
auto all_data = std::vector<char>{};
auto displacements = std::vector<int>{};
std::tie(all_data, displacements) =
const auto [all_data, displacements] =
::gather_all_data(
package_for_gather_rank,
gather_rank, m_rank);
Expand Down

0 comments on commit f4dc5eb

Please sign in to comment.