-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpointers.h
More file actions
111 lines (89 loc) · 2.05 KB
/
pointers.h
File metadata and controls
111 lines (89 loc) · 2.05 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
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// pointers.h
// Copyright (c) 2009 Alexander Stepanov and Paul McJones
//
// Permission to use, copy, modify, distribute and sell this software
// and its documentation for any purpose is hereby granted without
// fee, provided that the above copyright notice appear in all copies
// and that both that copyright notice and this permission notice
// appear in supporting documentation. The authors make no
// representations about the suitability of this software for any
// purpose. It is provided "as is" without express or implied
// warranty.
// Definitions of type functions and global functions from concepts
// Readable, Writeable, Mutable, Iterator, BidirectionalIterator
// for types const T& and pointer(T) from
// Elements of Programming
// by Alexander Stepanov and Paul McJones
// Addison-Wesley Professional, 2009
#ifndef EOP_POINTERS
#define EOP_POINTERS
#include "intrinsics.h"
#include "type_functions.h"
#include <cstddef> // ptrdiff_t
template<typename T>
requires(Regular(T))
struct value_type<pointer(T)>
{
typedef T type;
};
template<typename T>
requires(Regular(T))
const T& source(pointer(T) x)
{
return *x;
}
template<typename T>
requires(Regular(T))
const T& source(const T& x)
{
return x;
}
template<typename T>
requires(Regular(T))
struct distance_type<pointer(T)>
{
typedef ptrdiff_t type;
};
template<typename T>
requires(Regular(T))
pointer(T) successor(pointer(T) x)
{
return x + ptrdiff_t(1);
}
template<typename T>
requires(Regular(T))
pointer(T) predecessor(pointer(T) x)
{
return x - ptrdiff_t(1);
}
template<typename T>
requires(Regular(T))
T& sink(pointer(T) x)
{
return *x;
}
template<typename T>
requires(Regular(T))
T& sink(T& x)
{
return x;
}
template<typename T>
requires(Regular(T))
T& deref(pointer(T) x)
{
return *x;
}
//template<typename T>
// requires(Regular(T))
//T& deref(T& x)
//{
// return x;
//}
template<typename T>
requires(Regular(T))
struct iterator_concept<T*>
{
typedef random_access_iterator_tag concept;
};
#endif // EOP_POINTERS