Key

KeyVal

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
#ifndef DataFormats_Common_AssociationMapKeyVal_h
#define DataFormats_Common_AssociationMapKeyVal_h
/*
 *
 * helper classes for AssociationMap
 *
 * \author Luca Lista, INFN
 *
 *
 */
#include "DataFormats/Provenance/interface/ProductID.h"
#include "FWCore/Utilities/interface/EDMException.h"

#include <utility>

namespace edm {

  class EDProductGetter;

  namespace helpers {
    template <typename K, typename V>
    struct KeyVal {
      typedef K key_type;
      typedef V value_type;
      KeyVal() : key(), val() {}
      KeyVal(const K& k, const V& v) : key(k), val(v) {}
      template <typename K_, typename V_>
      KeyVal(K_&& k, V_&& v) : key(std::forward<K_>(k)), val(std::forward<V_>(v)) {}

      KeyVal(EDProductGetter const* getter) : key(ProductID(), getter), val(ProductID(), getter) {}

      K key;
      V val;
    };

    template <typename K>
    struct Key {
      typedef K key_type;
      Key() {}
      Key(const K& k) : key(k) {}
      template <typename K_>
      Key(K_&& k) : key(std::forward<K_>(k)) {}

      Key(EDProductGetter const* getter) : key(ProductID(), getter) {}

      K key;
    };

    /// throw if r hasn't the same id as rp
    template <typename RP, typename R>
    void checkRef(const RP& rp, const R& r) {
      if (rp.id() != r.id()) {
        Exception::throwThis(edm::errors::InvalidReference, "invalid reference");
      }
    }
  }  // namespace helpers
}  // namespace edm

#endif