0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 18:11:59 +00:00

feat: add size utils

This commit is contained in:
Baoshuo Ren 2022-05-25 10:36:14 +08:00
parent a7343483b0
commit 98a50dc842
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

23
templates/size.h Normal file
View File

@ -0,0 +1,23 @@
#include <cstddef>
/**
* Get size of the given array.
*
* @param array An array
* @return Size of the array
*/
template <class T, std::size_t N>
constexpr std::size_t size(const T (&array)[N]) noexcept {
return N;
}
/**
* Get size of the given container.
*
* @param c An container
* @return Size of the container
*/
template <class C>
constexpr auto size(const C& c) -> decltype(c.size()) {
return c.size();
}