From adf5946711dd8a6d56028d229dc3c5e100bdd879 Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 7 Jan 2016 13:33:26 +0100 Subject: [PATCH] Core/Console: Add CountOf function Former-commit-id: 8ea1456bc8debae102ca616176febb15d3759d17 --- include/Nazara/Core/Algorithm.hpp | 2 ++ include/Nazara/Core/Algorithm.inl | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/Nazara/Core/Algorithm.hpp b/include/Nazara/Core/Algorithm.hpp index 408eb79cf..048c5d902 100644 --- a/include/Nazara/Core/Algorithm.hpp +++ b/include/Nazara/Core/Algorithm.hpp @@ -23,6 +23,8 @@ namespace Nz template auto Apply(O& object, F&& fn, Tuple&& t); template ByteArray ComputeHash(HashType hash, const T& v); template ByteArray ComputeHash(AbstractHash* hash, const T& v); + template constexpr std::size_t CountOf(T(&name)[N]) noexcept; + template std::size_t CountOf(const T& c); template void HashCombine(std::size_t& seed, const T& v); template diff --git a/include/Nazara/Core/Algorithm.inl b/include/Nazara/Core/Algorithm.inl index a23fea4e1..5977c6d42 100644 --- a/include/Nazara/Core/Algorithm.inl +++ b/include/Nazara/Core/Algorithm.inl @@ -62,6 +62,18 @@ namespace Nz return hash->End(); } + template + constexpr std::size_t CountOf(T(&name)[N]) noexcept + { + return N; + } + + template + std::size_t CountOf(const T& c) + { + return c.size(); + } + // Algorithme venant de CityHash par Google // http://stackoverflow.com/questions/8513911/how-to-create-a-good-hash-combine-with-64-bit-output-inspired-by-boosthash-co template