Function signed_count

Summary

#include "breeze/counting/signed_count.hpp"

(1) template <typename T, std::ptrdiff_t n>
    constexpr std::ptrdiff_t signed_count(T const (&)[n]) noexcept

(2) template <typename T>
    constexpr std::ptrdiff_t signed_count(T const &t)

Function overload

Synopsis

#include "breeze/counting/signed_count.hpp"

template <typename T, std::ptrdiff_t n>
constexpr std::ptrdiff_t signed_count(T const (&)[n]) noexcept

Description

Arrays and containers element counter.

signed_count() provides an extension of container::size() that covers both standard containers and built-in arrays.

The syntax is, uniformly, breeze::signed_count( a ) regardless of the actual type of a.

Following C++ best practices, these templates return a signed integer. They are made obsolete in C++20 by the namespace-scope std::ssize()'s. However our version avoids any fancy derivation of the return type, even for containers.

See
begin(), end(), cbegin(), cend().
Returns
The number of elements of the array argument (obviously, n).

Source

Lines 47-52 in breeze/counting/signed_count.hpp.

template< typename T, std::ptrdiff_t n >
constexpr std::ptrdiff_t
signed_count( T const ( & )[ n ] ) noexcept
{
    return n ;
}

Synopsis

#include "breeze/counting/signed_count.hpp"

template <typename T>
constexpr std::ptrdiff_t signed_count(T const &t)

Description

Arrays and containers element counter.

signed_count() provides an extension of container::size() that covers both standard containers and built-in arrays.

The syntax is, uniformly, breeze::signed_count( a ) regardless of the actual type of a.

Following C++ best practices, these templates return a signed integer. They are made obsolete in C++20 by the namespace-scope std::ssize()'s. However our version avoids any fancy derivation of the return type, even for containers.

See
begin(), end(), cbegin(), cend().
Precondition
t.size() <= PTRDIFF_MAX
Returns
The value of t.size() converted to std::ptrdiff_t.

Source

Lines 65-77 in breeze/counting/signed_count.hpp.

template< typename T >
constexpr std::ptrdiff_t
signed_count( T const & t )
{
    typedef std::ptrdiff_t
                        return_type ;

    std::size_t const   max = std::numeric_limits< return_type >::max
                                BREEZE_PREVENT_MACRO_EXPANSION () ;

    BREEZE_ASSERT( t.size() <= max ) ;
    return static_cast< return_type >( t.size() ) ;
}