.. _program_listing_file_src_pcms_utility_common.h: Program Listing for File common.h ================================= |exhale_lsh| :ref:`Return to documentation for file ` (``src/pcms/utility/common.h``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #ifndef PCMS_COUPLING_COMMON_H #define PCMS_COUPLING_COMMON_H #include "pcms/utility/assert.h" #include #include #include #include namespace pcms { namespace detail { // helper function for dealing with field maps template auto& find_or_error(const std::string& name, const std::map& map) { auto it = map.find(name); PCMS_ALWAYS_ASSERT(it != map.end()); return it->second; } template auto& find_or_error(const std::string& name, std::map& map) { auto it = map.find(name); PCMS_ALWAYS_ASSERT(it != map.end()); return it->second; } template auto find_many_or_error(const std::vector& keys, const std::map& map) { std::vector> results; results.reserve(keys.size()); std::transform(keys.begin(), keys.end(), std::back_inserter(results), [&map](const std::string& key) { return std::ref(detail::find_or_error(key, map)); }); return results; } template auto find_many_or_error(const std::vector& keys, std::map& map) { std::vector> results; results.reserve(keys.size()); std::transform(keys.begin(), keys.end(), std::back_inserter(results), [&map](const std::string& key) { return std::ref(detail::find_or_error(key, map)); }); return results; } } // namespace detail } // namespace pcms #endif // PCMS_COUPLING_COMMON_H