| 1 |
//===--- MockHeaders.cpp - Mock headers for dataflow analyses -*- C++ ---*-===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
// |
| 9 |
// This file defines mock headers for testing of dataflow analyses. |
| 10 |
// |
| 11 |
//===----------------------------------------------------------------------===// |
| 12 |
|
| 13 |
#include "MockHeaders.h" |
| 14 |
|
| 15 |
namespace clang { |
| 16 |
namespace dataflow { |
| 17 |
namespace test { |
| 18 |
static constexpr char CStdDefHeader[] = R"( |
| 19 |
#ifndef CSTDDEF_H |
| 20 |
#define CSTDDEF_H |
| 21 |
|
| 22 |
namespace std { |
| 23 |
|
| 24 |
typedef decltype(sizeof(char)) size_t; |
| 25 |
|
| 26 |
using nullptr_t = decltype(nullptr); |
| 27 |
|
| 28 |
} // namespace std |
| 29 |
|
| 30 |
typedef decltype(sizeof(char)) size_t; |
| 31 |
typedef decltype(sizeof(char*)) ptrdiff_t; |
| 32 |
|
| 33 |
#endif // CSTDDEF_H |
| 34 |
)"; |
| 35 |
|
| 36 |
static constexpr char StdTypeTraitsHeader[] = R"( |
| 37 |
#ifndef STD_TYPE_TRAITS_H |
| 38 |
#define STD_TYPE_TRAITS_H |
| 39 |
|
| 40 |
#include "cstddef.h" |
| 41 |
|
| 42 |
namespace std { |
| 43 |
|
| 44 |
template <typename T, T V> |
| 45 |
struct integral_constant { |
| 46 |
static constexpr T value = V; |
| 47 |
}; |
| 48 |
|
| 49 |
using true_type = integral_constant<bool, true>; |
| 50 |
using false_type = integral_constant<bool, false>; |
| 51 |
|
| 52 |
template< class T > struct remove_reference {typedef T type;}; |
| 53 |
template< class T > struct remove_reference<T&> {typedef T type;}; |
| 54 |
template< class T > struct remove_reference<T&&> {typedef T type;}; |
| 55 |
|
| 56 |
template <class T> |
| 57 |
using remove_reference_t = typename remove_reference<T>::type; |
| 58 |
|
| 59 |
template <class T> |
| 60 |
struct remove_extent { |
| 61 |
typedef T type; |
| 62 |
}; |
| 63 |
|
| 64 |
template <class T> |
| 65 |
struct remove_extent<T[]> { |
| 66 |
typedef T type; |
| 67 |
}; |
| 68 |
|
| 69 |
template <class T, size_t N> |
| 70 |
struct remove_extent<T[N]> { |
| 71 |
typedef T type; |
| 72 |
}; |
| 73 |
|
| 74 |
template <class T> |
| 75 |
struct is_array : false_type {}; |
| 76 |
|
| 77 |
template <class T> |
| 78 |
struct is_array<T[]> : true_type {}; |
| 79 |
|
| 80 |
template <class T, size_t N> |
| 81 |
struct is_array<T[N]> : true_type {}; |
| 82 |
|
| 83 |
template <class> |
| 84 |
struct is_function : false_type {}; |
| 85 |
|
| 86 |
template <class Ret, class... Args> |
| 87 |
struct is_function<Ret(Args...)> : true_type {}; |
| 88 |
|
| 89 |
namespace detail { |
| 90 |
|
| 91 |
template <class T> |
| 92 |
struct type_identity { |
| 93 |
using type = T; |
| 94 |
}; // or use type_identity (since C++20) |
| 95 |
|
| 96 |
template <class T> |
| 97 |
auto try_add_pointer(int) -> type_identity<typename remove_reference<T>::type*>; |
| 98 |
template <class T> |
| 99 |
auto try_add_pointer(...) -> type_identity<T>; |
| 100 |
|
| 101 |
} // namespace detail |
| 102 |
|
| 103 |
template <class T> |
| 104 |
struct add_pointer : decltype(detail::try_add_pointer<T>(0)) {}; |
| 105 |
|
| 106 |
template <bool B, class T, class F> |
| 107 |
struct conditional { |
| 108 |
typedef T type; |
| 109 |
}; |
| 110 |
|
| 111 |
template <class T, class F> |
| 112 |
struct conditional<false, T, F> { |
| 113 |
typedef F type; |
| 114 |
}; |
| 115 |
|
| 116 |
template <class T> |
| 117 |
struct remove_cv { |
| 118 |
typedef T type; |
| 119 |
}; |
| 120 |
template <class T> |
| 121 |
struct remove_cv<const T> { |
| 122 |
typedef T type; |
| 123 |
}; |
| 124 |
template <class T> |
| 125 |
struct remove_cv<volatile T> { |
| 126 |
typedef T type; |
| 127 |
}; |
| 128 |
template <class T> |
| 129 |
struct remove_cv<const volatile T> { |
| 130 |
typedef T type; |
| 131 |
}; |
| 132 |
|
| 133 |
template <class T> |
| 134 |
using remove_cv_t = typename remove_cv<T>::type; |
| 135 |
|
| 136 |
template <class T> |
| 137 |
struct decay { |
| 138 |
private: |
| 139 |
typedef typename remove_reference<T>::type U; |
| 140 |
|
| 141 |
public: |
| 142 |
typedef typename conditional< |
| 143 |
is_array<U>::value, typename remove_extent<U>::type*, |
| 144 |
typename conditional<is_function<U>::value, typename add_pointer<U>::type, |
| 145 |
typename remove_cv<U>::type>::type>::type type; |
| 146 |
}; |
| 147 |
|
| 148 |
template <bool B, class T = void> |
| 149 |
struct enable_if {}; |
| 150 |
|
| 151 |
template <class T> |
| 152 |
struct enable_if<true, T> { |
| 153 |
typedef T type; |
| 154 |
}; |
| 155 |
|
| 156 |
template <bool B, class T = void> |
| 157 |
using enable_if_t = typename enable_if<B, T>::type; |
| 158 |
|
| 159 |
template <class T, class U> |
| 160 |
struct is_same : false_type {}; |
| 161 |
|
| 162 |
template <class T> |
| 163 |
struct is_same<T, T> : true_type {}; |
| 164 |
|
| 165 |
template <class T> |
| 166 |
struct is_void : is_same<void, typename remove_cv<T>::type> {}; |
| 167 |
|
| 168 |
namespace detail { |
| 169 |
|
| 170 |
template <class T> |
| 171 |
auto try_add_lvalue_reference(int) -> type_identity<T&>; |
| 172 |
template <class T> |
| 173 |
auto try_add_lvalue_reference(...) -> type_identity<T>; |
| 174 |
|
| 175 |
template <class T> |
| 176 |
auto try_add_rvalue_reference(int) -> type_identity<T&&>; |
| 177 |
template <class T> |
| 178 |
auto try_add_rvalue_reference(...) -> type_identity<T>; |
| 179 |
|
| 180 |
} // namespace detail |
| 181 |
|
| 182 |
template <class T> |
| 183 |
struct add_lvalue_reference : decltype(detail::try_add_lvalue_reference<T>(0)) { |
| 184 |
}; |
| 185 |
|
| 186 |
template <class T> |
| 187 |
struct add_rvalue_reference : decltype(detail::try_add_rvalue_reference<T>(0)) { |
| 188 |
}; |
| 189 |
|
| 190 |
template <class T> |
| 191 |
typename add_rvalue_reference<T>::type declval() noexcept; |
| 192 |
|
| 193 |
namespace detail { |
| 194 |
|
| 195 |
template <class T> |
| 196 |
auto test_returnable(int) |
| 197 |
-> decltype(void(static_cast<T (*)()>(nullptr)), true_type{}); |
| 198 |
template <class> |
| 199 |
auto test_returnable(...) -> false_type; |
| 200 |
|
| 201 |
template <class From, class To> |
| 202 |
auto test_implicitly_convertible(int) |
| 203 |
-> decltype(void(declval<void (&)(To)>()(declval<From>())), true_type{}); |
| 204 |
template <class, class> |
| 205 |
auto test_implicitly_convertible(...) -> false_type; |
| 206 |
|
| 207 |
} // namespace detail |
| 208 |
|
| 209 |
template <class From, class To> |
| 210 |
struct is_convertible |
| 211 |
: integral_constant<bool, |
| 212 |
(decltype(detail::test_returnable<To>(0))::value && |
| 213 |
decltype(detail::test_implicitly_convertible<From, To>( |
| 214 |
0))::value) || |
| 215 |
(is_void<From>::value && is_void<To>::value)> {}; |
| 216 |
|
| 217 |
template <class From, class To> |
| 218 |
inline constexpr bool is_convertible_v = is_convertible<From, To>::value; |
| 219 |
|
| 220 |
template <class...> |
| 221 |
using void_t = void; |
| 222 |
|
| 223 |
template <class, class T, class... Args> |
| 224 |
struct is_constructible_ : false_type {}; |
| 225 |
|
| 226 |
template <class T, class... Args> |
| 227 |
struct is_constructible_<void_t<decltype(T(declval<Args>()...))>, T, Args...> |
| 228 |
: true_type {}; |
| 229 |
|
| 230 |
template <class T, class... Args> |
| 231 |
using is_constructible = is_constructible_<void_t<>, T, Args...>; |
| 232 |
|
| 233 |
template <class T, class... Args> |
| 234 |
inline constexpr bool is_constructible_v = is_constructible<T, Args...>::value; |
| 235 |
|
| 236 |
template <class _Tp> |
| 237 |
struct __uncvref { |
| 238 |
typedef typename remove_cv<typename remove_reference<_Tp>::type>::type type; |
| 239 |
}; |
| 240 |
|
| 241 |
template <class _Tp> |
| 242 |
using __uncvref_t = typename __uncvref<_Tp>::type; |
| 243 |
|
| 244 |
template <bool _Val> |
| 245 |
using _BoolConstant = integral_constant<bool, _Val>; |
| 246 |
|
| 247 |
template <class _Tp, class _Up> |
| 248 |
using _IsSame = _BoolConstant<__is_same(_Tp, _Up)>; |
| 249 |
|
| 250 |
template <class _Tp, class _Up> |
| 251 |
using _IsNotSame = _BoolConstant<!__is_same(_Tp, _Up)>; |
| 252 |
|
| 253 |
template <bool> |
| 254 |
struct _MetaBase; |
| 255 |
template <> |
| 256 |
struct _MetaBase<true> { |
| 257 |
template <class _Tp, class _Up> |
| 258 |
using _SelectImpl = _Tp; |
| 259 |
template <template <class...> class _FirstFn, template <class...> class, |
| 260 |
class... _Args> |
| 261 |
using _SelectApplyImpl = _FirstFn<_Args...>; |
| 262 |
template <class _First, class...> |
| 263 |
using _FirstImpl = _First; |
| 264 |
template <class, class _Second, class...> |
| 265 |
using _SecondImpl = _Second; |
| 266 |
template <class _Result, class _First, class... _Rest> |
| 267 |
using _OrImpl = |
| 268 |
typename _MetaBase<_First::value != true && sizeof...(_Rest) != 0>:: |
| 269 |
template _OrImpl<_First, _Rest...>; |
| 270 |
}; |
| 271 |
|
| 272 |
template <> |
| 273 |
struct _MetaBase<false> { |
| 274 |
template <class _Tp, class _Up> |
| 275 |
using _SelectImpl = _Up; |
| 276 |
template <template <class...> class, template <class...> class _SecondFn, |
| 277 |
class... _Args> |
| 278 |
using _SelectApplyImpl = _SecondFn<_Args...>; |
| 279 |
template <class _Result, class...> |
| 280 |
using _OrImpl = _Result; |
| 281 |
}; |
| 282 |
|
| 283 |
template <bool _Cond, class _IfRes, class _ElseRes> |
| 284 |
using _If = typename _MetaBase<_Cond>::template _SelectImpl<_IfRes, _ElseRes>; |
| 285 |
|
| 286 |
template <class... _Rest> |
| 287 |
using _Or = typename _MetaBase<sizeof...(_Rest) != |
| 288 |
0>::template _OrImpl<false_type, _Rest...>; |
| 289 |
|
| 290 |
template <bool _Bp, class _Tp = void> |
| 291 |
using __enable_if_t = typename enable_if<_Bp, _Tp>::type; |
| 292 |
|
| 293 |
template <class...> |
| 294 |
using __expand_to_true = true_type; |
| 295 |
template <class... _Pred> |
| 296 |
__expand_to_true<__enable_if_t<_Pred::value>...> __and_helper(int); |
| 297 |
template <class...> |
| 298 |
false_type __and_helper(...); |
| 299 |
template <class... _Pred> |
| 300 |
using _And = decltype(__and_helper<_Pred...>(0)); |
| 301 |
|
| 302 |
template <class _Pred> |
| 303 |
struct _Not : _BoolConstant<!_Pred::value> {}; |
| 304 |
|
| 305 |
struct __check_tuple_constructor_fail { |
| 306 |
static constexpr bool __enable_explicit_default() { return false; } |
| 307 |
static constexpr bool __enable_implicit_default() { return false; } |
| 308 |
template <class...> |
| 309 |
static constexpr bool __enable_explicit() { |
| 310 |
return false; |
| 311 |
} |
| 312 |
template <class...> |
| 313 |
static constexpr bool __enable_implicit() { |
| 314 |
return false; |
| 315 |
} |
| 316 |
}; |
| 317 |
|
| 318 |
template <typename, typename _Tp> |
| 319 |
struct __select_2nd { |
| 320 |
typedef _Tp type; |
| 321 |
}; |
| 322 |
template <class _Tp, class _Arg> |
| 323 |
typename __select_2nd<decltype((declval<_Tp>() = declval<_Arg>())), |
| 324 |
true_type>::type |
| 325 |
__is_assignable_test(int); |
| 326 |
template <class, class> |
| 327 |
false_type __is_assignable_test(...); |
| 328 |
template <class _Tp, class _Arg, |
| 329 |
bool = is_void<_Tp>::value || is_void<_Arg>::value> |
| 330 |
struct __is_assignable_imp |
| 331 |
: public decltype((__is_assignable_test<_Tp, _Arg>(0))) {}; |
| 332 |
template <class _Tp, class _Arg> |
| 333 |
struct __is_assignable_imp<_Tp, _Arg, true> : public false_type {}; |
| 334 |
template <class _Tp, class _Arg> |
| 335 |
struct is_assignable : public __is_assignable_imp<_Tp, _Arg> {}; |
| 336 |
|
| 337 |
template <class _Tp> |
| 338 |
struct __libcpp_is_integral : public false_type {}; |
| 339 |
template <> |
| 340 |
struct __libcpp_is_integral<bool> : public true_type {}; |
| 341 |
template <> |
| 342 |
struct __libcpp_is_integral<char> : public true_type {}; |
| 343 |
template <> |
| 344 |
struct __libcpp_is_integral<signed char> : public true_type {}; |
| 345 |
template <> |
| 346 |
struct __libcpp_is_integral<unsigned char> : public true_type {}; |
| 347 |
template <> |
| 348 |
struct __libcpp_is_integral<wchar_t> : public true_type {}; |
| 349 |
template <> |
| 350 |
struct __libcpp_is_integral<short> : public true_type {}; // NOLINT |
| 351 |
template <> |
| 352 |
struct __libcpp_is_integral<unsigned short> : public true_type {}; // NOLINT |
| 353 |
template <> |
| 354 |
struct __libcpp_is_integral<int> : public true_type {}; |
| 355 |
template <> |
| 356 |
struct __libcpp_is_integral<unsigned int> : public true_type {}; |
| 357 |
template <> |
| 358 |
struct __libcpp_is_integral<long> : public true_type {}; // NOLINT |
| 359 |
template <> |
| 360 |
struct __libcpp_is_integral<unsigned long> : public true_type {}; // NOLINT |
| 361 |
template <> |
| 362 |
struct __libcpp_is_integral<long long> : public true_type {}; // NOLINT |
| 363 |
template <> // NOLINTNEXTLINE |
| 364 |
struct __libcpp_is_integral<unsigned long long> : public true_type {}; |
| 365 |
template <class _Tp> |
| 366 |
struct is_integral |
| 367 |
: public __libcpp_is_integral<typename remove_cv<_Tp>::type> {}; |
| 368 |
|
| 369 |
template <class _Tp> |
| 370 |
struct __libcpp_is_floating_point : public false_type {}; |
| 371 |
template <> |
| 372 |
struct __libcpp_is_floating_point<float> : public true_type {}; |
| 373 |
template <> |
| 374 |
struct __libcpp_is_floating_point<double> : public true_type {}; |
| 375 |
template <> |
| 376 |
struct __libcpp_is_floating_point<long double> : public true_type {}; |
| 377 |
template <class _Tp> |
| 378 |
struct is_floating_point |
| 379 |
: public __libcpp_is_floating_point<typename remove_cv<_Tp>::type> {}; |
| 380 |
|
| 381 |
template <class _Tp> |
| 382 |
struct is_arithmetic |
| 383 |
: public integral_constant<bool, is_integral<_Tp>::value || |
| 384 |
is_floating_point<_Tp>::value> {}; |
| 385 |
|
| 386 |
template <class _Tp> |
| 387 |
struct __libcpp_is_pointer : public false_type {}; |
| 388 |
template <class _Tp> |
| 389 |
struct __libcpp_is_pointer<_Tp*> : public true_type {}; |
| 390 |
template <class _Tp> |
| 391 |
struct is_pointer : public __libcpp_is_pointer<typename remove_cv<_Tp>::type> { |
| 392 |
}; |
| 393 |
|
| 394 |
template <class _Tp> |
| 395 |
struct __libcpp_is_member_pointer : public false_type {}; |
| 396 |
template <class _Tp, class _Up> |
| 397 |
struct __libcpp_is_member_pointer<_Tp _Up::*> : public true_type {}; |
| 398 |
template <class _Tp> |
| 399 |
struct is_member_pointer |
| 400 |
: public __libcpp_is_member_pointer<typename remove_cv<_Tp>::type> {}; |
| 401 |
|
| 402 |
template <class _Tp> |
| 403 |
struct __libcpp_union : public false_type {}; |
| 404 |
template <class _Tp> |
| 405 |
struct is_union : public __libcpp_union<typename remove_cv<_Tp>::type> {}; |
| 406 |
|
| 407 |
template <class T> |
| 408 |
struct is_reference : false_type {}; |
| 409 |
template <class T> |
| 410 |
struct is_reference<T&> : true_type {}; |
| 411 |
template <class T> |
| 412 |
struct is_reference<T&&> : true_type {}; |
| 413 |
|
| 414 |
template <class T> |
| 415 |
inline constexpr bool is_reference_v = is_reference<T>::value; |
| 416 |
|
| 417 |
struct __two { |
| 418 |
char __lx[2]; |
| 419 |
}; |
| 420 |
|
| 421 |
namespace __is_class_imp { |
| 422 |
template <class _Tp> |
| 423 |
char __test(int _Tp::*); |
| 424 |
template <class _Tp> |
| 425 |
__two __test(...); |
| 426 |
} // namespace __is_class_imp |
| 427 |
template <class _Tp> |
| 428 |
struct is_class |
| 429 |
: public integral_constant<bool, |
| 430 |
sizeof(__is_class_imp::__test<_Tp>(0)) == 1 && |
| 431 |
!is_union<_Tp>::value> {}; |
| 432 |
|
| 433 |
template <class _Tp> |
| 434 |
struct __is_nullptr_t_impl : public false_type {}; |
| 435 |
template <> |
| 436 |
struct __is_nullptr_t_impl<nullptr_t> : public true_type {}; |
| 437 |
template <class _Tp> |
| 438 |
struct __is_nullptr_t |
| 439 |
: public __is_nullptr_t_impl<typename remove_cv<_Tp>::type> {}; |
| 440 |
template <class _Tp> |
| 441 |
struct is_null_pointer |
| 442 |
: public __is_nullptr_t_impl<typename remove_cv<_Tp>::type> {}; |
| 443 |
|
| 444 |
template <class _Tp> |
| 445 |
struct is_enum |
| 446 |
: public integral_constant< |
| 447 |
bool, !is_void<_Tp>::value && !is_integral<_Tp>::value && |
| 448 |
!is_floating_point<_Tp>::value && !is_array<_Tp>::value && |
| 449 |
!is_pointer<_Tp>::value && !is_reference<_Tp>::value && |
| 450 |
!is_member_pointer<_Tp>::value && !is_union<_Tp>::value && |
| 451 |
!is_class<_Tp>::value && !is_function<_Tp>::value> {}; |
| 452 |
|
| 453 |
template <class _Tp> |
| 454 |
struct is_scalar |
| 455 |
: public integral_constant< |
| 456 |
bool, is_arithmetic<_Tp>::value || is_member_pointer<_Tp>::value || |
| 457 |
is_pointer<_Tp>::value || __is_nullptr_t<_Tp>::value || |
| 458 |
is_enum<_Tp>::value> {}; |
| 459 |
template <> |
| 460 |
struct is_scalar<nullptr_t> : public true_type {}; |
| 461 |
|
| 462 |
struct in_place_t {}; |
| 463 |
|
| 464 |
constexpr in_place_t in_place; |
| 465 |
|
| 466 |
} // namespace std |
| 467 |
|
| 468 |
#endif // STD_TYPE_TRAITS_H |
| 469 |
)"; |
| 470 |
|
| 471 |
static constexpr char AbslTypeTraitsHeader[] = R"( |
| 472 |
#ifndef ABSL_TYPE_TRAITS_H |
| 473 |
#define ABSL_TYPE_TRAITS_H |
| 474 |
|
| 475 |
#include "std_type_traits.h" |
| 476 |
|
| 477 |
namespace absl { |
| 478 |
|
| 479 |
template <typename... Ts> |
| 480 |
struct conjunction : std::true_type {}; |
| 481 |
|
| 482 |
template <typename T, typename... Ts> |
| 483 |
struct conjunction<T, Ts...> |
| 484 |
: std::conditional<T::value, conjunction<Ts...>, T>::type {}; |
| 485 |
|
| 486 |
template <typename T> |
| 487 |
struct conjunction<T> : T {}; |
| 488 |
|
| 489 |
template <typename... Ts> |
| 490 |
struct disjunction : std::false_type {}; |
| 491 |
|
| 492 |
template <typename T, typename... Ts> |
| 493 |
struct disjunction<T, Ts...> |
| 494 |
: std::conditional<T::value, T, disjunction<Ts...>>::type {}; |
| 495 |
|
| 496 |
template <typename T> |
| 497 |
struct disjunction<T> : T {}; |
| 498 |
|
| 499 |
template <typename T> |
| 500 |
struct negation : std::integral_constant<bool, !T::value> {}; |
| 501 |
|
| 502 |
template <bool B, typename T = void> |
| 503 |
using enable_if_t = typename std::enable_if<B, T>::type; |
| 504 |
|
| 505 |
|
| 506 |
template <bool B, typename T, typename F> |
| 507 |
using conditional_t = typename std::conditional<B, T, F>::type; |
| 508 |
|
| 509 |
template <typename T> |
| 510 |
using remove_cv_t = typename std::remove_cv<T>::type; |
| 511 |
|
| 512 |
template <typename T> |
| 513 |
using remove_reference_t = typename std::remove_reference<T>::type; |
| 514 |
|
| 515 |
template <typename T> |
| 516 |
using decay_t = typename std::decay<T>::type; |
| 517 |
|
| 518 |
using std::in_place; |
| 519 |
using std::in_place_t; |
| 520 |
} // namespace absl |
| 521 |
|
| 522 |
#endif // ABSL_TYPE_TRAITS_H |
| 523 |
)"; |
| 524 |
|
| 525 |
static constexpr char StdStringHeader[] = R"( |
| 526 |
#ifndef STRING_H |
| 527 |
#define STRING_H |
| 528 |
|
| 529 |
namespace std { |
| 530 |
|
| 531 |
struct string { |
| 532 |
string(const char*); |
| 533 |
~string(); |
| 534 |
const char *c_str() const; |
| 535 |
bool empty(); |
| 536 |
}; |
| 537 |
|
| 538 |
struct string_view { |
| 539 |
string_view(const char*); |
| 540 |
~string_view(); |
| 541 |
bool empty(); |
| 542 |
}; |
| 543 |
|
| 544 |
bool operator!=(const string &LHS, const char *RHS); |
| 545 |
|
| 546 |
} // namespace std |
| 547 |
|
| 548 |
#endif // STRING_H |
| 549 |
)"; |
| 550 |
|
| 551 |
static constexpr char StdUtilityHeader[] = R"( |
| 552 |
#ifndef UTILITY_H |
| 553 |
#define UTILITY_H |
| 554 |
|
| 555 |
#include "std_type_traits.h" |
| 556 |
|
| 557 |
namespace std { |
| 558 |
|
| 559 |
template <typename T> |
| 560 |
constexpr remove_reference_t<T>&& move(T&& x); |
| 561 |
|
| 562 |
template <typename T> |
| 563 |
void swap(T& a, T& b) noexcept; |
| 564 |
|
| 565 |
} // namespace std |
| 566 |
|
| 567 |
#endif // UTILITY_H |
| 568 |
)"; |
| 569 |
|
| 570 |
static constexpr char StdInitializerListHeader[] = R"( |
| 571 |
#ifndef INITIALIZER_LIST_H |
| 572 |
#define INITIALIZER_LIST_H |
| 573 |
|
| 574 |
namespace std { |
| 575 |
|
| 576 |
template <typename T> |
| 577 |
class initializer_list { |
| 578 |
public: |
| 579 |
const T *a, *b; |
| 580 |
initializer_list() noexcept; |
| 581 |
}; |
| 582 |
|
| 583 |
} // namespace std |
| 584 |
|
| 585 |
#endif // INITIALIZER_LIST_H |
| 586 |
)"; |
| 587 |
|
| 588 |
static constexpr char StdOptionalHeader[] = R"( |
| 589 |
#include "std_initializer_list.h" |
| 590 |
#include "std_type_traits.h" |
| 591 |
#include "std_utility.h" |
| 592 |
|
| 593 |
namespace std { |
| 594 |
|
| 595 |
struct nullopt_t { |
| 596 |
constexpr explicit nullopt_t() {} |
| 597 |
}; |
| 598 |
constexpr nullopt_t nullopt; |
| 599 |
|
| 600 |
template <class _Tp> |
| 601 |
struct __optional_destruct_base { |
| 602 |
constexpr void reset() noexcept; |
| 603 |
}; |
| 604 |
|
| 605 |
template <class _Tp> |
| 606 |
struct __optional_storage_base : __optional_destruct_base<_Tp> { |
| 607 |
constexpr bool has_value() const noexcept; |
| 608 |
}; |
| 609 |
|
| 610 |
template <typename _Tp> |
| 611 |
class optional : private __optional_storage_base<_Tp> { |
| 612 |
using __base = __optional_storage_base<_Tp>; |
| 613 |
|
| 614 |
public: |
| 615 |
using value_type = _Tp; |
| 616 |
|
| 617 |
private: |
| 618 |
struct _CheckOptionalArgsConstructor { |
| 619 |
template <class _Up> |
| 620 |
static constexpr bool __enable_implicit() { |
| 621 |
return is_constructible_v<_Tp, _Up&&> && is_convertible_v<_Up&&, _Tp>; |
| 622 |
} |
| 623 |
|
| 624 |
template <class _Up> |
| 625 |
static constexpr bool __enable_explicit() { |
| 626 |
return is_constructible_v<_Tp, _Up&&> && !is_convertible_v<_Up&&, _Tp>; |
| 627 |
} |
| 628 |
}; |
| 629 |
template <class _Up> |
| 630 |
using _CheckOptionalArgsCtor = |
| 631 |
_If<_IsNotSame<__uncvref_t<_Up>, in_place_t>::value && |
| 632 |
_IsNotSame<__uncvref_t<_Up>, optional>::value, |
| 633 |
_CheckOptionalArgsConstructor, __check_tuple_constructor_fail>; |
| 634 |
template <class _QualUp> |
| 635 |
struct _CheckOptionalLikeConstructor { |
| 636 |
template <class _Up, class _Opt = optional<_Up>> |
| 637 |
using __check_constructible_from_opt = |
| 638 |
_Or<is_constructible<_Tp, _Opt&>, is_constructible<_Tp, _Opt const&>, |
| 639 |
is_constructible<_Tp, _Opt&&>, is_constructible<_Tp, _Opt const&&>, |
| 640 |
is_convertible<_Opt&, _Tp>, is_convertible<_Opt const&, _Tp>, |
| 641 |
is_convertible<_Opt&&, _Tp>, is_convertible<_Opt const&&, _Tp>>; |
| 642 |
template <class _Up, class _QUp = _QualUp> |
| 643 |
static constexpr bool __enable_implicit() { |
| 644 |
return is_convertible<_QUp, _Tp>::value && |
| 645 |
!__check_constructible_from_opt<_Up>::value; |
| 646 |
} |
| 647 |
template <class _Up, class _QUp = _QualUp> |
| 648 |
static constexpr bool __enable_explicit() { |
| 649 |
return !is_convertible<_QUp, _Tp>::value && |
| 650 |
!__check_constructible_from_opt<_Up>::value; |
| 651 |
} |
| 652 |
}; |
| 653 |
|
| 654 |
template <class _Up, class _QualUp> |
| 655 |
using _CheckOptionalLikeCtor = |
| 656 |
_If<_And<_IsNotSame<_Up, _Tp>, is_constructible<_Tp, _QualUp>>::value, |
| 657 |
_CheckOptionalLikeConstructor<_QualUp>, |
| 658 |
__check_tuple_constructor_fail>; |
| 659 |
|
| 660 |
|
| 661 |
template <class _Up, class _QualUp> |
| 662 |
using _CheckOptionalLikeAssign = _If< |
| 663 |
_And< |
| 664 |
_IsNotSame<_Up, _Tp>, |
| 665 |
is_constructible<_Tp, _QualUp>, |
| 666 |
is_assignable<_Tp&, _QualUp> |
| 667 |
>::value, |
| 668 |
_CheckOptionalLikeConstructor<_QualUp>, |
| 669 |
__check_tuple_constructor_fail |
| 670 |
>; |
| 671 |
|
| 672 |
public: |
| 673 |
constexpr optional() noexcept {} |
| 674 |
constexpr optional(const optional&) = default; |
| 675 |
constexpr optional(optional&&) = default; |
| 676 |
constexpr optional(nullopt_t) noexcept {} |
| 677 |
|
| 678 |
template < |
| 679 |
class _InPlaceT, class... _Args, |
| 680 |
class = enable_if_t<_And<_IsSame<_InPlaceT, in_place_t>, |
| 681 |
is_constructible<value_type, _Args...>>::value>> |
| 682 |
constexpr explicit optional(_InPlaceT, _Args&&... __args); |
| 683 |
|
| 684 |
template <class _Up, class... _Args, |
| 685 |
class = enable_if_t<is_constructible_v< |
| 686 |
value_type, initializer_list<_Up>&, _Args...>>> |
| 687 |
constexpr explicit optional(in_place_t, initializer_list<_Up> __il, |
| 688 |
_Args&&... __args); |
| 689 |
|
| 690 |
template < |
| 691 |
class _Up = value_type, |
| 692 |
enable_if_t<_CheckOptionalArgsCtor<_Up>::template __enable_implicit<_Up>(), |
| 693 |
int> = 0> |
| 694 |
constexpr optional(_Up&& __v); |
| 695 |
|
| 696 |
template < |
| 697 |
class _Up, |
| 698 |
enable_if_t<_CheckOptionalArgsCtor<_Up>::template __enable_explicit<_Up>(), |
| 699 |
int> = 0> |
| 700 |
constexpr explicit optional(_Up&& __v); |
| 701 |
|
| 702 |
template <class _Up, enable_if_t<_CheckOptionalLikeCtor<_Up, _Up const&>:: |
| 703 |
template __enable_implicit<_Up>(), |
| 704 |
int> = 0> |
| 705 |
constexpr optional(const optional<_Up>& __v); |
| 706 |
|
| 707 |
template <class _Up, enable_if_t<_CheckOptionalLikeCtor<_Up, _Up const&>:: |
| 708 |
template __enable_explicit<_Up>(), |
| 709 |
int> = 0> |
| 710 |
constexpr explicit optional(const optional<_Up>& __v); |
| 711 |
|
| 712 |
template <class _Up, enable_if_t<_CheckOptionalLikeCtor<_Up, _Up&&>:: |
| 713 |
template __enable_implicit<_Up>(), |
| 714 |
int> = 0> |
| 715 |
constexpr optional(optional<_Up>&& __v); |
| 716 |
|
| 717 |
template <class _Up, enable_if_t<_CheckOptionalLikeCtor<_Up, _Up&&>:: |
| 718 |
template __enable_explicit<_Up>(), |
| 719 |
int> = 0> |
| 720 |
constexpr explicit optional(optional<_Up>&& __v); |
| 721 |
|
| 722 |
constexpr optional& operator=(nullopt_t) noexcept; |
| 723 |
|
| 724 |
optional& operator=(const optional&); |
| 725 |
|
| 726 |
optional& operator=(optional&&); |
| 727 |
|
| 728 |
template <class _Up = value_type, |
| 729 |
class = enable_if_t<_And<_IsNotSame<__uncvref_t<_Up>, optional>, |
| 730 |
_Or<_IsNotSame<__uncvref_t<_Up>, value_type>, |
| 731 |
_Not<is_scalar<value_type>>>, |
| 732 |
is_constructible<value_type, _Up>, |
| 733 |
is_assignable<value_type&, _Up>>::value>> |
| 734 |
constexpr optional& operator=(_Up&& __v); |
| 735 |
|
| 736 |
template <class _Up, enable_if_t<_CheckOptionalLikeAssign<_Up, _Up const&>:: |
| 737 |
template __enable_assign<_Up>(), |
| 738 |
int> = 0> |
| 739 |
constexpr optional& operator=(const optional<_Up>& __v); |
| 740 |
|
| 741 |
template <class _Up, enable_if_t<_CheckOptionalLikeCtor<_Up, _Up&&>:: |
| 742 |
template __enable_assign<_Up>(), |
| 743 |
int> = 0> |
| 744 |
constexpr optional& operator=(optional<_Up>&& __v); |
| 745 |
|
| 746 |
const _Tp& operator*() const&; |
| 747 |
_Tp& operator*() &; |
| 748 |
const _Tp&& operator*() const&&; |
| 749 |
_Tp&& operator*() &&; |
| 750 |
|
| 751 |
const _Tp* operator->() const; |
| 752 |
_Tp* operator->(); |
| 753 |
|
| 754 |
const _Tp& value() const&; |
| 755 |
_Tp& value() &; |
| 756 |
const _Tp&& value() const&&; |
| 757 |
_Tp&& value() &&; |
| 758 |
|
| 759 |
template <typename U> |
| 760 |
constexpr _Tp value_or(U&& v) const&; |
| 761 |
template <typename U> |
| 762 |
_Tp value_or(U&& v) &&; |
| 763 |
|
| 764 |
template <typename... Args> |
| 765 |
_Tp& emplace(Args&&... args); |
| 766 |
|
| 767 |
template <typename U, typename... Args> |
| 768 |
_Tp& emplace(std::initializer_list<U> ilist, Args&&... args); |
| 769 |
|
| 770 |
using __base::reset; |
| 771 |
|
| 772 |
constexpr explicit operator bool() const noexcept; |
| 773 |
using __base::has_value; |
| 774 |
|
| 775 |
constexpr void swap(optional& __opt) noexcept; |
| 776 |
}; |
| 777 |
|
| 778 |
template <typename T> |
| 779 |
constexpr optional<typename std::decay<T>::type> make_optional(T&& v); |
| 780 |
|
| 781 |
template <typename T, typename... Args> |
| 782 |
constexpr optional<T> make_optional(Args&&... args); |
| 783 |
|
| 784 |
template <typename T, typename U, typename... Args> |
| 785 |
constexpr optional<T> make_optional(std::initializer_list<U> il, |
| 786 |
Args&&... args); |
| 787 |
|
| 788 |
template <typename T, typename U> |
| 789 |
constexpr bool operator==(const optional<T> &lhs, const optional<U> &rhs); |
| 790 |
template <typename T, typename U> |
| 791 |
constexpr bool operator!=(const optional<T> &lhs, const optional<U> &rhs); |
| 792 |
|
| 793 |
template <typename T> |
| 794 |
constexpr bool operator==(const optional<T> &opt, nullopt_t); |
| 795 |
|
| 796 |
// C++20 and later do not define the following overloads because they are |
| 797 |
// provided by rewritten candidates instead. |
| 798 |
#if __cplusplus < 202002L |
| 799 |
template <typename T> |
| 800 |
constexpr bool operator==(nullopt_t, const optional<T> &opt); |
| 801 |
template <typename T> |
| 802 |
constexpr bool operator!=(const optional<T> &opt, nullopt_t); |
| 803 |
template <typename T> |
| 804 |
constexpr bool operator!=(nullopt_t, const optional<T> &opt); |
| 805 |
#endif // __cplusplus < 202002L |
| 806 |
|
| 807 |
template <typename T, typename U> |
| 808 |
constexpr bool operator==(const optional<T> &opt, const U &value); |
| 809 |
template <typename T, typename U> |
| 810 |
constexpr bool operator==(const T &value, const optional<U> &opt); |
| 811 |
template <typename T, typename U> |
| 812 |
constexpr bool operator!=(const optional<T> &opt, const U &value); |
| 813 |
template <typename T, typename U> |
| 814 |
constexpr bool operator!=(const T &value, const optional<U> &opt); |
| 815 |
|
| 816 |
} // namespace std |
| 817 |
)"; |
| 818 |
|
| 819 |
static constexpr char AbslOptionalHeader[] = R"( |
| 820 |
#include "absl_type_traits.h" |
| 821 |
#include "std_initializer_list.h" |
| 822 |
#include "std_type_traits.h" |
| 823 |
#include "std_utility.h" |
| 824 |
|
| 825 |
namespace absl { |
| 826 |
|
| 827 |
struct nullopt_t { |
| 828 |
constexpr explicit nullopt_t() {} |
| 829 |
}; |
| 830 |
constexpr nullopt_t nullopt; |
| 831 |
|
| 832 |
template <typename T> |
| 833 |
class optional; |
| 834 |
|
| 835 |
namespace optional_internal { |
| 836 |
|
| 837 |
template <typename T, typename U> |
| 838 |
struct is_constructible_convertible_from_optional |
| 839 |
: std::integral_constant< |
| 840 |
bool, std::is_constructible<T, optional<U>&>::value || |
| 841 |
std::is_constructible<T, optional<U>&&>::value || |
| 842 |
std::is_constructible<T, const optional<U>&>::value || |
| 843 |
std::is_constructible<T, const optional<U>&&>::value || |
| 844 |
std::is_convertible<optional<U>&, T>::value || |
| 845 |
std::is_convertible<optional<U>&&, T>::value || |
| 846 |
std::is_convertible<const optional<U>&, T>::value || |
| 847 |
std::is_convertible<const optional<U>&&, T>::value> {}; |
| 848 |
|
| 849 |
template <typename T, typename U> |
| 850 |
struct is_constructible_convertible_assignable_from_optional |
| 851 |
: std::integral_constant< |
| 852 |
bool, is_constructible_convertible_from_optional<T, U>::value || |
| 853 |
std::is_assignable<T&, optional<U>&>::value || |
| 854 |
std::is_assignable<T&, optional<U>&&>::value || |
| 855 |
std::is_assignable<T&, const optional<U>&>::value || |
| 856 |
std::is_assignable<T&, const optional<U>&&>::value> {}; |
| 857 |
|
| 858 |
} // namespace optional_internal |
| 859 |
|
| 860 |
template <typename T> |
| 861 |
class optional { |
| 862 |
public: |
| 863 |
constexpr optional() noexcept; |
| 864 |
|
| 865 |
constexpr optional(nullopt_t) noexcept; |
| 866 |
|
| 867 |
optional(const optional&) = default; |
| 868 |
|
| 869 |
optional(optional&&) = default; |
| 870 |
|
| 871 |
template <typename InPlaceT, typename... Args, |
| 872 |
absl::enable_if_t<absl::conjunction< |
| 873 |
std::is_same<InPlaceT, in_place_t>, |
| 874 |
std::is_constructible<T, Args&&...>>::value>* = nullptr> |
| 875 |
constexpr explicit optional(InPlaceT, Args&&... args); |
| 876 |
|
| 877 |
template <typename U, typename... Args, |
| 878 |
typename = typename std::enable_if<std::is_constructible< |
| 879 |
T, std::initializer_list<U>&, Args&&...>::value>::type> |
| 880 |
constexpr explicit optional(in_place_t, std::initializer_list<U> il, |
| 881 |
Args&&... args); |
| 882 |
|
| 883 |
template < |
| 884 |
typename U = T, |
| 885 |
typename std::enable_if< |
| 886 |
absl::conjunction<absl::negation<std::is_same< |
| 887 |
in_place_t, typename std::decay<U>::type>>, |
| 888 |
absl::negation<std::is_same< |
| 889 |
optional<T>, typename std::decay<U>::type>>, |
| 890 |
std::is_convertible<U&&, T>, |
| 891 |
std::is_constructible<T, U&&>>::value, |
| 892 |
bool>::type = false> |
| 893 |
constexpr optional(U&& v); |
| 894 |
|
| 895 |
template < |
| 896 |
typename U = T, |
| 897 |
typename std::enable_if< |
| 898 |
absl::conjunction<absl::negation<std::is_same< |
| 899 |
in_place_t, typename std::decay<U>::type>>, |
| 900 |
absl::negation<std::is_same< |
| 901 |
optional<T>, typename std::decay<U>::type>>, |
| 902 |
absl::negation<std::is_convertible<U&&, T>>, |
| 903 |
std::is_constructible<T, U&&>>::value, |
| 904 |
bool>::type = false> |
| 905 |
explicit constexpr optional(U&& v); |
| 906 |
|
| 907 |
template <typename U, |
| 908 |
typename std::enable_if< |
| 909 |
absl::conjunction< |
| 910 |
absl::negation<std::is_same<T, U>>, |
| 911 |
std::is_constructible<T, const U&>, |
| 912 |
absl::negation< |
| 913 |
optional_internal:: |
| 914 |
is_constructible_convertible_from_optional<T, U>>, |
| 915 |
std::is_convertible<const U&, T>>::value, |
| 916 |
bool>::type = false> |
| 917 |
optional(const optional<U>& rhs); |
| 918 |
|
| 919 |
template <typename U, |
| 920 |
typename std::enable_if< |
| 921 |
absl::conjunction< |
| 922 |
absl::negation<std::is_same<T, U>>, |
| 923 |
std::is_constructible<T, const U&>, |
| 924 |
absl::negation< |
| 925 |
optional_internal:: |
| 926 |
is_constructible_convertible_from_optional<T, U>>, |
| 927 |
absl::negation<std::is_convertible<const U&, T>>>::value, |
| 928 |
bool>::type = false> |
| 929 |
explicit optional(const optional<U>& rhs); |
| 930 |
|
| 931 |
template < |
| 932 |
typename U, |
| 933 |
typename std::enable_if< |
| 934 |
absl::conjunction< |
| 935 |
absl::negation<std::is_same<T, U>>, std::is_constructible<T, U&&>, |
| 936 |
absl::negation< |
| 937 |
optional_internal::is_constructible_convertible_from_optional< |
| 938 |
T, U>>, |
| 939 |
std::is_convertible<U&&, T>>::value, |
| 940 |
bool>::type = false> |
| 941 |
optional(optional<U>&& rhs); |
| 942 |
|
| 943 |
template < |
| 944 |
typename U, |
| 945 |
typename std::enable_if< |
| 946 |
absl::conjunction< |
| 947 |
absl::negation<std::is_same<T, U>>, std::is_constructible<T, U&&>, |
| 948 |
absl::negation< |
| 949 |
optional_internal::is_constructible_convertible_from_optional< |
| 950 |
T, U>>, |
| 951 |
absl::negation<std::is_convertible<U&&, T>>>::value, |
| 952 |
bool>::type = false> |
| 953 |
explicit optional(optional<U>&& rhs); |
| 954 |
|
| 955 |
optional& operator=(nullopt_t) noexcept; |
| 956 |
|
| 957 |
optional& operator=(const optional& src); |
| 958 |
|
| 959 |
optional& operator=(optional&& src); |
| 960 |
|
| 961 |
template < |
| 962 |
typename U = T, |
| 963 |
typename = typename std::enable_if<absl::conjunction< |
| 964 |
absl::negation< |
| 965 |
std::is_same<optional<T>, typename std::decay<U>::type>>, |
| 966 |
absl::negation< |
| 967 |
absl::conjunction<std::is_scalar<T>, |
| 968 |
std::is_same<T, typename std::decay<U>::type>>>, |
| 969 |
std::is_constructible<T, U>, std::is_assignable<T&, U>>::value>::type> |
| 970 |
optional& operator=(U&& v); |
| 971 |
|
| 972 |
template < |
| 973 |
typename U, |
| 974 |
typename = typename std::enable_if<absl::conjunction< |
| 975 |
absl::negation<std::is_same<T, U>>, |
| 976 |
std::is_constructible<T, const U&>, std::is_assignable<T&, const U&>, |
| 977 |
absl::negation< |
| 978 |
optional_internal:: |
| 979 |
is_constructible_convertible_assignable_from_optional< |
| 980 |
T, U>>>::value>::type> |
| 981 |
optional& operator=(const optional<U>& rhs); |
| 982 |
|
| 983 |
template <typename U, |
| 984 |
typename = typename std::enable_if<absl::conjunction< |
| 985 |
absl::negation<std::is_same<T, U>>, std::is_constructible<T, U>, |
| 986 |
std::is_assignable<T&, U>, |
| 987 |
absl::negation< |
| 988 |
optional_internal:: |
| 989 |
is_constructible_convertible_assignable_from_optional< |
| 990 |
T, U>>>::value>::type> |
| 991 |
optional& operator=(optional<U>&& rhs); |
| 992 |
|
| 993 |
const T& operator*() const&; |
| 994 |
T& operator*() &; |
| 995 |
const T&& operator*() const&&; |
| 996 |
T&& operator*() &&; |
| 997 |
|
| 998 |
const T* operator->() const; |
| 999 |
T* operator->(); |
| 1000 |
|
| 1001 |
const T& value() const&; |
| 1002 |
T& value() &; |
| 1003 |
const T&& value() const&&; |
| 1004 |
T&& value() &&; |
| 1005 |
|
| 1006 |
template <typename U> |
| 1007 |
constexpr T value_or(U&& v) const&; |
| 1008 |
template <typename U> |
| 1009 |
T value_or(U&& v) &&; |
| 1010 |
|
| 1011 |
template <typename... Args> |
| 1012 |
T& emplace(Args&&... args); |
| 1013 |
|
| 1014 |
template <typename U, typename... Args> |
| 1015 |
T& emplace(std::initializer_list<U> ilist, Args&&... args); |
| 1016 |
|
| 1017 |
void reset() noexcept; |
| 1018 |
|
| 1019 |
constexpr explicit operator bool() const noexcept; |
| 1020 |
constexpr bool has_value() const noexcept; |
| 1021 |
|
| 1022 |
void swap(optional& rhs) noexcept; |
| 1023 |
}; |
| 1024 |
|
| 1025 |
template <typename T> |
| 1026 |
constexpr optional<typename std::decay<T>::type> make_optional(T&& v); |
| 1027 |
|
| 1028 |
template <typename T, typename... Args> |
| 1029 |
constexpr optional<T> make_optional(Args&&... args); |
| 1030 |
|
| 1031 |
template <typename T, typename U, typename... Args> |
| 1032 |
constexpr optional<T> make_optional(std::initializer_list<U> il, |
| 1033 |
Args&&... args); |
| 1034 |
|
| 1035 |
template <typename T, typename U> |
| 1036 |
constexpr bool operator==(const optional<T> &lhs, const optional<U> &rhs); |
| 1037 |
template <typename T, typename U> |
| 1038 |
constexpr bool operator!=(const optional<T> &lhs, const optional<U> &rhs); |
| 1039 |
|
| 1040 |
template <typename T> |
| 1041 |
constexpr bool operator==(const optional<T> &opt, nullopt_t); |
| 1042 |
template <typename T> |
| 1043 |
constexpr bool operator==(nullopt_t, const optional<T> &opt); |
| 1044 |
template <typename T> |
| 1045 |
constexpr bool operator!=(const optional<T> &opt, nullopt_t); |
| 1046 |
template <typename T> |
| 1047 |
constexpr bool operator!=(nullopt_t, const optional<T> &opt); |
| 1048 |
|
| 1049 |
template <typename T, typename U> |
| 1050 |
constexpr bool operator==(const optional<T> &opt, const U &value); |
| 1051 |
template <typename T, typename U> |
| 1052 |
constexpr bool operator==(const T &value, const optional<U> &opt); |
| 1053 |
template <typename T, typename U> |
| 1054 |
constexpr bool operator!=(const optional<T> &opt, const U &value); |
| 1055 |
template <typename T, typename U> |
| 1056 |
constexpr bool operator!=(const T &value, const optional<U> &opt); |
| 1057 |
|
| 1058 |
} // namespace absl |
| 1059 |
)"; |
| 1060 |
|
| 1061 |
static constexpr char BaseOptionalHeader[] = R"( |
| 1062 |
#include "std_initializer_list.h" |
| 1063 |
#include "std_type_traits.h" |
| 1064 |
#include "std_utility.h" |
| 1065 |
|
| 1066 |
namespace base { |
| 1067 |
|
| 1068 |
struct in_place_t {}; |
| 1069 |
constexpr in_place_t in_place; |
| 1070 |
|
| 1071 |
struct nullopt_t { |
| 1072 |
constexpr explicit nullopt_t() {} |
| 1073 |
}; |
| 1074 |
constexpr nullopt_t nullopt; |
| 1075 |
|
| 1076 |
template <typename T> |
| 1077 |
class Optional; |
| 1078 |
|
| 1079 |
namespace internal { |
| 1080 |
|
| 1081 |
template <typename T> |
| 1082 |
using RemoveCvRefT = std::remove_cv_t<std::remove_reference_t<T>>; |
| 1083 |
|
| 1084 |
template <typename T, typename U> |
| 1085 |
struct IsConvertibleFromOptional |
| 1086 |
: std::integral_constant< |
| 1087 |
bool, std::is_constructible<T, Optional<U>&>::value || |
| 1088 |
std::is_constructible<T, const Optional<U>&>::value || |
| 1089 |
std::is_constructible<T, Optional<U>&&>::value || |
| 1090 |
std::is_constructible<T, const Optional<U>&&>::value || |
| 1091 |
std::is_convertible<Optional<U>&, T>::value || |
| 1092 |
std::is_convertible<const Optional<U>&, T>::value || |
| 1093 |
std::is_convertible<Optional<U>&&, T>::value || |
| 1094 |
std::is_convertible<const Optional<U>&&, T>::value> {}; |
| 1095 |
|
| 1096 |
template <typename T, typename U> |
| 1097 |
struct IsAssignableFromOptional |
| 1098 |
: std::integral_constant< |
| 1099 |
bool, IsConvertibleFromOptional<T, U>::value || |
| 1100 |
std::is_assignable<T&, Optional<U>&>::value || |
| 1101 |
std::is_assignable<T&, const Optional<U>&>::value || |
| 1102 |
std::is_assignable<T&, Optional<U>&&>::value || |
| 1103 |
std::is_assignable<T&, const Optional<U>&&>::value> {}; |
| 1104 |
|
| 1105 |
} // namespace internal |
| 1106 |
|
| 1107 |
template <typename T> |
| 1108 |
class Optional { |
| 1109 |
public: |
| 1110 |
using value_type = T; |
| 1111 |
|
| 1112 |
constexpr Optional() = default; |
| 1113 |
constexpr Optional(const Optional& other) noexcept = default; |
| 1114 |
constexpr Optional(Optional&& other) noexcept = default; |
| 1115 |
|
| 1116 |
constexpr Optional(nullopt_t); |
| 1117 |
|
| 1118 |
template <typename U, |
| 1119 |
typename std::enable_if< |
| 1120 |
std::is_constructible<T, const U&>::value && |
| 1121 |
!internal::IsConvertibleFromOptional<T, U>::value && |
| 1122 |
std::is_convertible<const U&, T>::value, |
| 1123 |
bool>::type = false> |
| 1124 |
Optional(const Optional<U>& other) noexcept; |
| 1125 |
|
| 1126 |
template <typename U, |
| 1127 |
typename std::enable_if< |
| 1128 |
std::is_constructible<T, const U&>::value && |
| 1129 |
!internal::IsConvertibleFromOptional<T, U>::value && |
| 1130 |
!std::is_convertible<const U&, T>::value, |
| 1131 |
bool>::type = false> |
| 1132 |
explicit Optional(const Optional<U>& other) noexcept; |
| 1133 |
|
| 1134 |
template <typename U, |
| 1135 |
typename std::enable_if< |
| 1136 |
std::is_constructible<T, U&&>::value && |
| 1137 |
!internal::IsConvertibleFromOptional<T, U>::value && |
| 1138 |
std::is_convertible<U&&, T>::value, |
| 1139 |
bool>::type = false> |
| 1140 |
Optional(Optional<U>&& other) noexcept; |
| 1141 |
|
| 1142 |
template <typename U, |
| 1143 |
typename std::enable_if< |
| 1144 |
std::is_constructible<T, U&&>::value && |
| 1145 |
!internal::IsConvertibleFromOptional<T, U>::value && |
| 1146 |
!std::is_convertible<U&&, T>::value, |
| 1147 |
bool>::type = false> |
| 1148 |
explicit Optional(Optional<U>&& other) noexcept; |
| 1149 |
|
| 1150 |
template <class... Args> |
| 1151 |
constexpr explicit Optional(in_place_t, Args&&... args); |
| 1152 |
|
| 1153 |
template <class U, class... Args, |
| 1154 |
class = typename std::enable_if<std::is_constructible< |
| 1155 |
value_type, std::initializer_list<U>&, Args...>::value>::type> |
| 1156 |
constexpr explicit Optional(in_place_t, std::initializer_list<U> il, |
| 1157 |
Args&&... args); |
| 1158 |
|
| 1159 |
template < |
| 1160 |
typename U = value_type, |
| 1161 |
typename std::enable_if< |
| 1162 |
std::is_constructible<T, U&&>::value && |
| 1163 |
!std::is_same<internal::RemoveCvRefT<U>, in_place_t>::value && |
| 1164 |
!std::is_same<internal::RemoveCvRefT<U>, Optional<T>>::value && |
| 1165 |
std::is_convertible<U&&, T>::value, |
| 1166 |
bool>::type = false> |
| 1167 |
constexpr Optional(U&& value); |
| 1168 |
|
| 1169 |
template < |
| 1170 |
typename U = value_type, |
| 1171 |
typename std::enable_if< |
| 1172 |
std::is_constructible<T, U&&>::value && |
| 1173 |
!std::is_same<internal::RemoveCvRefT<U>, in_place_t>::value && |
| 1174 |
!std::is_same<internal::RemoveCvRefT<U>, Optional<T>>::value && |
| 1175 |
!std::is_convertible<U&&, T>::value, |
| 1176 |
bool>::type = false> |
| 1177 |
constexpr explicit Optional(U&& value); |
| 1178 |
|
| 1179 |
Optional& operator=(const Optional& other) noexcept; |
| 1180 |
|
| 1181 |
Optional& operator=(Optional&& other) noexcept; |
| 1182 |
|
| 1183 |
Optional& operator=(nullopt_t); |
| 1184 |
|
| 1185 |
template <typename U> |
| 1186 |
typename std::enable_if< |
| 1187 |
!std::is_same<internal::RemoveCvRefT<U>, Optional<T>>::value && |
| 1188 |
std::is_constructible<T, U>::value && |
| 1189 |
std::is_assignable<T&, U>::value && |
| 1190 |
(!std::is_scalar<T>::value || |
| 1191 |
!std::is_same<typename std::decay<U>::type, T>::value), |
| 1192 |
Optional&>::type |
| 1193 |
operator=(U&& value) noexcept; |
| 1194 |
|
| 1195 |
template <typename U> |
| 1196 |
typename std::enable_if<!internal::IsAssignableFromOptional<T, U>::value && |
| 1197 |
std::is_constructible<T, const U&>::value && |
| 1198 |
std::is_assignable<T&, const U&>::value, |
| 1199 |
Optional&>::type |
| 1200 |
operator=(const Optional<U>& other) noexcept; |
| 1201 |
|
| 1202 |
template <typename U> |
| 1203 |
typename std::enable_if<!internal::IsAssignableFromOptional<T, U>::value && |
| 1204 |
std::is_constructible<T, U>::value && |
| 1205 |
std::is_assignable<T&, U>::value, |
| 1206 |
Optional&>::type |
| 1207 |
operator=(Optional<U>&& other) noexcept; |
| 1208 |
|
| 1209 |
const T& operator*() const&; |
| 1210 |
T& operator*() &; |
| 1211 |
const T&& operator*() const&&; |
| 1212 |
T&& operator*() &&; |
| 1213 |
|
| 1214 |
const T* operator->() const; |
| 1215 |
T* operator->(); |
| 1216 |
|
| 1217 |
const T& value() const&; |
| 1218 |
T& value() &; |
| 1219 |
const T&& value() const&&; |
| 1220 |
T&& value() &&; |
| 1221 |
|
| 1222 |
template <typename U> |
| 1223 |
constexpr T value_or(U&& v) const&; |
| 1224 |
template <typename U> |
| 1225 |
T value_or(U&& v) &&; |
| 1226 |
|
| 1227 |
template <typename... Args> |
| 1228 |
T& emplace(Args&&... args); |
| 1229 |
|
| 1230 |
template <typename U, typename... Args> |
| 1231 |
T& emplace(std::initializer_list<U> ilist, Args&&... args); |
| 1232 |
|
| 1233 |
void reset() noexcept; |
| 1234 |
|
| 1235 |
constexpr explicit operator bool() const noexcept; |
| 1236 |
constexpr bool has_value() const noexcept; |
| 1237 |
|
| 1238 |
void swap(Optional& other); |
| 1239 |
}; |
| 1240 |
|
| 1241 |
template <typename T> |
| 1242 |
constexpr Optional<typename std::decay<T>::type> make_optional(T&& v); |
| 1243 |
|
| 1244 |
template <typename T, typename... Args> |
| 1245 |
constexpr Optional<T> make_optional(Args&&... args); |
| 1246 |
|
| 1247 |
template <typename T, typename U, typename... Args> |
| 1248 |
constexpr Optional<T> make_optional(std::initializer_list<U> il, |
| 1249 |
Args&&... args); |
| 1250 |
|
| 1251 |
template <typename T, typename U> |
| 1252 |
constexpr bool operator==(const Optional<T> &lhs, const Optional<U> &rhs); |
| 1253 |
template <typename T, typename U> |
| 1254 |
constexpr bool operator!=(const Optional<T> &lhs, const Optional<U> &rhs); |
| 1255 |
|
| 1256 |
template <typename T> |
| 1257 |
constexpr bool operator==(const Optional<T> &opt, nullopt_t); |
| 1258 |
template <typename T> |
| 1259 |
constexpr bool operator==(nullopt_t, const Optional<T> &opt); |
| 1260 |
template <typename T> |
| 1261 |
constexpr bool operator!=(const Optional<T> &opt, nullopt_t); |
| 1262 |
template <typename T> |
| 1263 |
constexpr bool operator!=(nullopt_t, const Optional<T> &opt); |
| 1264 |
|
| 1265 |
template <typename T, typename U> |
| 1266 |
constexpr bool operator==(const Optional<T> &opt, const U &value); |
| 1267 |
template <typename T, typename U> |
| 1268 |
constexpr bool operator==(const T &value, const Optional<U> &opt); |
| 1269 |
template <typename T, typename U> |
| 1270 |
constexpr bool operator!=(const Optional<T> &opt, const U &value); |
| 1271 |
template <typename T, typename U> |
| 1272 |
constexpr bool operator!=(const T &value, const Optional<U> &opt); |
| 1273 |
|
| 1274 |
} // namespace base |
| 1275 |
)"; |
| 1276 |
|
| 1277 |
constexpr const char StatusDefsHeader[] = |
| 1278 |
R"cc( |
| 1279 |
#ifndef STATUS_H_ |
| 1280 |
#define STATUS_H_ |
| 1281 |
|
| 1282 |
#include "absl_type_traits.h" |
| 1283 |
#include "std_initializer_list.h" |
| 1284 |
#include "std_string.h" |
| 1285 |
#include "std_type_traits.h" |
| 1286 |
#include "std_utility.h" |
| 1287 |
|
| 1288 |
namespace absl { |
| 1289 |
struct SourceLocation { |
| 1290 |
static constexpr SourceLocation current(); |
| 1291 |
static constexpr SourceLocation |
| 1292 |
DoNotInvokeDirectlyNoSeriouslyDont(int line, const char *file_name); |
| 1293 |
}; |
| 1294 |
} // namespace absl |
| 1295 |
namespace absl { |
| 1296 |
enum class StatusCode : int { |
| 1297 |
kOk, |
| 1298 |
kCancelled, |
| 1299 |
kUnknown, |
| 1300 |
kInvalidArgument, |
| 1301 |
kDeadlineExceeded, |
| 1302 |
kNotFound, |
| 1303 |
kAlreadyExists, |
| 1304 |
kPermissionDenied, |
| 1305 |
kResourceExhausted, |
| 1306 |
kFailedPrecondition, |
| 1307 |
kAborted, |
| 1308 |
kOutOfRange, |
| 1309 |
kUnimplemented, |
| 1310 |
kInternal, |
| 1311 |
kUnavailable, |
| 1312 |
kDataLoss, |
| 1313 |
kUnauthenticated, |
| 1314 |
}; |
| 1315 |
} // namespace absl |
| 1316 |
|
| 1317 |
namespace absl { |
| 1318 |
enum class StatusToStringMode : int { |
| 1319 |
kWithNoExtraData = 0, |
| 1320 |
kWithPayload = 1 << 0, |
| 1321 |
kWithSourceLocation = 1 << 1, |
| 1322 |
kWithEverything = ~kWithNoExtraData, |
| 1323 |
kDefault = kWithPayload, |
| 1324 |
}; |
| 1325 |
class Status { |
| 1326 |
public: |
| 1327 |
Status(); |
| 1328 |
template <typename Enum> Status(Enum code, std::string_view msg); |
| 1329 |
Status(absl::StatusCode code, std::string_view msg, |
| 1330 |
absl::SourceLocation loc = SourceLocation::current()); |
| 1331 |
Status(const Status &base_status, absl::SourceLocation loc); |
| 1332 |
Status(Status &&base_status, absl::SourceLocation loc); |
| 1333 |
~Status() {} |
| 1334 |
|
| 1335 |
Status(const Status &); |
| 1336 |
Status &operator=(const Status &x); |
| 1337 |
|
| 1338 |
Status(Status &&) noexcept; |
| 1339 |
Status &operator=(Status &&); |
| 1340 |
|
| 1341 |
friend bool operator==(const Status &, const Status &); |
| 1342 |
friend bool operator!=(const Status &, const Status &); |
| 1343 |
|
| 1344 |
bool ok() const { return true; } |
| 1345 |
void CheckSuccess() const; |
| 1346 |
void IgnoreError() const; |
| 1347 |
int error_code() const; |
| 1348 |
absl::Status ToCanonical() const; |
| 1349 |
std::string |
| 1350 |
ToString(StatusToStringMode m = StatusToStringMode::kDefault) const; |
| 1351 |
void Update(const Status &new_status); |
| 1352 |
void Update(Status &&new_status); |
| 1353 |
}; |
| 1354 |
|
| 1355 |
bool operator==(const Status &lhs, const Status &rhs); |
| 1356 |
bool operator!=(const Status &lhs, const Status &rhs); |
| 1357 |
|
| 1358 |
Status OkStatus(); |
| 1359 |
Status InvalidArgumentError(const char *); |
| 1360 |
|
| 1361 |
} // namespace absl |
| 1362 |
|
| 1363 |
#endif // STATUS_H |
| 1364 |
)cc"; |
| 1365 |
|
| 1366 |
constexpr const char StatusOrDefsHeader[] = R"cc( |
| 1367 |
#ifndef STATUSOR_H_ |
| 1368 |
#define STATUSOR_H_ |
| 1369 |
#include "absl_type_traits.h" |
| 1370 |
#include "status_defs.h" |
| 1371 |
#include "std_initializer_list.h" |
| 1372 |
#include "std_type_traits.h" |
| 1373 |
#include "std_utility.h" |
| 1374 |
|
| 1375 |
namespace absl { |
| 1376 |
|
| 1377 |
template <typename T> struct StatusOr; |
| 1378 |
|
| 1379 |
namespace internal_statusor { |
| 1380 |
|
| 1381 |
template <typename T, typename U, typename = void> |
| 1382 |
struct HasConversionOperatorToStatusOr : std::false_type {}; |
| 1383 |
|
| 1384 |
template <typename T, typename U> |
| 1385 |
void test(char (*)[sizeof(std::declval<U>().operator absl::StatusOr<T>())]); |
| 1386 |
|
| 1387 |
template <typename T, typename U> |
| 1388 |
struct HasConversionOperatorToStatusOr<T, U, decltype(test<T, U>(0))> |
| 1389 |
: std::true_type {}; |
| 1390 |
|
| 1391 |
template <typename T, typename U> |
| 1392 |
using IsConstructibleOrConvertibleFromStatusOr = |
| 1393 |
absl::disjunction<std::is_constructible<T, StatusOr<U> &>, |
| 1394 |
std::is_constructible<T, const StatusOr<U> &>, |
| 1395 |
std::is_constructible<T, StatusOr<U> &&>, |
| 1396 |
std::is_constructible<T, const StatusOr<U> &&>, |
| 1397 |
std::is_convertible<StatusOr<U> &, T>, |
| 1398 |
std::is_convertible<const StatusOr<U> &, T>, |
| 1399 |
std::is_convertible<StatusOr<U> &&, T>, |
| 1400 |
std::is_convertible<const StatusOr<U> &&, T>>; |
| 1401 |
|
| 1402 |
template <typename T, typename U> |
| 1403 |
using IsConstructibleOrConvertibleOrAssignableFromStatusOr = |
| 1404 |
absl::disjunction<IsConstructibleOrConvertibleFromStatusOr<T, U>, |
| 1405 |
std::is_assignable<T &, StatusOr<U> &>, |
| 1406 |
std::is_assignable<T &, const StatusOr<U> &>, |
| 1407 |
std::is_assignable<T &, StatusOr<U> &&>, |
| 1408 |
std::is_assignable<T &, const StatusOr<U> &&>>; |
| 1409 |
|
| 1410 |
template <typename T, typename U> |
| 1411 |
struct IsDirectInitializationAmbiguous |
| 1412 |
: public absl::conditional_t< |
| 1413 |
std::is_same<absl::remove_cv_t<absl::remove_reference_t<U>>, |
| 1414 |
U>::value, |
| 1415 |
std::false_type, |
| 1416 |
IsDirectInitializationAmbiguous< |
| 1417 |
T, absl::remove_cv_t<absl::remove_reference_t<U>>>> {}; |
| 1418 |
|
| 1419 |
template <typename T, typename V> |
| 1420 |
struct IsDirectInitializationAmbiguous<T, absl::StatusOr<V>> |
| 1421 |
: public IsConstructibleOrConvertibleFromStatusOr<T, V> {}; |
| 1422 |
|
| 1423 |
template <typename T, typename U> |
| 1424 |
using IsDirectInitializationValid = absl::disjunction< |
| 1425 |
// Short circuits if T is basically U. |
| 1426 |
std::is_same<T, absl::remove_cv_t<absl::remove_reference_t<U>>>, |
| 1427 |
absl::negation<absl::disjunction< |
| 1428 |
std::is_same<absl::StatusOr<T>, |
| 1429 |
absl::remove_cv_t<absl::remove_reference_t<U>>>, |
| 1430 |
std::is_same<absl::Status, |
| 1431 |
absl::remove_cv_t<absl::remove_reference_t<U>>>, |
| 1432 |
std::is_same<absl::in_place_t, |
| 1433 |
absl::remove_cv_t<absl::remove_reference_t<U>>>, |
| 1434 |
IsDirectInitializationAmbiguous<T, U>>>>; |
| 1435 |
|
| 1436 |
template <typename T, typename U> |
| 1437 |
struct IsForwardingAssignmentAmbiguous |
| 1438 |
: public absl::conditional_t< |
| 1439 |
std::is_same<absl::remove_cv_t<absl::remove_reference_t<U>>, |
| 1440 |
U>::value, |
| 1441 |
std::false_type, |
| 1442 |
IsForwardingAssignmentAmbiguous< |
| 1443 |
T, absl::remove_cv_t<absl::remove_reference_t<U>>>> {}; |
| 1444 |
|
| 1445 |
template <typename T, typename U> |
| 1446 |
struct IsForwardingAssignmentAmbiguous<T, absl::StatusOr<U>> |
| 1447 |
: public IsConstructibleOrConvertibleOrAssignableFromStatusOr<T, U> {}; |
| 1448 |
|
| 1449 |
template <typename T, typename U> |
| 1450 |
using IsForwardingAssignmentValid = absl::disjunction< |
| 1451 |
// Short circuits if T is basically U. |
| 1452 |
std::is_same<T, absl::remove_cv_t<absl::remove_reference_t<U>>>, |
| 1453 |
absl::negation<absl::disjunction< |
| 1454 |
std::is_same<absl::StatusOr<T>, |
| 1455 |
absl::remove_cv_t<absl::remove_reference_t<U>>>, |
| 1456 |
std::is_same<absl::Status, |
| 1457 |
absl::remove_cv_t<absl::remove_reference_t<U>>>, |
| 1458 |
std::is_same<absl::in_place_t, |
| 1459 |
absl::remove_cv_t<absl::remove_reference_t<U>>>, |
| 1460 |
IsForwardingAssignmentAmbiguous<T, U>>>>; |
| 1461 |
|
| 1462 |
template <typename T, typename U> |
| 1463 |
using IsForwardingAssignmentValid = absl::disjunction< |
| 1464 |
// Short circuits if T is basically U. |
| 1465 |
std::is_same<T, absl::remove_cv_t<absl::remove_reference_t<U>>>, |
| 1466 |
absl::negation<absl::disjunction< |
| 1467 |
std::is_same<absl::StatusOr<T>, |
| 1468 |
absl::remove_cv_t<absl::remove_reference_t<U>>>, |
| 1469 |
std::is_same<absl::Status, |
| 1470 |
absl::remove_cv_t<absl::remove_reference_t<U>>>, |
| 1471 |
std::is_same<absl::in_place_t, |
| 1472 |
absl::remove_cv_t<absl::remove_reference_t<U>>>, |
| 1473 |
IsForwardingAssignmentAmbiguous<T, U>>>>; |
| 1474 |
|
| 1475 |
template <typename T> struct OperatorBase { |
| 1476 |
const T &value() const &; |
| 1477 |
T &value() &; |
| 1478 |
const T &&value() const &&; |
| 1479 |
T &&value() &&; |
| 1480 |
|
| 1481 |
const T &operator*() const &; |
| 1482 |
T &operator*() &; |
| 1483 |
const T &&operator*() const &&; |
| 1484 |
T &&operator*() &&; |
| 1485 |
|
| 1486 |
// To test that analyses are okay if there is a use of operator* |
| 1487 |
// within this base class. |
| 1488 |
const T *operator->() const { return __builtin_addressof(**this); } |
| 1489 |
T *operator->() { return __builtin_addressof(**this); } |
| 1490 |
}; |
| 1491 |
|
| 1492 |
} // namespace internal_statusor |
| 1493 |
|
| 1494 |
template <typename T> |
| 1495 |
struct StatusOr : private internal_statusor::OperatorBase<T> { |
| 1496 |
explicit StatusOr(); |
| 1497 |
|
| 1498 |
StatusOr(const StatusOr &) = default; |
| 1499 |
StatusOr &operator=(const StatusOr &) = default; |
| 1500 |
|
| 1501 |
StatusOr(StatusOr &&) = default; |
| 1502 |
StatusOr &operator=(StatusOr &&) = default; |
| 1503 |
|
| 1504 |
template < |
| 1505 |
typename U, |
| 1506 |
absl::enable_if_t< |
| 1507 |
absl::conjunction< |
| 1508 |
absl::negation<std::is_same<T, U>>, |
| 1509 |
std::is_constructible<T, const U &>, |
| 1510 |
std::is_convertible<const U &, T>, |
| 1511 |
absl::negation< |
| 1512 |
internal_statusor::IsConstructibleOrConvertibleFromStatusOr< |
| 1513 |
T, U>>>::value, |
| 1514 |
int> = 0> |
| 1515 |
StatusOr(const StatusOr<U> &); |
| 1516 |
|
| 1517 |
template < |
| 1518 |
typename U, |
| 1519 |
absl::enable_if_t< |
| 1520 |
absl::conjunction< |
| 1521 |
absl::negation<std::is_same<T, U>>, |
| 1522 |
std::is_constructible<T, const U &>, |
| 1523 |
absl::negation<std::is_convertible<const U &, T>>, |
| 1524 |
absl::negation< |
| 1525 |
internal_statusor::IsConstructibleOrConvertibleFromStatusOr< |
| 1526 |
T, U>>>::value, |
| 1527 |
int> = 0> |
| 1528 |
explicit StatusOr(const StatusOr<U> &); |
| 1529 |
|
| 1530 |
template < |
| 1531 |
typename U, |
| 1532 |
absl::enable_if_t< |
| 1533 |
absl::conjunction< |
| 1534 |
absl::negation<std::is_same<T, U>>, |
| 1535 |
std::is_constructible<T, U &&>, std::is_convertible<U &&, T>, |
| 1536 |
absl::negation< |
| 1537 |
internal_statusor::IsConstructibleOrConvertibleFromStatusOr< |
| 1538 |
T, U>>>::value, |
| 1539 |
int> = 0> |
| 1540 |
StatusOr(StatusOr<U> &&); |
| 1541 |
|
| 1542 |
template < |
| 1543 |
typename U, |
| 1544 |
absl::enable_if_t< |
| 1545 |
absl::conjunction< |
| 1546 |
absl::negation<std::is_same<T, U>>, |
| 1547 |
std::is_constructible<T, U &&>, |
| 1548 |
absl::negation<std::is_convertible<U &&, T>>, |
| 1549 |
absl::negation< |
| 1550 |
internal_statusor::IsConstructibleOrConvertibleFromStatusOr< |
| 1551 |
T, U>>>::value, |
| 1552 |
int> = 0> |
| 1553 |
explicit StatusOr(StatusOr<U> &&); |
| 1554 |
|
| 1555 |
template < |
| 1556 |
typename U, |
| 1557 |
absl::enable_if_t< |
| 1558 |
absl::conjunction< |
| 1559 |
absl::negation<std::is_same<T, U>>, |
| 1560 |
std::is_constructible<T, const U &>, |
| 1561 |
std::is_assignable<T, const U &>, |
| 1562 |
absl::negation< |
| 1563 |
internal_statusor:: |
| 1564 |
IsConstructibleOrConvertibleOrAssignableFromStatusOr< |
| 1565 |
T, U>>>::value, |
| 1566 |
int> = 0> |
| 1567 |
StatusOr &operator=(const StatusOr<U> &); |
| 1568 |
|
| 1569 |
template < |
| 1570 |
typename U, |
| 1571 |
absl::enable_if_t< |
| 1572 |
absl::conjunction< |
| 1573 |
absl::negation<std::is_same<T, U>>, |
| 1574 |
std::is_constructible<T, U &&>, std::is_assignable<T, U &&>, |
| 1575 |
absl::negation< |
| 1576 |
internal_statusor:: |
| 1577 |
IsConstructibleOrConvertibleOrAssignableFromStatusOr< |
| 1578 |
T, U>>>::value, |
| 1579 |
int> = 0> |
| 1580 |
StatusOr &operator=(StatusOr<U> &&); |
| 1581 |
|
| 1582 |
template < |
| 1583 |
typename U = absl::Status, |
| 1584 |
absl::enable_if_t< |
| 1585 |
absl::conjunction< |
| 1586 |
std::is_convertible<U &&, absl::Status>, |
| 1587 |
std::is_constructible<absl::Status, U &&>, |
| 1588 |
absl::negation<std::is_same<absl::decay_t<U>, absl::StatusOr<T>>>, |
| 1589 |
absl::negation<std::is_same<absl::decay_t<U>, T>>, |
| 1590 |
absl::negation<std::is_same<absl::decay_t<U>, absl::in_place_t>>, |
| 1591 |
absl::negation<internal_statusor::HasConversionOperatorToStatusOr< |
| 1592 |
T, U &&>>>::value, |
| 1593 |
int> = 0> |
| 1594 |
StatusOr(U &&); |
| 1595 |
|
| 1596 |
template < |
| 1597 |
typename U = absl::Status, |
| 1598 |
absl::enable_if_t< |
| 1599 |
absl::conjunction< |
| 1600 |
absl::negation<std::is_convertible<U &&, absl::Status>>, |
| 1601 |
std::is_constructible<absl::Status, U &&>, |
| 1602 |
absl::negation<std::is_same<absl::decay_t<U>, absl::StatusOr<T>>>, |
| 1603 |
absl::negation<std::is_same<absl::decay_t<U>, T>>, |
| 1604 |
absl::negation<std::is_same<absl::decay_t<U>, absl::in_place_t>>, |
| 1605 |
absl::negation<internal_statusor::HasConversionOperatorToStatusOr< |
| 1606 |
T, U &&>>>::value, |
| 1607 |
int> = 0> |
| 1608 |
explicit StatusOr(U &&); |
| 1609 |
|
| 1610 |
template < |
| 1611 |
typename U = absl::Status, |
| 1612 |
absl::enable_if_t< |
| 1613 |
absl::conjunction< |
| 1614 |
std::is_convertible<U &&, absl::Status>, |
| 1615 |
std::is_constructible<absl::Status, U &&>, |
| 1616 |
absl::negation<std::is_same<absl::decay_t<U>, absl::StatusOr<T>>>, |
| 1617 |
absl::negation<std::is_same<absl::decay_t<U>, T>>, |
| 1618 |
absl::negation<std::is_same<absl::decay_t<U>, absl::in_place_t>>, |
| 1619 |
absl::negation<internal_statusor::HasConversionOperatorToStatusOr< |
| 1620 |
T, U &&>>>::value, |
| 1621 |
int> = 0> |
| 1622 |
StatusOr &operator=(U &&); |
| 1623 |
|
| 1624 |
template < |
| 1625 |
typename U = T, |
| 1626 |
typename = typename std::enable_if<absl::conjunction< |
| 1627 |
std::is_constructible<T, U &&>, std::is_assignable<T &, U &&>, |
| 1628 |
absl::disjunction< |
| 1629 |
std::is_same<absl::remove_cv_t<absl::remove_reference_t<U>>, T>, |
| 1630 |
absl::conjunction< |
| 1631 |
absl::negation<std::is_convertible<U &&, absl::Status>>, |
| 1632 |
absl::negation< |
| 1633 |
internal_statusor::HasConversionOperatorToStatusOr< |
| 1634 |
T, U &&>>>>, |
| 1635 |
internal_statusor::IsForwardingAssignmentValid<T, U &&>>::value>:: |
| 1636 |
type> |
| 1637 |
StatusOr &operator=(U &&); |
| 1638 |
|
| 1639 |
template <typename... Args> explicit StatusOr(absl::in_place_t, Args &&...); |
| 1640 |
|
| 1641 |
template <typename U, typename... Args> |
| 1642 |
explicit StatusOr(absl::in_place_t, std::initializer_list<U>, Args &&...); |
| 1643 |
|
| 1644 |
template < |
| 1645 |
typename U = T, |
| 1646 |
absl::enable_if_t< |
| 1647 |
absl::conjunction< |
| 1648 |
internal_statusor::IsDirectInitializationValid<T, U &&>, |
| 1649 |
std::is_constructible<T, U &&>, std::is_convertible<U &&, T>, |
| 1650 |
absl::disjunction< |
| 1651 |
std::is_same<absl::remove_cv_t<absl::remove_reference_t<U>>, |
| 1652 |
T>, |
| 1653 |
absl::conjunction< |
| 1654 |
absl::negation<std::is_convertible<U &&, absl::Status>>, |
| 1655 |
absl::negation< |
| 1656 |
internal_statusor::HasConversionOperatorToStatusOr< |
| 1657 |
T, U &&>>>>>::value, |
| 1658 |
int> = 0> |
| 1659 |
StatusOr(U &&); |
| 1660 |
|
| 1661 |
template < |
| 1662 |
typename U = T, |
| 1663 |
absl::enable_if_t< |
| 1664 |
absl::conjunction< |
| 1665 |
internal_statusor::IsDirectInitializationValid<T, U &&>, |
| 1666 |
absl::disjunction< |
| 1667 |
std::is_same<absl::remove_cv_t<absl::remove_reference_t<U>>, |
| 1668 |
T>, |
| 1669 |
absl::conjunction< |
| 1670 |
absl::negation<std::is_constructible<absl::Status, U &&>>, |
| 1671 |
absl::negation< |
| 1672 |
internal_statusor::HasConversionOperatorToStatusOr< |
| 1673 |
T, U &&>>>>, |
| 1674 |
std::is_constructible<T, U &&>, |
| 1675 |
absl::negation<std::is_convertible<U &&, T>>>::value, |
| 1676 |
int> = 0> |
| 1677 |
explicit StatusOr(U &&); |
| 1678 |
|
| 1679 |
bool ok() const; |
| 1680 |
|
| 1681 |
const Status &status() const & { return status_; } |
| 1682 |
Status status() &&; |
| 1683 |
|
| 1684 |
using StatusOr::OperatorBase::value; |
| 1685 |
|
| 1686 |
const T &ValueOrDie() const &; |
| 1687 |
T &ValueOrDie() &; |
| 1688 |
const T &&ValueOrDie() const &&; |
| 1689 |
T &&ValueOrDie() &&; |
| 1690 |
|
| 1691 |
using StatusOr::OperatorBase::operator*; |
| 1692 |
using StatusOr::OperatorBase::operator->; |
| 1693 |
|
| 1694 |
template <typename U> T value_or(U &&default_value) const &; |
| 1695 |
template <typename U> T value_or(U &&default_value) &&; |
| 1696 |
|
| 1697 |
template <typename... Args> T &emplace(Args &&...args); |
| 1698 |
|
| 1699 |
template < |
| 1700 |
typename U, typename... Args, |
| 1701 |
absl::enable_if_t<std::is_constructible<T, std::initializer_list<U> &, |
| 1702 |
Args &&...>::value, |
| 1703 |
int> = 0> |
| 1704 |
T &emplace(std::initializer_list<U> ilist, Args &&...args); |
| 1705 |
|
| 1706 |
private: |
| 1707 |
absl::Status status_; |
| 1708 |
}; |
| 1709 |
|
| 1710 |
template <typename T> |
| 1711 |
bool operator==(const StatusOr<T> &lhs, const StatusOr<T> &rhs); |
| 1712 |
|
| 1713 |
template <typename T> |
| 1714 |
bool operator!=(const StatusOr<T> &lhs, const StatusOr<T> &rhs); |
| 1715 |
|
| 1716 |
} // namespace absl |
| 1717 |
|
| 1718 |
#endif // STATUSOR_H_ |
| 1719 |
)cc"; |
| 1720 |
|
| 1721 |
static constexpr char StdVectorHeader[] = R"cc( |
| 1722 |
#ifndef STD_VECTOR_H |
| 1723 |
#define STD_VECTOR_H |
| 1724 |
namespace std { |
| 1725 |
template <class T> struct allocator { |
| 1726 |
typedef size_t size_type; |
| 1727 |
typedef ptrdiff_t difference_type; |
| 1728 |
typedef T *pointer; |
| 1729 |
typedef const T *const_pointer; |
| 1730 |
typedef T value_type; |
| 1731 |
|
| 1732 |
T *allocate(size_t n); |
| 1733 |
}; |
| 1734 |
|
| 1735 |
template <class Alloc> struct allocator_traits { |
| 1736 |
typedef Alloc allocator_type; |
| 1737 |
typedef typename allocator_type::value_type value_type; |
| 1738 |
typedef typename allocator_type::pointer pointer; |
| 1739 |
typedef typename allocator_type::const_pointer const_pointer; |
| 1740 |
typedef typename allocator_type::difference_type difference_type; |
| 1741 |
typedef typename allocator_type::size_type size_type; |
| 1742 |
}; |
| 1743 |
|
| 1744 |
template <typename T, class Allocator = allocator<T>> class vector { |
| 1745 |
public: |
| 1746 |
using value_type = T; |
| 1747 |
using size_type = typename allocator_traits<Allocator>::size_type; |
| 1748 |
|
| 1749 |
// Constructors. |
| 1750 |
vector() {} |
| 1751 |
vector(size_type, const Allocator & = Allocator()) {} |
| 1752 |
vector(initializer_list<T> initializer_list, |
| 1753 |
const Allocator & = Allocator()) {} |
| 1754 |
vector(const vector &vector) {} |
| 1755 |
~vector(); |
| 1756 |
|
| 1757 |
// Modifiers. |
| 1758 |
void push_back(const T &value); |
| 1759 |
void push_back(T &&value); |
| 1760 |
template <typename... Args> T &emplace_back(Args &&...args); |
| 1761 |
|
| 1762 |
// Iterators |
| 1763 |
class InputIterator { |
| 1764 |
public: |
| 1765 |
InputIterator(const InputIterator &); |
| 1766 |
~InputIterator(); |
| 1767 |
InputIterator &operator=(const InputIterator &); |
| 1768 |
InputIterator &operator++(); |
| 1769 |
T &operator*() const; |
| 1770 |
bool operator!=(const InputIterator &) const; |
| 1771 |
bool operator==(const InputIterator &) const; |
| 1772 |
}; |
| 1773 |
typedef InputIterator iterator; |
| 1774 |
typedef const InputIterator const_iterator; |
| 1775 |
iterator begin() noexcept; |
| 1776 |
const_iterator begin() const noexcept; |
| 1777 |
const_iterator cbegin() const noexcept; |
| 1778 |
iterator end() noexcept; |
| 1779 |
const_iterator end() const noexcept; |
| 1780 |
const_iterator cend() const noexcept; |
| 1781 |
T *data() noexcept; |
| 1782 |
const T *data() const noexcept; |
| 1783 |
T &operator[](int n); |
| 1784 |
const T &operator[](int n) const; |
| 1785 |
T &at(int n); |
| 1786 |
const T &at(int n) const; |
| 1787 |
size_t size() const; |
| 1788 |
}; |
| 1789 |
} // namespace std |
| 1790 |
#endif // STD_VECTOR_H |
| 1791 |
)cc"; |
| 1792 |
|
| 1793 |
static constexpr char StdPairHeader[] = R"cc( |
| 1794 |
#ifndef STD_PAIR_H |
| 1795 |
#define STD_PAIR_H |
| 1796 |
namespace std { |
| 1797 |
template <class T1, class T2> struct pair { |
| 1798 |
T1 first; |
| 1799 |
T2 second; |
| 1800 |
|
| 1801 |
typedef T1 first_type; |
| 1802 |
typedef T2 second_type; |
| 1803 |
|
| 1804 |
constexpr pair(); |
| 1805 |
|
| 1806 |
template <class U1, class U2> pair(pair<U1, U2> &&p); |
| 1807 |
|
| 1808 |
template <class U1, class U2> pair(U1 &&x, U2 &&y); |
| 1809 |
}; |
| 1810 |
|
| 1811 |
template <class T1, class T2> pair<T1, T2> make_pair(T1 &&t1, T2 &&t2); |
| 1812 |
} // namespace std |
| 1813 |
#endif // STD_PAIR_H |
| 1814 |
)cc"; |
| 1815 |
|
| 1816 |
constexpr const char AbslLogHeader[] = R"cc( |
| 1817 |
#ifndef ABSL_LOG_H |
| 1818 |
#define ABSL_LOG_H |
| 1819 |
|
| 1820 |
#include "std_pair.h" |
| 1821 |
|
| 1822 |
namespace absl { |
| 1823 |
|
| 1824 |
#define ABSL_PREDICT_FALSE(x) (__builtin_expect(false || (x), false)) |
| 1825 |
#define ABSL_PREDICT_TRUE(x) (__builtin_expect(false || (x), true)) |
| 1826 |
|
| 1827 |
namespace log_internal { |
| 1828 |
class LogMessage { |
| 1829 |
public: |
| 1830 |
LogMessage(); |
| 1831 |
LogMessage &stream(); |
| 1832 |
LogMessage &InternalStream(); |
| 1833 |
LogMessage &WithVerbosity(int verboselevel); |
| 1834 |
template <typename T> LogMessage &operator<<(const T &); |
| 1835 |
}; |
| 1836 |
class LogMessageFatal : public LogMessage { |
| 1837 |
public: |
| 1838 |
LogMessageFatal(); |
| 1839 |
~LogMessageFatal() __attribute__((noreturn)); |
| 1840 |
}; |
| 1841 |
class LogMessageQuietlyFatal : public LogMessage { |
| 1842 |
public: |
| 1843 |
LogMessageQuietlyFatal(); |
| 1844 |
~LogMessageQuietlyFatal() __attribute__((noreturn)); |
| 1845 |
}; |
| 1846 |
class Voidify final { |
| 1847 |
public: |
| 1848 |
// This has to be an operator with a precedence lower than << but higher |
| 1849 |
// than |
| 1850 |
// ?: |
| 1851 |
template <typename T> void operator&&(const T &) const && {} |
| 1852 |
}; |
| 1853 |
} // namespace log_internal |
| 1854 |
} // namespace absl |
| 1855 |
|
| 1856 |
#ifndef NULL |
| 1857 |
#define NULL __null |
| 1858 |
#endif |
| 1859 |
extern "C" void abort() {} |
| 1860 |
#define ABSL_LOG_INTERNAL_LOG_INFO ::absl::log_internal::LogMessage() |
| 1861 |
#define ABSL_LOG_INTERNAL_LOG_WARNING ::absl::log_internal::LogMessage() |
| 1862 |
#define ABSL_LOG_INTERNAL_LOG_ERROR ::absl::log_internal::LogMessage() |
| 1863 |
#define ABSL_LOG_INTERNAL_LOG_FATAL ::absl::log_internal::LogMessageFatal() |
| 1864 |
#define ABSL_LOG_INTERNAL_LOG_QFATAL \ |
| 1865 |
::absl::log_internal::LogMessageQuietlyFatal() |
| 1866 |
#define LOG(severity) ABSL_LOG_INTERNAL_LOG_##severity.InternalStream() |
| 1867 |
|
| 1868 |
#define PREDICT_FALSE(x) (__builtin_expect(x, 0)) |
| 1869 |
#define ABSL_LOG_INTERNAL_STRIP_STRING_LITERAL(lit) lit |
| 1870 |
|
| 1871 |
#define ABSL_LOG_INTERNAL_STATELESS_CONDITION(condition) \ |
| 1872 |
switch (0) \ |
| 1873 |
case 0: \ |
| 1874 |
default: \ |
| 1875 |
!(condition) ? (void)0 : ::absl::log_internal::Voidify() && |
| 1876 |
|
| 1877 |
#define ABSL_LOG_INTERNAL_CONDITION_INFO(type, condition) \ |
| 1878 |
ABSL_LOG_INTERNAL_##type##_CONDITION(condition) |
| 1879 |
|
| 1880 |
#define ABSL_LOG_INTERNAL_CONDITION_FATAL(type, condition) \ |
| 1881 |
ABSL_LOG_INTERNAL_##type##_CONDITION(condition) |
| 1882 |
|
| 1883 |
#define ABSL_LOG_INTERNAL_CONDITION_QFATAL(type, condition) \ |
| 1884 |
ABSL_LOG_INTERNAL_##type##_CONDITION(condition) |
| 1885 |
|
| 1886 |
#define ABSL_CHECK_IMPL(condition, condition_text) \ |
| 1887 |
ABSL_LOG_INTERNAL_CONDITION_FATAL(STATELESS, \ |
| 1888 |
ABSL_PREDICT_FALSE(!(condition))) \ |
| 1889 |
ABSL_LOG_INTERNAL_CHECK(condition_text).InternalStream() |
| 1890 |
|
| 1891 |
#define ABSL_QCHECK_IMPL(condition, condition_text) \ |
| 1892 |
ABSL_LOG_INTERNAL_CONDITION_QFATAL(STATELESS, \ |
| 1893 |
ABSL_PREDICT_FALSE(!(condition))) \ |
| 1894 |
ABSL_LOG_INTERNAL_QCHECK(condition_text).InternalStream() |
| 1895 |
|
| 1896 |
#define CHECK(condition) ABSL_CHECK_IMPL((condition), #condition) |
| 1897 |
#define DCHECK(condition) CHECK(condition) |
| 1898 |
#define QCHECK(condition) ABSL_QCHECK_IMPL((condition), #condition) |
| 1899 |
|
| 1900 |
#define ABSL_LOG_INTERNAL_MAX_LOG_VERBOSITY_CHECK(x) |
| 1901 |
|
| 1902 |
namespace absl { |
| 1903 |
|
| 1904 |
template <typename T> class StatusOr; |
| 1905 |
class Status; |
| 1906 |
|
| 1907 |
namespace status_internal { |
| 1908 |
std::string *MakeCheckFailString(const absl::Status *status, |
| 1909 |
const char *prefix); |
| 1910 |
} // namespace status_internal |
| 1911 |
|
| 1912 |
namespace log_internal { |
| 1913 |
template <class T> const T &GetReferenceableValue(const T &t); |
| 1914 |
char GetReferenceableValue(char t); |
| 1915 |
unsigned char GetReferenceableValue(unsigned char t); |
| 1916 |
signed char GetReferenceableValue(signed char t); |
| 1917 |
short GetReferenceableValue(short t); |
| 1918 |
unsigned short GetReferenceableValue(unsigned short t); |
| 1919 |
int GetReferenceableValue(int t); |
| 1920 |
unsigned int GetReferenceableValue(unsigned int t); |
| 1921 |
long GetReferenceableValue(long t); |
| 1922 |
unsigned long GetReferenceableValue(unsigned long t); |
| 1923 |
long long GetReferenceableValue(long long t); |
| 1924 |
unsigned long long GetReferenceableValue(unsigned long long t); |
| 1925 |
const absl::Status *AsStatus(const absl::Status &s); |
| 1926 |
template <typename T> const absl::Status *AsStatus(const absl::StatusOr<T> &s); |
| 1927 |
} // namespace log_internal |
| 1928 |
} // namespace absl |
| 1929 |
// TODO(tkd): this still doesn't allow operator<<, unlike the real CHECK_ |
| 1930 |
// macros. |
| 1931 |
#define ABSL_LOG_INTERNAL_CHECK_OP(name, op, val1, val2) \ |
| 1932 |
while (char *_result = ::absl::log_internal::name##Impl( \ |
| 1933 |
::absl::log_internal::GetReferenceableValue(val1), \ |
| 1934 |
::absl::log_internal::GetReferenceableValue(val2), \ |
| 1935 |
#val1 " " #op " " #val2)) \ |
| 1936 |
(void)0 |
| 1937 |
#define ABSL_LOG_INTERNAL_QCHECK_OP(name, op, val1, val2) \ |
| 1938 |
while (char *_result = ::absl::log_internal::name##Impl( \ |
| 1939 |
::absl::log_internal::GetReferenceableValue(val1), \ |
| 1940 |
::absl::log_internal::GetReferenceableValue(val2), \ |
| 1941 |
#val1 " " #op " " #val2)) \ |
| 1942 |
(void)0 |
| 1943 |
namespace absl { |
| 1944 |
namespace log_internal { |
| 1945 |
template <class T1, class T2> |
| 1946 |
char *Check_NEImpl(const T1 &v1, const T2 &v2, const char *names); |
| 1947 |
template <class T1, class T2> |
| 1948 |
char *Check_EQImpl(const T1 &v1, const T2 &v2, const char *names); |
| 1949 |
template <class T1, class T2> |
| 1950 |
char *Check_LTImpl(const T1 &v1, const T2 &v2, const char *names); |
| 1951 |
|
| 1952 |
#define CHECK_EQ(a, b) ABSL_LOG_INTERNAL_CHECK_OP(Check_EQ, ==, a, b) |
| 1953 |
#define CHECK_NE(a, b) ABSL_LOG_INTERNAL_CHECK_OP(Check_NE, !=, a, b) |
| 1954 |
#define CHECK_LT(a, b) ABSL_LOG_INTERNAL_CHECK_OP(Check_EQ, <, a, b) |
| 1955 |
|
| 1956 |
#define QCHECK_EQ(a, b) ABSL_LOG_INTERNAL_QCHECK_OP(Check_EQ, ==, a, b) |
| 1957 |
#define QCHECK_NE(a, b) ABSL_LOG_INTERNAL_QCHECK_OP(Check_NE, !=, a, b) |
| 1958 |
} // namespace log_internal |
| 1959 |
} // namespace absl |
| 1960 |
|
| 1961 |
#define CHECK_NOTNULL(x) CHECK((x) != nullptr) |
| 1962 |
|
| 1963 |
#define ABSL_LOG_INTERNAL_CHECK(failure_message) \ |
| 1964 |
::absl::log_internal::LogMessageFatal() |
| 1965 |
#define ABSL_LOG_INTERNAL_QCHECK(failure_message) \ |
| 1966 |
::absl::log_internal::LogMessageQuietlyFatal() |
| 1967 |
#define ABSL_LOG_INTERNAL_CHECK_OK(val) \ |
| 1968 |
for (::std::pair<const ::absl::Status *, ::std::string *> \ |
| 1969 |
absl_log_internal_check_ok_goo; \ |
| 1970 |
absl_log_internal_check_ok_goo.first = \ |
| 1971 |
::absl::log_internal::AsStatus(val), \ |
| 1972 |
absl_log_internal_check_ok_goo.second = \ |
| 1973 |
ABSL_PREDICT_TRUE(absl_log_internal_check_ok_goo.first->ok()) \ |
| 1974 |
? nullptr \ |
| 1975 |
: ::absl::status_internal::MakeCheckFailString( \ |
| 1976 |
absl_log_internal_check_ok_goo.first, \ |
| 1977 |
ABSL_LOG_INTERNAL_STRIP_STRING_LITERAL(#val " is OK")), \ |
| 1978 |
!ABSL_PREDICT_TRUE(absl_log_internal_check_ok_goo.first->ok());) \ |
| 1979 |
ABSL_LOG_INTERNAL_CHECK(*absl_log_internal_check_ok_goo.second) \ |
| 1980 |
.InternalStream() |
| 1981 |
#define ABSL_LOG_INTERNAL_QCHECK_OK(val) \ |
| 1982 |
for (::std::pair<const ::absl::Status *, ::std::string *> \ |
| 1983 |
absl_log_internal_check_ok_goo; \ |
| 1984 |
absl_log_internal_check_ok_goo.first = \ |
| 1985 |
::absl::log_internal::AsStatus(val), \ |
| 1986 |
absl_log_internal_check_ok_goo.second = \ |
| 1987 |
ABSL_PREDICT_TRUE(absl_log_internal_check_ok_goo.first->ok()) \ |
| 1988 |
? nullptr \ |
| 1989 |
: ::absl::status_internal::MakeCheckFailString( \ |
| 1990 |
absl_log_internal_check_ok_goo.first, \ |
| 1991 |
ABSL_LOG_INTERNAL_STRIP_STRING_LITERAL(#val " is OK")), \ |
| 1992 |
!ABSL_PREDICT_TRUE(absl_log_internal_check_ok_goo.first->ok());) \ |
| 1993 |
ABSL_LOG_INTERNAL_QCHECK(*absl_log_internal_check_ok_goo.second) \ |
| 1994 |
.InternalStream() |
| 1995 |
|
| 1996 |
#define CHECK_OK(val) ABSL_LOG_INTERNAL_CHECK_OK(val) |
| 1997 |
#define DCHECK_OK(val) ABSL_LOG_INTERNAL_CHECK_OK(val) |
| 1998 |
#define QCHECK_OK(val) ABSL_LOG_INTERNAL_QCHECK_OK(val) |
| 1999 |
|
| 2000 |
#endif // ABSL_LOG_H |
| 2001 |
)cc"; |
| 2002 |
|
| 2003 |
constexpr const char TestingDefsHeader[] = R"cc( |
| 2004 |
#pragma clang system_header |
| 2005 |
|
| 2006 |
#ifndef TESTING_DEFS_H |
| 2007 |
#define TESTING_DEFS_H |
| 2008 |
|
| 2009 |
#include "absl_type_traits.h" |
| 2010 |
#include "std_initializer_list.h" |
| 2011 |
#include "std_string.h" |
| 2012 |
#include "std_type_traits.h" |
| 2013 |
#include "std_utility.h" |
| 2014 |
|
| 2015 |
namespace testing { |
| 2016 |
struct AssertionResult { |
| 2017 |
template <typename T> |
| 2018 |
explicit AssertionResult(const T &res, bool enable_if = true) {} |
| 2019 |
~AssertionResult(); |
| 2020 |
operator bool() const; |
| 2021 |
template <typename T> AssertionResult &operator<<(const T &value); |
| 2022 |
const char *failure_message() const; |
| 2023 |
}; |
| 2024 |
|
| 2025 |
class TestPartResult { |
| 2026 |
public: |
| 2027 |
enum Type { kSuccess, kNonFatalFailure, kFatalFailure, kSkip }; |
| 2028 |
}; |
| 2029 |
|
| 2030 |
class Test { |
| 2031 |
public: |
| 2032 |
virtual ~Test() = default; |
| 2033 |
|
| 2034 |
protected: |
| 2035 |
virtual void SetUp() {} |
| 2036 |
}; |
| 2037 |
|
| 2038 |
class Message { |
| 2039 |
public: |
| 2040 |
template <typename T> Message &operator<<(const T &val); |
| 2041 |
}; |
| 2042 |
|
| 2043 |
namespace internal { |
| 2044 |
class AssertHelper { |
| 2045 |
public: |
| 2046 |
AssertHelper(TestPartResult::Type type, const char *file, int line, |
| 2047 |
const char *message); |
| 2048 |
void operator=(const Message &message) const; |
| 2049 |
}; |
| 2050 |
|
| 2051 |
class EqHelper { |
| 2052 |
public: |
| 2053 |
template <typename T1, typename T2> |
| 2054 |
static AssertionResult Compare(const char *lhx, const char *rhx, |
| 2055 |
const T1 &lhs, const T2 &rhs); |
| 2056 |
}; |
| 2057 |
|
| 2058 |
#define GTEST_IMPL_CMP_HELPER_(op_name) \ |
| 2059 |
template <typename T1, typename T2> \ |
| 2060 |
AssertionResult CmpHelper##op_name(const char *expr1, const char *expr2, \ |
| 2061 |
const T1 &val1, const T2 &val2); |
| 2062 |
|
| 2063 |
GTEST_IMPL_CMP_HELPER_(NE) |
| 2064 |
GTEST_IMPL_CMP_HELPER_(LE) |
| 2065 |
GTEST_IMPL_CMP_HELPER_(LT) |
| 2066 |
GTEST_IMPL_CMP_HELPER_(GE) |
| 2067 |
GTEST_IMPL_CMP_HELPER_(GT) |
| 2068 |
|
| 2069 |
#undef GTEST_IMPL_CMP_HELPER_ |
| 2070 |
|
| 2071 |
std::string GetBoolAssertionFailureMessage( |
| 2072 |
const AssertionResult &assertion_result, const char *expression_text, |
| 2073 |
const char *actual_predicate_value, const char *expected_predicate_value); |
| 2074 |
|
| 2075 |
template <typename M> class PredicateFormatterFromMatcher { |
| 2076 |
public: |
| 2077 |
template <typename T> |
| 2078 |
AssertionResult operator()(const char *value_text, const T &x) const; |
| 2079 |
}; |
| 2080 |
|
| 2081 |
template <typename M> |
| 2082 |
inline PredicateFormatterFromMatcher<M> |
| 2083 |
MakePredicateFormatterFromMatcher(M matcher) { |
| 2084 |
return PredicateFormatterFromMatcher<M>(); |
| 2085 |
} |
| 2086 |
} // namespace internal |
| 2087 |
|
| 2088 |
namespace status { |
| 2089 |
namespace internal_status { |
| 2090 |
class IsOkMatcher {}; |
| 2091 |
|
| 2092 |
class StatusIsMatcher {}; |
| 2093 |
|
| 2094 |
class CanonicalStatusIsMatcher {}; |
| 2095 |
|
| 2096 |
template <typename M> class IsOkAndHoldsMatcher {}; |
| 2097 |
|
| 2098 |
} // namespace internal_status |
| 2099 |
|
| 2100 |
internal_status::IsOkMatcher IsOk(); |
| 2101 |
|
| 2102 |
template <typename StatusCodeMatcher> |
| 2103 |
internal_status::StatusIsMatcher StatusIs(StatusCodeMatcher &&code_matcher); |
| 2104 |
|
| 2105 |
template <typename StatusCodeMatcher> |
| 2106 |
internal_status::CanonicalStatusIsMatcher |
| 2107 |
CanonicalStatusIs(StatusCodeMatcher &&code_matcher); |
| 2108 |
|
| 2109 |
template <typename InnerMatcher> |
| 2110 |
internal_status::IsOkAndHoldsMatcher<InnerMatcher> IsOkAndHolds(InnerMatcher m); |
| 2111 |
} // namespace status |
| 2112 |
|
| 2113 |
class IsTrueMatcher {}; |
| 2114 |
IsTrueMatcher IsTrue(); |
| 2115 |
|
| 2116 |
class IsFalseMatcher {}; |
| 2117 |
IsFalseMatcher IsFalse(); |
| 2118 |
|
| 2119 |
} // namespace testing |
| 2120 |
|
| 2121 |
namespace absl_testing { |
| 2122 |
namespace status_internal { |
| 2123 |
class IsOkMatcher {}; |
| 2124 |
template <typename M> class IsOkAndHoldsMatcher {}; |
| 2125 |
class StatusIsMatcher {}; |
| 2126 |
class CanonicalStatusIsMatcher {}; |
| 2127 |
} // namespace status_internal |
| 2128 |
status_internal::IsOkMatcher IsOk(); |
| 2129 |
template <typename InnerMatcher> |
| 2130 |
status_internal::IsOkAndHoldsMatcher<InnerMatcher> IsOkAndHolds(InnerMatcher m); |
| 2131 |
template <typename StatusCodeMatcher> |
| 2132 |
status_internal::StatusIsMatcher StatusIs(StatusCodeMatcher &&code_matcher); |
| 2133 |
|
| 2134 |
template <typename StatusCodeMatcher> |
| 2135 |
status_internal::CanonicalStatusIsMatcher |
| 2136 |
CanonicalStatusIs(StatusCodeMatcher &&code_matcher); |
| 2137 |
} // namespace absl_testing |
| 2138 |
|
| 2139 |
using testing::AssertionResult; |
| 2140 |
#define EXPECT_TRUE(x) \ |
| 2141 |
switch (0) \ |
| 2142 |
case 0: \ |
| 2143 |
default: \ |
| 2144 |
if (const AssertionResult gtest_ar_ = AssertionResult(x)) { \ |
| 2145 |
} else /* NOLINT */ \ |
| 2146 |
::testing::Message() |
| 2147 |
#define EXPECT_FALSE(x) EXPECT_TRUE(!(x)) |
| 2148 |
|
| 2149 |
#define GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ |
| 2150 |
switch (0) \ |
| 2151 |
case 0: \ |
| 2152 |
default: |
| 2153 |
|
| 2154 |
#define GTEST_ASSERT_(expression, on_failure) \ |
| 2155 |
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ |
| 2156 |
if (const ::testing::AssertionResult gtest_ar = (expression)) \ |
| 2157 |
; \ |
| 2158 |
else \ |
| 2159 |
on_failure(gtest_ar.failure_message()) |
| 2160 |
#define GTEST_PRED_FORMAT1_(pred_format, v1, on_failure) \ |
| 2161 |
GTEST_ASSERT_(pred_format(#v1, v1), on_failure) |
| 2162 |
#define GTEST_PRED_FORMAT2_(pred_format, v1, v2, on_failure) \ |
| 2163 |
GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2), on_failure) |
| 2164 |
#define GTEST_MESSAGE_AT_(file, line, message, result_type) \ |
| 2165 |
::testing::internal::AssertHelper(result_type, file, line, message) = \ |
| 2166 |
::testing::Message() |
| 2167 |
#define GTEST_MESSAGE_(message, result_type) \ |
| 2168 |
GTEST_MESSAGE_AT_(__FILE__, __LINE__, message, result_type) |
| 2169 |
#define GTEST_FATAL_FAILURE_(message) \ |
| 2170 |
return GTEST_MESSAGE_(message, ::testing::TestPartResult::kFatalFailure) |
| 2171 |
#define GTEST_NONFATAL_FAILURE_(message) \ |
| 2172 |
GTEST_MESSAGE_(message, ::testing::TestPartResult::kNonFatalFailure) |
| 2173 |
|
| 2174 |
#define ASSERT_PRED_FORMAT1(pred_format, v1) \ |
| 2175 |
GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_FATAL_FAILURE_) |
| 2176 |
#define ASSERT_PRED_FORMAT2(pred_format, v1, v2) \ |
| 2177 |
GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_FATAL_FAILURE_) |
| 2178 |
|
| 2179 |
#define ASSERT_THAT(value, matcher) \ |
| 2180 |
ASSERT_PRED_FORMAT1( \ |
| 2181 |
::testing::internal::MakePredicateFormatterFromMatcher(matcher), value) |
| 2182 |
#define ASSERT_OK(x) ASSERT_THAT(x, ::testing::status::IsOk()) |
| 2183 |
|
| 2184 |
#define EXPECT_PRED_FORMAT1(pred_format, v1) \ |
| 2185 |
GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_NONFATAL_FAILURE_) |
| 2186 |
#define EXPECT_PRED_FORMAT2(pred_format, v1, v2) \ |
| 2187 |
GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_NONFATAL_FAILURE_) |
| 2188 |
#define EXPECT_THAT(value, matcher) \ |
| 2189 |
EXPECT_PRED_FORMAT1( \ |
| 2190 |
::testing::internal::MakePredicateFormatterFromMatcher(matcher), value) |
| 2191 |
#define EXPECT_OK(expression) EXPECT_THAT(expression, ::testing::status::IsOk()) |
| 2192 |
|
| 2193 |
#define GTEST_TEST_BOOLEAN_(expression, text, actual, expected, fail) \ |
| 2194 |
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ |
| 2195 |
if (const ::testing::AssertionResult gtest_ar_ = \ |
| 2196 |
::testing::AssertionResult(expression)) \ |
| 2197 |
; \ |
| 2198 |
else \ |
| 2199 |
fail(::testing::internal::GetBoolAssertionFailureMessage( \ |
| 2200 |
gtest_ar_, text, #actual, #expected) \ |
| 2201 |
.c_str()) |
| 2202 |
#define GTEST_ASSERT_TRUE(condition) \ |
| 2203 |
GTEST_TEST_BOOLEAN_(condition, #condition, false, true, GTEST_FATAL_FAILURE_) |
| 2204 |
#define GTEST_ASSERT_FALSE(condition) \ |
| 2205 |
GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \ |
| 2206 |
GTEST_FATAL_FAILURE_) |
| 2207 |
#define ASSERT_TRUE(condition) GTEST_ASSERT_TRUE(condition) |
| 2208 |
#define ASSERT_FALSE(condition) GTEST_ASSERT_FALSE(condition) |
| 2209 |
|
| 2210 |
#define EXPECT_EQ(x, y) \ |
| 2211 |
EXPECT_PRED_FORMAT2(::testing::internal::EqHelper::Compare, x, y) |
| 2212 |
#define EXPECT_NE(x, y) \ |
| 2213 |
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperNE, x, y) |
| 2214 |
#define EXPECT_LT(x, y) \ |
| 2215 |
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLT, x, y) |
| 2216 |
#define EXPECT_GT(x, y) \ |
| 2217 |
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGT, x, y) |
| 2218 |
#define EXPECT_LE(x, y) \ |
| 2219 |
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLE, x, y) |
| 2220 |
#define EXPECT_GE(x, y) \ |
| 2221 |
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGE, x, y) |
| 2222 |
|
| 2223 |
#define ASSERT_EQ(x, y) \ |
| 2224 |
ASSERT_PRED_FORMAT2(testing::internal::EqHelper::Compare, x, y) |
| 2225 |
#define ASSERT_NE(x, y) \ |
| 2226 |
ASSERT_PRED_FORMAT2(testing::internal::CmpHelperNE, x, y) |
| 2227 |
#define ASSERT_LT(x, y) \ |
| 2228 |
ASSERT_PRED_FORMAT2(testing::internal::CmpHelperLT, x, y) |
| 2229 |
#define ASSERT_GT(x, y) \ |
| 2230 |
ASSERT_PRED_FORMAT2(testing::internal::CmpHelperGT, x, y) |
| 2231 |
#define ASSERT_LE(x, y) \ |
| 2232 |
ASSERT_PRED_FORMAT2(testing::internal::CmpHelperLE, x, y) |
| 2233 |
#define ASSERT_GE(x, y) \ |
| 2234 |
ASSERT_PRED_FORMAT2(testing::internal::CmpHelperGE, x, y) |
| 2235 |
|
| 2236 |
#endif // TESTING_DEFS_H |
| 2237 |
)cc"; |
| 2238 |
|
| 2239 |
constexpr const char StdUniquePtrHeader[] = R"cc( |
| 2240 |
namespace std { |
| 2241 |
|
| 2242 |
template <typename T> |
| 2243 |
struct default_delete {}; |
| 2244 |
|
| 2245 |
template <typename T, typename D = default_delete<T>> |
| 2246 |
class unique_ptr { |
| 2247 |
public: |
| 2248 |
using element_type = T; |
| 2249 |
using deleter_type = D; |
| 2250 |
|
| 2251 |
constexpr unique_ptr(); |
| 2252 |
constexpr unique_ptr(nullptr_t) noexcept; |
| 2253 |
unique_ptr(unique_ptr&&); |
| 2254 |
explicit unique_ptr(T*); |
| 2255 |
template <typename U, typename E> |
| 2256 |
unique_ptr(unique_ptr<U, E>&&); |
| 2257 |
|
| 2258 |
~unique_ptr(); |
| 2259 |
|
| 2260 |
unique_ptr& operator=(unique_ptr&&); |
| 2261 |
template <typename U, typename E> |
| 2262 |
unique_ptr& operator=(unique_ptr<U, E>&&); |
| 2263 |
unique_ptr& operator=(nullptr_t); |
| 2264 |
|
| 2265 |
void reset(T* = nullptr) noexcept; |
| 2266 |
T* release(); |
| 2267 |
T* get() const; |
| 2268 |
|
| 2269 |
T& operator*() const; |
| 2270 |
T* operator->() const; |
| 2271 |
explicit operator bool() const noexcept; |
| 2272 |
}; |
| 2273 |
|
| 2274 |
template <typename T, typename D> |
| 2275 |
class unique_ptr<T[], D> { |
| 2276 |
public: |
| 2277 |
T* get() const; |
| 2278 |
T& operator[](size_t i); |
| 2279 |
const T& operator[](size_t i) const; |
| 2280 |
}; |
| 2281 |
|
| 2282 |
template <typename T, typename... Args> |
| 2283 |
unique_ptr<T> make_unique(Args&&...); |
| 2284 |
|
| 2285 |
template <class T, class D> |
| 2286 |
void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept; |
| 2287 |
|
| 2288 |
template <class T1, class D1, class T2, class D2> |
| 2289 |
bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); |
| 2290 |
template <class T1, class D1, class T2, class D2> |
| 2291 |
bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); |
| 2292 |
template <class T1, class D1, class T2, class D2> |
| 2293 |
bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); |
| 2294 |
template <class T1, class D1, class T2, class D2> |
| 2295 |
bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); |
| 2296 |
template <class T1, class D1, class T2, class D2> |
| 2297 |
bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); |
| 2298 |
template <class T1, class D1, class T2, class D2> |
| 2299 |
bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); |
| 2300 |
|
| 2301 |
template <class T, class D> |
| 2302 |
bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept; |
| 2303 |
template <class T, class D> |
| 2304 |
bool operator==(nullptr_t, const unique_ptr<T, D>& y) noexcept; |
| 2305 |
template <class T, class D> |
| 2306 |
bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept; |
| 2307 |
template <class T, class D> |
| 2308 |
bool operator!=(nullptr_t, const unique_ptr<T, D>& y) noexcept; |
| 2309 |
template <class T, class D> |
| 2310 |
bool operator<(const unique_ptr<T, D>& x, nullptr_t); |
| 2311 |
template <class T, class D> |
| 2312 |
bool operator<(nullptr_t, const unique_ptr<T, D>& y); |
| 2313 |
template <class T, class D> |
| 2314 |
bool operator<=(const unique_ptr<T, D>& x, nullptr_t); |
| 2315 |
template <class T, class D> |
| 2316 |
bool operator<=(nullptr_t, const unique_ptr<T, D>& y); |
| 2317 |
template <class T, class D> |
| 2318 |
bool operator>(const unique_ptr<T, D>& x, nullptr_t); |
| 2319 |
template <class T, class D> |
| 2320 |
bool operator>(nullptr_t, const unique_ptr<T, D>& y); |
| 2321 |
template <class T, class D> |
| 2322 |
bool operator>=(const unique_ptr<T, D>& x, nullptr_t); |
| 2323 |
template <class T, class D> |
| 2324 |
bool operator>=(nullptr_t, const unique_ptr<T, D>& y); |
| 2325 |
} |
| 2326 |
)cc"; |
| 2327 |
|
| 2328 |
std::vector<std::pair<std::string, std::string>> getMockHeaders() { |
| 2329 |
std::vector<std::pair<std::string, std::string>> Headers; |
| 2330 |
Headers.emplace_back("cstddef.h", CStdDefHeader); |
| 2331 |
Headers.emplace_back("std_initializer_list.h", StdInitializerListHeader); |
| 2332 |
Headers.emplace_back("std_string.h", StdStringHeader); |
| 2333 |
Headers.emplace_back("std_type_traits.h", StdTypeTraitsHeader); |
| 2334 |
Headers.emplace_back("std_utility.h", StdUtilityHeader); |
| 2335 |
Headers.emplace_back("std_optional.h", StdOptionalHeader); |
| 2336 |
Headers.emplace_back("absl_type_traits.h", AbslTypeTraitsHeader); |
| 2337 |
Headers.emplace_back("absl_optional.h", AbslOptionalHeader); |
| 2338 |
Headers.emplace_back("base_optional.h", BaseOptionalHeader); |
| 2339 |
Headers.emplace_back("std_vector.h", StdVectorHeader); |
| 2340 |
Headers.emplace_back("std_pair.h", StdPairHeader); |
| 2341 |
Headers.emplace_back("status_defs.h", StatusDefsHeader); |
| 2342 |
Headers.emplace_back("statusor_defs.h", StatusOrDefsHeader); |
| 2343 |
Headers.emplace_back("absl_log.h", AbslLogHeader); |
| 2344 |
Headers.emplace_back("testing_defs.h", TestingDefsHeader); |
| 2345 |
Headers.emplace_back("std_unique_ptr.h", StdUniquePtrHeader); |
| 2346 |
return Headers; |
| 2347 |
} |
| 2348 |
|
| 2349 |
} // namespace test |
| 2350 |
} // namespace dataflow |
| 2351 |
} // namespace clang |