-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperate_const_vector.cpp
More file actions
48 lines (36 loc) · 1.08 KB
/
operate_const_vector.cpp
File metadata and controls
48 lines (36 loc) · 1.08 KB
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
#include <boost/range/iterator_range.hpp>
#include <boost/assign/std/vector.hpp>
using boost::assign::operator+=;
#include <vector>
#include <algorithm>
#include <iterator>
#include <iostream>
template<class T>
boost::iterator_range<const T*> makePointerRange(const std::vector<const T>& vector)
{
return boost::make_iterator_range(&(vector[0]), &(vector[0]) + vector.size());
}
template<class T>
boost::iterator_range<const T*> makePointerRange(const std::vector<T>& vector)
{
return boost::make_iterator_range(&(vector[0]), &(vector[0]) + vector.size());
}
typedef boost::iterator_range<const int*> ConcreteConstRange;
void operateConstRange(const ConcreteConstRange& range)
{
std::copy(range.begin(), range.end(),
std::ostream_iterator<const int>(std::cout, " "));
std::cout << std::endl;
}
namespace {
int main_()
{
std::vector<const int> vectorOfConst;
vectorOfConst += 1, 5, 4, 3;
operateConstRange(makePointerRange(vectorOfConst));
std::vector<int> vector;
vector += 1, 5, 4, 3;
operateConstRange(makePointerRange(vector));
return 0;
}
}