randomize_range.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //===----------------------------------------------------------------------===//
  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. #ifndef _LIBCPP___LIBCXX_DEBUG_RANDOMIZE_RANGE_H
  9. #define _LIBCPP___LIBCXX_DEBUG_RANDOMIZE_RANGE_H
  10. #include <__config>
  11. #ifdef _LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY
  12. # include <__algorithm/shuffle.h>
  13. # include <__type_traits/is_constant_evaluated.h>
  14. #endif
  15. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  16. # pragma GCC system_header
  17. #endif
  18. _LIBCPP_BEGIN_NAMESPACE_STD
  19. template <class _AlgPolicy, class _Iterator, class _Sentinel>
  20. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
  21. void __debug_randomize_range(_Iterator __first, _Sentinel __last) {
  22. #ifdef _LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY
  23. # ifdef _LIBCPP_CXX03_LANG
  24. # error Support for unspecified stability is only for C++11 and higher
  25. # endif
  26. if (!__libcpp_is_constant_evaluated())
  27. std::__shuffle<_AlgPolicy>(__first, __last, __libcpp_debug_randomizer());
  28. #else
  29. (void)__first;
  30. (void)__last;
  31. #endif
  32. }
  33. _LIBCPP_END_NAMESPACE_STD
  34. #endif // _LIBCPP___LIBCXX_DEBUG_RANDOMIZE_RANGE_H