Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:05

0001 
0002 //              Copyright Catch2 Authors
0003 // Distributed under the Boost Software License, Version 1.0.
0004 //   (See accompanying file LICENSE.txt or copy at
0005 //        https://www.boost.org/LICENSE_1_0.txt)
0006 
0007 // SPDX-License-Identifier: BSL-1.0
0008 #ifndef CATCH_CONTAINER_NONMEMBERS_HPP_INCLUDED
0009 #define CATCH_CONTAINER_NONMEMBERS_HPP_INCLUDED
0010 
0011 #include <catch2/internal/catch_compiler_capabilities.hpp>
0012 
0013 #include <cstddef>
0014 #include <initializer_list>
0015 
0016 // We want a simple polyfill over `std::empty`, `std::size` and so on
0017 // for C++14 or C++ libraries with incomplete support.
0018 // We also have to handle that MSVC std lib will happily provide these
0019 // under older standards.
0020 #if defined(CATCH_CPP17_OR_GREATER) || defined(_MSC_VER)
0021 
0022 // We are already using this header either way, so there shouldn't
0023 // be much additional overhead in including it to get the feature
0024 // test macros
0025 #include <string>
0026 
0027 #  if !defined(__cpp_lib_nonmember_container_access)
0028 #      define CATCH_CONFIG_POLYFILL_NONMEMBER_CONTAINER_ACCESS
0029 #  endif
0030 
0031 #else
0032 #define CATCH_CONFIG_POLYFILL_NONMEMBER_CONTAINER_ACCESS
0033 #endif
0034 
0035 
0036 
0037 namespace Catch {
0038 namespace Detail {
0039 
0040 #if defined(CATCH_CONFIG_POLYFILL_NONMEMBER_CONTAINER_ACCESS)
0041     template <typename Container>
0042     constexpr auto empty(Container const& cont) -> decltype(cont.empty()) {
0043         return cont.empty();
0044     }
0045     template <typename T, std::size_t N>
0046     constexpr bool empty(const T (&)[N]) noexcept {
0047         // GCC < 7 does not support the const T(&)[] parameter syntax
0048         // so we have to ignore the length explicitly
0049         (void)N;
0050         return false;
0051     }
0052     template <typename T>
0053     constexpr bool empty(std::initializer_list<T> list) noexcept {
0054         return list.size() > 0;
0055     }
0056 
0057 
0058     template <typename Container>
0059     constexpr auto size(Container const& cont) -> decltype(cont.size()) {
0060         return cont.size();
0061     }
0062     template <typename T, std::size_t N>
0063     constexpr std::size_t size(const T(&)[N]) noexcept {
0064         return N;
0065     }
0066 #endif // CATCH_CONFIG_POLYFILL_NONMEMBER_CONTAINER_ACCESS
0067 
0068 } // end namespace Detail
0069 } // end namespace Catch
0070 
0071 
0072 
0073 #endif // CATCH_CONTAINER_NONMEMBERS_HPP_INCLUDED