-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitwise-costness.cpp
73 lines (64 loc) · 1.63 KB
/
bitwise-costness.cpp
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
#include <new>
#include <memory>
#include <atomic>
#include <thread>
#include <mutex>
#include <future>
#include <utility>
#include <tuple>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <forward_list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <algorithm>
#include <iterator>
#include <functional>
#include <regex>
#include <bitset>
#include <iostream>
using namespace std;
class BigArray
{
vector<int> v; // huge vector
int accessCounter;
mutable int accessCounterMut;
int *v2; // another int array
public:
int getItem(int index) const
{
// accessCounter++; // <- fails as function marked as const
accessCounterMut++; // <- does not fail
const_cast<BigArray *>(this)->accessCounter++; // hacky way to update
return v[index];
}
void setV2Item(int index, int x)
{
*(v2 + index) = x;
}
/**
* 1. the return value of fun is a constant pointer pointing to a constant integer value
*
* 2. the parameter of fun is a reference of a constant pointer pointing to a constant
* integer the reference cannot refer to a different pointer (nature of references)
* the referred pointer cannot point to a different value the pointed value of the
* referred pointer cannot be changed
*
* 3. fun is also a const function, meaning that it cannot directly modify members unless
* they are marked mutable, also it can only call other const functions
*
*/
const int *const fun(const int *const &p) const;
};
int main()
{
BigArray b1;
return 0;
}