OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
ssize.hpp
1#pragma once
2
3#if __has_include(<version>)
4#include <version>
5// MacOSX11.3 SDK provides ssize but does not define it...
6#if __cpp_lib_ssize >= 201902L \
7 || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 114000 && _LIBCPP_STD_VER > 17) \
8 || defined(__EMSCRIPTEN__)
9#include <iterator>
10#define OSSIA_HAS_STD_SSIZE 1
11#endif
12#endif
13
14#if !defined(OSSIA_HAS_STD_SSIZE)
15#include <type_traits>
16namespace std
17{
18template <class T>
19static constexpr auto ssize(const T& t) noexcept
20{
21 return static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(t.size())>>>(
22 t.size());
23}
24
25template <class T, ptrdiff_t S>
26static constexpr ptrdiff_t ssize(const T (&)[S]) noexcept
27{
28 return S;
29}
30}
31#endif