empty.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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_INLINE_VISIBILITY
  21. constexpr auto empty(const _Cont& __c)
  22. _NOEXCEPT_(noexcept(__c.empty()))
  23. -> decltype (__c.empty())
  24. { return __c.empty(); }
  25. template <class _Tp, size_t _Sz>
  26. _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
  27. constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; }
  28. template <class _Ep>
  29. _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
  30. constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
  31. #endif // _LIBCPP_STD_VER >= 17
  32. _LIBCPP_END_NAMESPACE_STD
  33. #endif // _LIBCPP___ITERATOR_EMPTY_H