11 template <
typename INT>
14 s <<
"0x" << std::hex <<
i;
19 template <
typename INT>
24 s <<
"0b" <<
b.to_string().substr(32 -
n, 32);
25 }
else if (
sizeof(
i) <= 8) {
27 s <<
"0b" <<
b.to_string().substr(64 -
n, 64);
33 template <
typename T,
size_t N>
39 template <
typename T,
size_t N>
43 for (
size_t i = 0;
i <
N; ++
i) {
60 _reversed(
T& _t) :
t(_t) {}
61 decltype(
t.rbegin()) begin() {
return t.rbegin(); }
62 decltype(
t.rend()) end() {
return t.rend(); }
66 details::_reversed<T> reversed(
T&
t) {
67 return details::_reversed<T>(
t);
72 template <
class STR = std::
string>
73 std::vector<STR> split_string(
const std::string&
s,
char c =
' ',
char d =
' ') {
75 const char*
str =
s.c_str();
81 }
while (0 != *
str++);
87 template <
class T1,
class T2>
88 void flatten_container(
const T1&
input, T2&
output) {
89 typename T1::const_iterator
it;
97 struct is_map_of_vectors :
public std::false_type {};
99 template <
typename T1,
typename T2>
100 struct is_map_of_vectors<
std::
map<T1, std::vector<T2> > > :
public std::true_type {};
103 template <
typename Map>
104 void merge_map_into_map(
const Map& map1, Map& map2) {
106 typedef typename Map::iterator
Iterator;
107 typedef typename Map::mapped_type
Container;
109 for (
auto& kv1 : map1) {
110 std::pair<Iterator, bool>
ins = map2.insert(kv1);
113 const Container* container1 = &(kv1.second);
115 container2->insert(container2->end(), container1->begin(), container1->end());
125 template <
class ForwardIt,
class BinaryPredicate,
class BinaryOp>
126 ForwardIt adjacent_cluster(ForwardIt
first, ForwardIt
last, BinaryPredicate adjacent, BinaryOp cluster) {
143 template <
typename RandomAccessIterator,
typename Compare = std::less<> >
144 void merge_sort_merge(RandomAccessIterator
first,
145 RandomAccessIterator middle,
146 RandomAccessIterator
last,
150 typedef typename std::iterator_traits<RandomAccessIterator>::pointer pointer;
151 std::unique_ptr<value_type[]>
p{
new value_type[len]};
152 pointer
buf =
p.get();
153 pointer buf_end =
buf + len;
155 RandomAccessIterator first1 =
first;
156 RandomAccessIterator last1 = middle;
157 RandomAccessIterator first2 = middle;
158 RandomAccessIterator last2 =
last;
160 while (first1 != last1 && first2 != last2) {
161 if (
cmp(*first2, *first1)) {
167 while (first1 != last1) {
170 while (first2 != last2) {
179 template <
typename RandomAccessIterator,
typename Compare = std::less<> >
180 void merge_sort(RandomAccessIterator
first, RandomAccessIterator
last, Compare
cmp) {
193 template <
typename RandomAccessIterator,
typename Compare,
typename Compare3>
194 void merge_sort_merge3(RandomAccessIterator
first,
195 RandomAccessIterator one_third,
196 RandomAccessIterator two_third,
197 RandomAccessIterator
last,
202 typedef typename std::iterator_traits<RandomAccessIterator>::pointer pointer;
203 std::unique_ptr<value_type[]>
p{
new value_type[len]};
204 pointer
buf =
p.get();
205 const pointer buf_end =
buf + len;
207 RandomAccessIterator first1 =
first;
208 RandomAccessIterator last1 = one_third;
209 RandomAccessIterator first2 = one_third;
210 RandomAccessIterator last2 = two_third;
211 RandomAccessIterator first3 = two_third;
212 RandomAccessIterator last3 =
last;
214 while (first1 != last1 && first2 != last2 && first3 != last3) {
215 int rr = cmp3(*first1, *first2, *first3);
218 }
else if (
rr == 1) {
220 }
else if (
rr == 2) {
225 if (first3 == last3) {
227 }
else if (first2 == last2) {
230 }
else if (first1 == last1) {
237 while (first1 != last1 && first2 != last2) {
238 if (
cmp(*first2, *first1)) {
244 while (first1 != last1) {
247 while (first2 != last2) {
256 template <
typename RandomAccessIterator,
typename Compare,
typename Compare3>
257 void merge_sort3(RandomAccessIterator
first, RandomAccessIterator
last, Compare
cmp, Compare3 cmp3) {
261 RandomAccessIterator two_third =
std::next(
first, (len + 2) / 3 * 2);
262 merge_sort3(
first, one_third,
cmp, cmp3);
263 merge_sort3(one_third, two_third,
cmp, cmp3);
264 merge_sort3(two_third,
last,
cmp, cmp3);
265 merge_sort_merge3(
first, one_third, two_third,
last,
cmp, cmp3);
270 template <
typename RandomAccessIterator,
typename Compare,
typename Compare3>
271 void merge_sort3_with_hint(
272 RandomAccessIterator
first, RandomAccessIterator
last, Compare
cmp, Compare3 cmp3, std::ptrdiff_t
d) {
277 merge_sort3(
first, one_third,
cmp, cmp3);
278 merge_sort3(one_third, two_third,
cmp, cmp3);
279 merge_sort3(two_third,
last,
cmp, cmp3);
280 merge_sort_merge3(
first, one_third, two_third,
last,
cmp, cmp3);
static char to_hex(unsigned int i)
static std::string const input
Container::value_type value_type
edm::AssociationVector< reco::JetRefBaseProd, Values > Container