empty.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef _LIBCPP___ITERATOR_EMPTY_H
  10. #define _LIBCPP___ITERATOR_EMPTY_H
  11. #include <__config>
  12. #include <cstddef>
  13. #include <initializer_list>
  14. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  15. # pragma GCC system_header
  16. #endif
  17. _LIBCPP_BEGIN_NAMESPACE_STD
  18. #if _LIBCPP_STD_VER >= 17
  19. template <class _Cont>
  20. _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI constexpr auto empty(const _Cont& __c)
  21. _NOEXCEPT_(noexcept(__c.empty())) -> decltype(__c.empty()) {
  22. return __c.empty();
  23. }
  24. template <class _Tp, size_t _Sz>
  25. _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI constexpr bool empty(const _Tp (&)[_Sz]) noexcept {
  26. return false;
  27. }
  28. template <class _Ep>
  29. _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI constexpr bool empty(initializer_list<_Ep> __il) noexcept {
  30. return __il.size() == 0;
  31. }
  32. #endif // _LIBCPP_STD_VER >= 17
  33. _LIBCPP_END_NAMESPACE_STD
  34. #endif // _LIBCPP___ITERATOR_EMPTY_H