invert_if.h 836 B

123456789101112131415161718192021222324252627282930
  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___BIT_INVERT_IF_H
  9. #define _LIBCPP___BIT_INVERT_IF_H
  10. #include <__concepts/arithmetic.h>
  11. #include <__config>
  12. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  13. # pragma GCC system_header
  14. #endif
  15. _LIBCPP_BEGIN_NAMESPACE_STD
  16. template <bool _Invert, class _Tp>
  17. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp __invert_if(_Tp __v) {
  18. if (_Invert)
  19. return ~__v;
  20. return __v;
  21. }
  22. _LIBCPP_END_NAMESPACE_STD
  23. #endif // _LIBCPP___BIT_INVERT_IF_H