MCPcopy Create free account
hub / github.com/Geode-solutions/OpenGeode / extract_vector_elements

Function extract_vector_elements

include/geode/basic/algorithm.hpp:93–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

91 */
92 template < typename DeleteContainer, typename ValueContainer >
93 [[nodiscard]] ValueContainer extract_vector_elements(
94 const DeleteContainer& to_keep, const ValueContainer& in_values )
95 {
96 OpenGeodeBasicException::check_assertion(
97 to_keep.size() == in_values.size(),
98 "[extract_vector_elements] Number of elements in the two vectors "
99 "should match" );
100 const auto nb_to_keep =
101 static_cast< index_t >( absl::c_count( to_keep, true ) );
102 if( nb_to_keep == in_values.size() )
103 {
104 return in_values;
105 }
106 ValueContainer out_values;
107 out_values.reserve( nb_to_keep );
108 for( const auto i : Indices{ to_keep } )
109 {
110 if( to_keep[i] )
111 {
112 out_values.push_back( in_values[i] );
113 }
114 }
115 return out_values;
116 }
117
118 /*!
119 * Modify the container by removing every duplicated values inside

Callers 2

Calls 2

sizeMethod · 0.45
reserveMethod · 0.45

Tested by 1