nlib
Swap.h
1
2
/*--------------------------------------------------------------------------------*
3
Project: CrossRoad
4
Copyright (C)Nintendo All rights reserved.
5
6
These coded instructions, statements, and computer programs contain proprietary
7
information of Nintendo and/or its licensed developers and are protected by
8
national and international copyright laws. They may not be disclosed to third
9
parties or copied or duplicated in any form, in whole or in part, without the
10
prior written consent of Nintendo.
11
12
The content herein is highly confidential and should be handled accordingly.
13
*--------------------------------------------------------------------------------*/
14
15
#pragma once
16
#ifndef INCLUDE_NN_NLIB_SWAP_H_
17
#define INCLUDE_NN_NLIB_SWAP_H_
18
19
#include "
nn/nlib/Config.h
"
20
#ifdef NLIB_CXX11_SWAPHEADER
21
#include <utility>
// NOLINT
22
#else
23
#include <algorithm>
// NOLINT
24
#endif
25
26
#ifdef __cpp_rvalue_references
27
#define NLIB_DEFINE_STD_SWAP(tp)
28
#define NLIB_DEFINE_STD_SWAP_T_BEGIN2(ns1, ns2)
29
#define NLIB_DEFINE_STD_SWAP_T_BEGIN3(ns1, ns2, ns3)
30
#define NLIB_DEFINE_STD_SWAP_T_BEGIN4(ns1, ns2, ns3, ns4)
31
#define NLIB_DEFINE_STD_SWAP_T_END2(ns1, ns2)
32
#define NLIB_DEFINE_STD_SWAP_T_END3(ns1, ns2, ns3)
33
#define NLIB_DEFINE_STD_SWAP_T_END4(ns1, ns2, ns3, ns4)
34
#define NLIB_DEFINE_STD_SWAP_T1(targ1, tp)
35
#define NLIB_DEFINE_STD_SWAP_T2(targ1, targ2, tp)
36
#else
37
#define NLIB_DEFINE_STD_SWAP(tp) \
38
namespace std { \
39
template<> inline void swap<tp>(tp& lhs, tp& rhs) {
/* NOLINT */
\
40
tp x(lhs, nlib_ns::move_tag()); \
41
lhs.assign(rhs, nlib_ns::move_tag()); \
42
rhs.assign(x, nlib_ns::move_tag()); \
43
} \
44
}
45
#ifndef NLIB_STD_SWAP_WORKAROUND
46
# define NLIB_DEFINE_STD_SWAP_T_BEGIN2(ns1, ns2) NLIB_NAMESPACE_BEGIN // NOLINT
47
# define NLIB_DEFINE_STD_SWAP_T_BEGIN3(ns1, ns2, ns3) \
48
NLIB_NAMESPACE_BEGIN namespace ns3 { // NOLINT
49
# define NLIB_DEFINE_STD_SWAP_T_BEGIN4(ns1, ns2, ns3, ns4) \
50
NLIB_NAMESPACE_BEGIN namespace ns3 { namespace ns4 { // NOLINT
51
# define NLIB_DEFINE_STD_SWAP_T_END2(ns1, ns2) NLIB_NAMESPACE_END // NOLINT
52
# define NLIB_DEFINE_STD_SWAP_T_END3(ns1, ns2, ns3) } NLIB_NAMESPACE_END // NOLINT
53
# define NLIB_DEFINE_STD_SWAP_T_END4(ns1, ns2, ns3, ns4) }} NLIB_NAMESPACE_END // NOLINT
54
#else
55
// This code is for the compilers which std::swap has priority over ADL.
56
# define NLIB_DEFINE_STD_SWAP_T_BEGIN2(ns1, ns2) namespace std { // NOLINT
57
# define NLIB_DEFINE_STD_SWAP_T_BEGIN3(ns1, ns2, ns3) namespace std { // NOLINT
58
# define NLIB_DEFINE_STD_SWAP_T_BEGIN4(ns1, ns2, ns3, ns4) namespace std { // NOLINT
59
# define NLIB_DEFINE_STD_SWAP_T_END2(ns1, ns2) } // NOLINT
60
# define NLIB_DEFINE_STD_SWAP_T_END3(ns1, ns2, ns3) } // NOLINT
61
# define NLIB_DEFINE_STD_SWAP_T_END4(ns1, ns2, ns3, ns4) } // NOLINT
62
#endif
63
#if 1
64
# define NLIB_DEFINE_STD_SWAP_T1(targ1, tp) \
65
template<class targ1> NLIB_ALWAYS_INLINE \
66
void swap(tp<targ1>& lhs, tp<targ1>& rhs)
/* NOLINT */
{ \
67
tp<targ1> x(lhs, nlib_ns::move_tag()); \
68
lhs.assign(rhs, nlib_ns::move_tag()); \
69
rhs.assign(x, nlib_ns::move_tag()); \
70
}
71
# define NLIB_DEFINE_STD_SWAP_T2(targ1, targ2, tp) \
72
template<class targ1, class targ2> NLIB_ALWAYS_INLINE \
73
void swap(tp<targ1, targ2>& lhs, tp<targ1, targ2>& rhs)
/* NOLINT */
{ \
74
tp<targ1, targ2> x(lhs, nlib_ns::move_tag()); \
75
lhs.assign(rhs, nlib_ns::move_tag()); \
76
rhs.assign(x, nlib_ns::move_tag()); \
77
}
78
#else
79
# define NLIB_DEFINE_STD_SWAP_T1(targ1, tp) \
80
template<class targ1> NLIB_ALWAYS_INLINE \
81
void swap(tp<targ1>& lhs, tp<targ1>& rhs)
/* NOLINT */
{ \
82
lhs.swap(rhs); \
83
}
84
# define NLIB_DEFINE_STD_SWAP_T2(targ1, targ2, tp) \
85
template<class targ1, class targ2> NLIB_ALWAYS_INLINE \
86
void swap(tp<targ1, targ2>& lhs, tp<targ1, targ2>& rhs)
/* NOLINT */
{ \
87
lhs.swap(rhs); \
88
}
89
#endif
90
#endif
91
92
#endif // INCLUDE_NN_NLIB_SWAP_H_
Config.h
A file that contains the configuration information for each development environment.
© 2012-2017 Nintendo Co., Ltd. All rights reserved.