#ifndef FOR_EACH_ENTRY_HH #define FOR_EACH_ENTRY_HH #include #include // traits to detect FindMany types. namespace art { template class FindMany; } template struct is_FindMany : std::false_type { }; template struct is_FindMany> : std::true_type { }; // for_each_entry(fm, f) encapsulates a loop over all entries in the // primary product of an association, and calls the provided function // once for each collection of associated objects. // 'fm' must be a FindMany object, relating the entries in the product // whose handle was used to create the FindMany object to some objects // (of type B) in a second product in the event. For each element in // the first product, for_each_entry will call the callable object // 'f', (typically a lambda expression), passing to it a argument of // type 'std::vector const&'. template void for_each_entry(FM const& fm, FCN f) { static_assert(is_FindMany::value, "fm is not an art::FindMany"); for (std::size_t i = 0, sz = fm.size(); i != sz; ++i) { f(fm.at(i)); } } #endif