VCCC  2024.05
VisualCamp Common C++ library
ssize.hpp
Go to the documentation of this file.
1 //
2 // Created by yonggyulee on 2023/12/30.
3 //
4 
5 #ifndef VCCC_RANGES_SSIZE_HPP
6 #define VCCC_RANGES_SSIZE_HPP
7 
8 #include <type_traits>
9 #include <utility>
10 
12 #include "vccc/__ranges/size.hpp"
14 
15 namespace vccc {
16 namespace ranges {
17 namespace detail {
18 
19 template<typename T, bool = (sizeof(T) > sizeof(std::ptrdiff_t)) /* true */>
20 struct ssize_type {
21  using type = T;
22 };
23 template<typename T>
24 struct ssize_type<T, false> {
25  using type = std::ptrdiff_t;
26 };
27 
28 template<typename T, typename = void>
29 struct is_ranges_size_callable : std::false_type {};
30 template<typename T>
31 struct is_ranges_size_callable<T, void_t<decltype( vccc::ranges::size(std::declval<T>()) )>> : std::true_type {};
32 
33 struct ssize_niebloid {
35  constexpr auto operator()(T&& t) const {
36  using size_type = decltype(ranges::size(t));
37  using unsigned_type = std::make_unsigned_t<size_type>;
38  using R = typename ssize_type<unsigned_type>::type;
39  return static_cast<R>(ranges::size(t));
40  }
41 };
42 
43 } // namespace detail
44 
45 namespace niebloid {
46 
49 
56 VCCC_INLINE_OR_STATIC constexpr detail::ssize_niebloid ssize{};
57 
59 
60 } // namespace niebloid
61 using namespace niebloid;
62 
63 } // namespace ranges
64 } // namespace vccc
65 
66 #endif // VCCC_RANGES_SSIZE_HPP
constexpr VCCC_INLINE_OR_STATIC detail::ssize_niebloid ssize
returns a signed integer equal to the size of a range
Definition: ssize.hpp:56
constexpr VCCC_INLINE_OR_STATIC detail::size_niebloid size
returns the size of a container or array
Definition: size.hpp:145
void void_t
Definition: void_t.hpp:19
#define VCCC_INLINE_OR_STATIC
Definition: inline_or_static.hpp:9
Definition: directory.h:12
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 1 > value
Definition: key_value.hpp:35