bpair.h
Go to the documentation of this file.
1 /*--------------------------------------------------------------------------------------+
2 |
3 | Supplied under applicable software license agreement.
4 |
5 | Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved.
6 |
7 +---------------------------------------------------------------------------------------*/
8 #pragma once
9 
10 // -*- C++ -*-
11 /***************************************************************************
12  *
13  * _pair.h - definition of std::bpair
14  *
15  * $Id: _pair.h 538186 2007-05-15 14:23:59Z faridz $
16  *
17  ***************************************************************************
18  *
19  * Licensed to the Apache Software Foundation (ASF) under one or more
20  * contributor license agreements. See the NOTICE file distributed
21  * with this work for additional information regarding copyright
22  * ownership. The ASF licenses this file to you under the Apache
23  * License, Version 2.0 (the "License"); you may not use this file
24  * except in compliance with the License. You may obtain a copy of
25  * the License at
26  *
27  * http://www.apache.org/licenses/LICENSE-2.0
28  *
29  * Unless required by applicable law or agreed to in writing, software
30  * distributed under the License is distributed on an "AS IS" BASIS,
31  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
32  * implied. See the License for the specific language governing
33  * permissions and limitations under the License.
34  *
35  * Copyright 1994-2005 Rogue Wave Software.
36  *
37  ***************************************************************************
38  *
39  * Copyright (c) 1994
40  * Hewlett-Packard Company
41  *
42  * Permission to use, copy, modify, distribute and sell this software
43  * and its documentation for any purpose is hereby granted without fee,
44  * provided that the above copyright notice appear in all copies and
45  * that both that copyright notice and this permission notice appear
46  * in supporting documentation. Hewlett-Packard Company makes no
47  * representations about the suitability of this software for any
48  * purpose. It is provided "as is" without express or implied warranty.
49  *
50  **************************************************************************
51  *
52  * NOTICE: This File contains modifications made by Bentley Systems Inc. where designated.
53  *
54  *************************************************************************/
55 
56 #ifndef _RWSTD_RW_PAIR_H_INCLUDED
57 #define _RWSTD_RW_PAIR_H_INCLUDED
58 
59 // *** BENTLEY_CHANGE
61 
62 //#ifndef _RWSTD_RW_FUNCBASE_H_INCLUDED
63 //# include <rw/_funcbase.h> // for less
64 //#endif // _RWSTD_RW_FUNCBASE_H_INCLUDED
65 
66 
67 // *** BENTLEY_CHANGE
68 NAMESPACE_BENTLEY_BSTDCXX_BEGIN
69 
71 // 20.2.2
72 template <class _TypeT, class _TypeU>
73 struct bpair
74 {
75  typedef _TypeT first_type;
76  typedef _TypeU second_type;
77 
80 
81  // 20.2.2, p2
82  bpair ()
83 #ifndef _RWSTD_NO_EMPTY_MEM_INITIALIZER
84  : first (/* lwg issue 265 */), second () { }
85 #else
86  // assumes types satisfy the CopyConstructible requirements
87  : first (first_type ()), second (second_type ()) { }
88 #endif // _RWSTD_NO_EMPTY_MEM_INITIALIZER
89 
90  // 20.2.2, p3
91  bpair (const first_type &__x, const second_type &__y)
92  : first (__x), second (__y) { }
93 
94  // 20.2.2, p4
95  template <class _TypeX, class _TypeY>
96  bpair (const bpair <_TypeX, _TypeY> &__rhs)
97  : first (__rhs.first), second (__rhs.second) { }
98 
99  template <class _TypeX, class _TypeY,
100  typename std::enable_if<std::is_convertible<_TypeX, _TypeT>::value && std::is_convertible<_TypeY, _TypeY>::value, void>::type>
102  : first(std::forward<_TypeX>(__rhs.first)), second (std::forward<_TypeY>(__rhs.second)) { }
103 
104  template<class _TypeX, class _TypeY>
106  {
107  first = std::forward<_TypeX>(__rhs.first);
108  second = std::forward<_TypeY>(__rhs.second);
109  return (*this);
110  }
111 
112  // lwg issue 353
113  template <class _TypeX, class _TypeY>
115  return first = __rhs.first, second = __rhs.second, *this;
116  }
117 };
118 
119 // 20.2.2, p5
120 template <class _TypeT, class _TypeU>
121 inline bool
123 {
124  return __x.first == __y.first && __x.second == __y.second;
125 }
126 
127 
128 template <class _TypeT, class _TypeU>
129 inline bool
131 {
132  return !(__x == __y);
133 }
134 
135 
136 // 20.2.2, p6
137 template <class _TypeT, class _TypeU>
138 inline bool
139 operator< (const bpair<_TypeT, _TypeU>& __x, const bpair<_TypeT, _TypeU>& __y)
140 {
141  std::less<_TypeT> __lessT;
142 
143  // follows resolution of lwg issue 348
144  return __lessT (__x.first, __y.first)
145  || ( !__lessT (__y.first, __x.first)
146  && std::less<_TypeU>()(__x.second, __y.second));
147 }
148 
149 
150 template <class _TypeT, class _TypeU>
151 inline bool
153 {
154  return __y < __x;
155 }
156 
157 
158 template <class _TypeT, class _TypeU>
159 inline bool
161 {
162  return !(__x < __y);
163 }
164 
165 
166 template <class _TypeT, class _TypeU>
167 inline bool
168 operator<= (const bpair<_TypeT, _TypeU>& __x, const bpair<_TypeT, _TypeU>& __y)
169 {
170  return !(__y < __x);
171 }
172 
173 
174 // 20.2.2, p7, signature follows lwg issue 181
175 template <class _TypeT, class _TypeU>
177 make_bpair (_TypeT __x, _TypeU __y)
178 {
179  return bpair<_TypeT, _TypeU>(__x, __y);
180 }
181 
182 // *** BENTLEY_CHANGE
183 NAMESPACE_BENTLEY_BSTDCXX_END
184 
185 #endif // _RWSTD_RW_PAIR_H_INCLUDED
bool operator>=(const bpair< _TypeT, _TypeU > &__x, const bpair< _TypeT, _TypeU > &__y)
Definition: bpair.h:160
bool operator==(const bpair< _TypeT, _TypeU > &__x, const bpair< _TypeT, _TypeU > &__y)
Definition: bpair.h:122
first_type first
Definition: bpair.h:78
bool operator>(const bpair< _TypeT, _TypeU > &__x, const bpair< _TypeT, _TypeU > &__y)
Definition: bpair.h:152
bpair()
Definition: bpair.h:82
_TypeU second_type
Definition: bpair.h:76
A template that has many of the capabilities of std::pair.
Definition: bpair.h:73
bpair< _TypeT, _TypeU > & operator=(bpair< _TypeX, _TypeY > &&__rhs)
Definition: bpair.h:105
bpair(bpair< _TypeX, _TypeY > &&__rhs)
Definition: bpair.h:101
bpair< _TypeT, _TypeU > make_bpair(_TypeT __x, _TypeU __y)
Definition: bpair.h:177
second_type second
Definition: bpair.h:79
bpair(const first_type &__x, const second_type &__y)
Definition: bpair.h:91
bool operator!=(const bpair< _TypeT, _TypeU > &__x, const bpair< _TypeT, _TypeU > &__y)
Definition: bpair.h:130
_TypeT first_type
Definition: bpair.h:75
bpair(const bpair< _TypeX, _TypeY > &__rhs)
Definition: bpair.h:96

Copyright © 2017 Bentley Systems, Incorporated. All rights reserved.