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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#ifndef DataFormats_Common_RefTraits_h
#define DataFormats_Common_RefTraits_h
#include <algorithm>
namespace edm {
template <typename C, typename T, typename F>
class RefVector;
template <typename T>
class RefToBaseVector;
namespace refhelper {
template <typename C, typename T>
struct FindUsingAdvance {
typedef C const& first_argument_type;
typedef unsigned int second_argument_type;
typedef T const* result_type;
result_type operator()(first_argument_type iContainer, second_argument_type iIndex) {
typename C::const_iterator it = iContainer.begin();
std::advance(it, static_cast<typename C::size_type>(iIndex));
return it.operator->();
}
};
template <typename REFV>
struct FindRefVectorUsingAdvance {
using first_argument_type = REFV const&;
using second_argument_type = typename REFV::key_type;
using result_type = typename REFV::member_type const*;
result_type operator()(first_argument_type iContainer, second_argument_type iIndex) {
typename REFV::const_iterator it = iContainer.begin();
std::advance(it, iIndex);
return it.operator->()->get();
}
};
//Used in edm::Ref to set the default 'find' method to use based on the Container and 'contained' type
template <typename C, typename T>
struct FindTrait {
typedef FindUsingAdvance<C, T> value;
};
template <typename C, typename T, typename F>
struct FindTrait<RefVector<C, T, F>, T> {
typedef FindRefVectorUsingAdvance<RefVector<C, T, F> > value;
};
template <typename T>
struct FindTrait<RefToBaseVector<T>, T> {
typedef FindRefVectorUsingAdvance<RefToBaseVector<T> > value;
};
template <typename C>
struct ValueTrait {
typedef typename C::value_type value;
};
template <typename C, typename T, typename F>
struct ValueTrait<RefVector<C, T, F> > {
typedef T value;
};
template <typename T>
struct ValueTrait<RefToBaseVector<T> > {
typedef T value;
};
} // namespace refhelper
} // namespace edm
#endif
|