forked from msinilo/rdestl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pair.h
77 lines (63 loc) · 2.03 KB
/
pair.h
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
#ifndef RDESTL_PAIR_H
#define RDESTL_PAIR_H
// Use std::pair (it's bigger, but the actual code is 'good enough'
// and it comes with more 'modern C++' bells and whistles (most notably, piecewise construct)
//#define RDESTL_USE_STD_PAIR 1
#include <utility>
#include "type_traits.h"
namespace rde
{
#ifdef RDESTL_USE_STD_PAIR
template<typename T1, typename T2>
using pair = std::pair<T1, T2>;
#else
//=============================================================================
template<typename T1, typename T2>
struct pair
{
typedef T1 first_type;
typedef T2 second_type;
pair() { /**/ }
pair(const T1& a, const T2& b): first(a), second(b) { /**/ }
explicit pair(const T1& a): first(a) { /**/ }
pair(const pair<T1, T2>& rhs): first(rhs.first), second(rhs.second) { /**/ }
pair(pair<T1, T2>&& rhs): first(std::move(rhs.first)), second(std::move(rhs.second)) { /**/ }
template<class... Args2>
pair(T1&& first_args, Args2&&... second_args)
: first(std::forward<T1>(first_args))
, second(std::forward<Args2>(second_args)...) { /**/ }
pair& operator=(const pair<T1, T2>& rhs)
{
first = rhs.first;
second = rhs.second;
return *this;
}
pair& operator=(pair<T1, T2>&& rhs)
{
first = std::move(rhs.first);
second = std::move(rhs.second);
return *this;
}
T1 first;
T2 second;
};
#endif // #ifdef RDESTL_USE_STD_PAIR
//=============================================================================
// Pair is POD if every element is POD/fundamental
template<typename T1, typename T2>
struct is_pod<pair<T1, T2>>
{
enum {
value = (is_pod<T1>::value || is_fundamental<T1>::value) &&
(is_pod<T2>::value || is_fundamental<T2>::value)
};
};
//-----------------------------------------------------------------------------
template<typename T1, typename T2>
pair<T1, T2> make_pair(const T1& a, const T2& b)
{
return pair<T1, T2>(a, b);
}
} // namespace rde
//-----------------------------------------------------------------------------
#endif // #ifndef RDESTL_PAIR_H