diff --git a/templates/size.h b/templates/size.h new file mode 100644 index 00000000..8c859a85 --- /dev/null +++ b/templates/size.h @@ -0,0 +1,23 @@ +#include + +/** + * Get size of the given array. + * + * @param array An array + * @return Size of the array + */ +template +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 +constexpr auto size(const C& c) -> decltype(c.size()) { + return c.size(); +}