tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
size.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_ITERATOR_SIZE_HPP
4#define TETL_ITERATOR_SIZE_HPP
5
11
12namespace etl {
13
17template <typename C>
18constexpr auto size(C const& c) noexcept(noexcept(c.size())) -> decltype(c.size())
19{
20 return c.size();
21}
22
24template <typename T, size_t N>
25constexpr auto size(T const (&array)[N]) noexcept -> size_t
26{
28 return N;
29}
30
32template <typename C>
33constexpr auto ssize(C const& c) -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>
34{
35 using R = common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>;
36 return static_cast<R>(c.size());
37}
38
40template <typename T, ptrdiff_t N>
41constexpr auto ssize(T const (&array)[static_cast<size_t>(N)]) noexcept -> ptrdiff_t
42{
43 // The static_cast<size_t>(N) inside the array parameter is to keep gcc's
44 // sign-conversion warnings happy. Array sizes are of type size_t which
45 // triggers a signed to unsigned conversion in this case.
47 return N;
48}
49
50} // namespace etl
51
52#endif // TETL_ITERATOR_SIZE_HPP
constexpr auto ssize(C const &c) -> common_type_t< ptrdiff_t, make_signed_t< decltype(c.size())> >
Definition size.hpp:33
constexpr auto size(C const &c) noexcept(noexcept(c.size())) -> decltype(c.size())
Returns the size of the given container c or array array. Returns c.size(), converted to the return t...
Definition size.hpp:18
Definition adjacent_find.hpp:8
TETL_BUILTIN_PTRDIFF ptrdiff_t
etl::ptrdiff_t is the signed integer type of the result of subtracting two pointers.
Definition ptrdiff_t.hpp:14
typename make_signed< T >::type make_signed_t
Definition make_signed.hpp:82
typename common_type< T... >::type common_type_t
Definition common_type.hpp:50
constexpr auto ignore_unused(Types &&...) -> void
Explicitly ignore arguments or variables.
Definition ignore_unused.hpp:17
A container that encapsulates fixed size arrays.
Definition array.hpp:48