File: VectorUtility.h

package info (click to toggle)
clustalx 2.1%2Blgpl-9
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 3,324 kB
  • sloc: cpp: 40,050; sh: 163; xml: 102; makefile: 16
file content (51 lines) | stat: -rw-r--r-- 1,501 bytes parent folder | download | duplicates (12)
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
/**
 * Author: Mark Larkin
 * 
 * Copyright (c) 2007 Des Higgins, Julie Thompson and Toby Gibson.  
 */
#ifndef VECTORUTILITY_H
#define VECTORUTILITY_H
#include <vector>

namespace vectorutils
{

/**
 * The function mergeVectors will add the contents of 
 * the other two vectors to the end of the first vector.
 */
template<class T>
void mergeVectors(std::vector<T>* vecToAddTo, std::vector<T>* vector1, std::vector<T>* vector2)
{
    typename std::vector<T>::iterator beginInsert = vecToAddTo->end();
    typename std::vector<T>::iterator beginVec1 = vector1->begin();
    typename std::vector<T>::iterator endVec1 = vector1->end();
    typename std::vector<T>::iterator beginVec2 = vector2->begin();
    typename std::vector<T>::iterator endVec2 = vector2->end();
    
    // Add the first vector
    vecToAddTo->insert(beginInsert, beginVec1, endVec1);
    
    beginInsert = vecToAddTo->end();
    // Add the second vector
    vecToAddTo->insert(beginInsert, beginVec2, endVec2);
}

/**
 * The function mergeVectors will add the contents of the second vector 
 * to the end of the first vector.
 */
template<class T>
void mergeVectors(std::vector<T>* vecToAddTo, std::vector<T>* vector1)
{
    typename std::vector<T>::iterator beginInsert = vecToAddTo->end();
    typename std::vector<T>::iterator beginVec1 = vector1->begin();
    typename std::vector<T>::iterator endVec1 = vector1->end();
    
    // Add the first vector
    vecToAddTo->insert(beginInsert, beginVec1, endVec1);
}

}

#endif