diff options
author | Matthias Maennich <matthias@maennich.net> | 2017-10-05 10:43:06 (GMT) |
---|---|---|
committer | Matthias Maennich <matthias@maennich.net> | 2017-10-23 15:51:35 (GMT) |
commit | 57132765e078a8654d1166d7d8a1c29ec01f47b4 (patch) | |
tree | d51bdca75aec3b2446c5c3963046608f67406f88 /Source/cmAlgorithms.h | |
parent | fa501bc8262e4a0fa6207d351eef3bf6822748ef (diff) | |
download | CMake-57132765e078a8654d1166d7d8a1c29ec01f47b4.zip CMake-57132765e078a8654d1166d7d8a1c29ec01f47b4.tar.gz CMake-57132765e078a8654d1166d7d8a1c29ec01f47b4.tar.bz2 |
Replace cmArray{Begin,End,Size} by their standard counterparts
std::{begin,end} are part of C++11, std::{cbegin,cend} are part of C++14
and an standard compliant implementation has been introduced within the
'cm' namespace: cm::{cbegin,cend}.
std::size is only part of C++17, hence exposing a compliant implementation
within namespace cm (cm::size).
where possible, the standard implementations are reused.
Diffstat (limited to 'Source/cmAlgorithms.h')
-rw-r--r-- | Source/cmAlgorithms.h | 77 |
1 files changed, 61 insertions, 16 deletions
diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h index 69d0ed6..3380b78 100644 --- a/Source/cmAlgorithms.h +++ b/Source/cmAlgorithms.h @@ -43,22 +43,6 @@ inline bool cmHasLiteralSuffixImpl(const char* str1, const char* str2, } template <typename T, size_t N> -const T* cmArrayBegin(const T (&a)[N]) -{ - return a; -} -template <typename T, size_t N> -const T* cmArrayEnd(const T (&a)[N]) -{ - return a + N; -} -template <typename T, size_t N> -size_t cmArraySize(const T (&)[N]) -{ - return N; -} - -template <typename T, size_t N> bool cmHasLiteralPrefix(const T& str1, const char (&str2)[N]) { return cmHasLiteralPrefixImpl(str1, str2, N - 1); @@ -418,6 +402,67 @@ std::unique_ptr<T> make_unique(Args&&... args) #endif +#if __cplusplus >= 201703L || defined(_MSVC_LANG) && _MSVC_LANG >= 201703L + +using std::size; + +#else + +// std::size backport from C++17. +template <class C> +#if !defined(_MSC_VER) || _MSC_VER >= 1900 +constexpr +#endif + auto + size(C const& c) -> decltype(c.size()) +{ + return c.size(); +} + +template <typename T, size_t N> +#if !defined(_MSC_VER) || _MSC_VER >= 1900 +constexpr +#endif + std::size_t + size(const T (&)[N]) throw() +{ + return N; +} + +#endif + +#if __cplusplus >= 201402L || defined(_MSVC_LANG) && _MSVC_LANG >= 201402L + +using std::cbegin; +using std::cend; + +#else + +// std::c{begin,end} backport from C++14 +template <class C> +#if defined(_MSC_VER) && _MSC_VER < 1900 +auto cbegin(C const& c) +#else +constexpr auto cbegin(C const& c) noexcept(noexcept(std::begin(c))) +#endif + -> decltype(std::begin(c)) +{ + return std::begin(c); +} + +template <class C> +#if defined(_MSC_VER) && _MSC_VER < 1900 +auto cend(C const& c) +#else +constexpr auto cend(C const& c) noexcept(noexcept(std::end(c))) +#endif + -> decltype(std::end(c)) +{ + return std::end(c); +} + +#endif + } // namespace cm #endif |