Repository navigation
Expand file tree
/
Copy pathalgorithm
More file actions
93 lines (78 loc) · 2.13 KB
/
Copy pathalgorithm
File metadata and controls
93 lines (78 loc) · 2.13 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
#pragma once
#ifndef __cplusplus
# error This header requires C++
#endif
#include <sps/cenv.h>
#include <algorithm>
namespace sps {
#if 0
template<class T>
typename std::enable_if<!std::numeric_limits<T>::is_integer, bool>::type
almost_equal(T x, T y, int ulp)
{
// the machine epsilon has to be scaled to the magnitude of the values used
// and multiplied by the desired precision in ULPs (units in the last place)
return std::fabs(x-y) <= std::numeric_limits<T>::epsilon() * std::fabs(x+y) * ulp
// unless the result is subnormal
|| std::fabs(x-y) < std::numeric_limits<T>::min();
}
if ( std::adjacent_find( myvector.begin(), myvector.end(), std::not_equal_to<>() ) == myvector.end() )
{
std::cout << "All elements are equal each other" << std::endl;
}
#endif
template <typename T>
struct wrapped_array {
wrapped_array(T* first, T* last) : begin_ {first}, end_ {last} {}
wrapped_array(T* first, std::ptrdiff_t size)
: wrapped_array {first, first + size} {}
T* begin() const noexcept { return begin_; }
T* end() const noexcept { return end_; }
T* begin_;
T* end_;
};
template <typename T>
wrapped_array<T> wrap_array(T* first, std::ptrdiff_t size) noexcept {
return {first, size};
}
#if CXX17
using std::clamp;
#else
template <typename T>
T clamp(T in, const T& low, const T& high) {
return std::min<T>(std::max<T>(in, low), high);
}
#endif
}
namespace sps {
#ifdef __GNUG__
using std::swap;
#elif defined(_MSC_VER)
# if (_MSC_VER < 1700)
template<typename T> void swap(T& t1, T& t2) {
T tmp(t1);
t1=t2;
t2=tmp;
}
# elif (_MSC_VER == 1700)
template<typename T> void swap(T& t1, T& t2) {
T temp = std::move(t1);
t1 = std::move(t2);
t2 = std::move(temp);
}
# elif (_MSC_VER >= 1800)
// Why can't we say using std::swap or template <typename T> using swap = std::swap<T>
template<typename T> void swap(T& t1,T& t2) {
T temp = std::move(t1);
t1 = std::move(t2);
t2 = std::move(temp);
}
# endif
#endif
} // namespace sps
/* Local variables: */
/* tab-width: 2 */
/* c-basic-offset: 2 */
/* indent-tabs-mode: nil */
/* mode: C++ */
/* End: */