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>
22 #else
23 #include <algorithm>
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<> \
40  inline void swap<tp>(tp & lhs, tp& rhs) { \
41  tp x(lhs, nlib_ns::move_tag()); \
42  lhs.assign(rhs, nlib_ns::move_tag()); \
43  rhs.assign(x, nlib_ns::move_tag()); \
44  } \
45  }
46 #ifndef NLIB_STD_SWAP_WORKAROUND
47 #define NLIB_DEFINE_STD_SWAP_T_BEGIN2(ns1, ns2) NLIB_NAMESPACE_BEGIN
48 #define NLIB_DEFINE_STD_SWAP_T_BEGIN3(ns1, ns2, ns3) NLIB_NAMESPACE_BEGIN namespace ns3 {
49 #define NLIB_DEFINE_STD_SWAP_T_BEGIN4(ns1, ns2, ns3, ns4) \
50  NLIB_NAMESPACE_BEGIN namespace ns3 { \
51  namespace ns4 {
52 #define NLIB_DEFINE_STD_SWAP_T_END2(ns1, ns2) NLIB_NAMESPACE_END
53 #define NLIB_DEFINE_STD_SWAP_T_END3(ns1, ns2, ns3) \
54  } \
55  NLIB_NAMESPACE_END
56 #define NLIB_DEFINE_STD_SWAP_T_END4(ns1, ns2, ns3, ns4) \
57  } \
58  } \
59  NLIB_NAMESPACE_END
60 #else
61 // This code is for the compilers which std::swap has priority over ADL.
62 #define NLIB_DEFINE_STD_SWAP_T_BEGIN2(ns1, ns2) namespace std {
63 #define NLIB_DEFINE_STD_SWAP_T_BEGIN3(ns1, ns2, ns3) namespace std {
64 #define NLIB_DEFINE_STD_SWAP_T_BEGIN4(ns1, ns2, ns3, ns4) namespace std {
65 #define NLIB_DEFINE_STD_SWAP_T_END2(ns1, ns2) }
66 #define NLIB_DEFINE_STD_SWAP_T_END3(ns1, ns2, ns3) }
67 #define NLIB_DEFINE_STD_SWAP_T_END4(ns1, ns2, ns3, ns4) }
68 #endif
69 #if 1
70 #define NLIB_DEFINE_STD_SWAP_T1(targ1, tp) \
71  template<class targ1> \
72  NLIB_ALWAYS_INLINE void swap(tp<targ1>& lhs, tp<targ1>& rhs) { \
73  tp<targ1> x(lhs, nlib_ns::move_tag()); \
74  lhs.assign(rhs, nlib_ns::move_tag()); \
75  rhs.assign(x, nlib_ns::move_tag()); \
76  }
77 #define NLIB_DEFINE_STD_SWAP_T2(targ1, targ2, tp) \
78  template<class targ1, class targ2> \
79  NLIB_ALWAYS_INLINE void swap(tp<targ1, targ2>& lhs, tp<targ1, targ2>& rhs) { \
80  tp<targ1, targ2> x(lhs, nlib_ns::move_tag()); \
81  lhs.assign(rhs, nlib_ns::move_tag()); \
82  rhs.assign(x, nlib_ns::move_tag()); \
83  }
84 #else
85 #define NLIB_DEFINE_STD_SWAP_T1(targ1, tp) \
86  template<class targ1> \
87  NLIB_ALWAYS_INLINE void swap(tp<targ1>& lhs, tp<targ1>& rhs) { \
88  lhs.swap(rhs); \
89  }
90 #define NLIB_DEFINE_STD_SWAP_T2(targ1, targ2, tp) \
91  template<class targ1, class targ2> \
92  NLIB_ALWAYS_INLINE void swap(tp<targ1, targ2>& lhs, tp<targ1, targ2>& rhs) { \
93  lhs.swap(rhs); \
94  }
95 #endif
96 #endif
97 
98 #endif // INCLUDE_NN_NLIB_SWAP_H_
A file that contains the configuration information for each development environment.