From 6e389512f548d3efdb4f25407fb51e0cbbdc8051 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 26 May 2017 07:59:18 +0100 Subject: [PATCH] Modernize the way we compute memory domains from type Use a constexpr function instead of a template type --- src/memory.hh | 12 +++++------- src/meta.hh | 3 ++- src/vector.hh | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/memory.hh b/src/memory.hh index 4d41c0c0..fe6f70ea 100644 --- a/src/memory.hh +++ b/src/memory.hh @@ -6,6 +6,7 @@ #include #include "assert.hh" +#include "meta.hh" namespace Kakoune { @@ -141,14 +142,11 @@ bool operator!=(const Allocator& lhs, const Allocator& rhs) return d1 != d2; } + +constexpr MemoryDomain memory_domain(Meta::AnyType) { return MemoryDomain::Undefined; } + template -struct TypeDomain -{ - static constexpr MemoryDomain domain() { return TypeDomain::helper((T*)nullptr); } -private: - template static decltype(U::Domain) constexpr helper(U*) { return U::Domain; } - static constexpr MemoryDomain helper(...) { return MemoryDomain::Undefined; } -}; +constexpr decltype(T::Domain) memory_domain(Meta::Type) { return T::Domain; } template struct UseMemoryDomain diff --git a/src/meta.hh b/src/meta.hh index 70a99428..04c343d5 100644 --- a/src/meta.hh +++ b/src/meta.hh @@ -6,7 +6,8 @@ namespace Kakoune inline namespace Meta { -template struct Type {}; +struct AnyType{}; +template struct Type : AnyType {}; } diff --git a/src/vector.hh b/src/vector.hh index c8cc9d08..e149998d 100644 --- a/src/vector.hh +++ b/src/vector.hh @@ -8,7 +8,7 @@ namespace Kakoune { -template::domain()> +template{})> using Vector = std::vector>; }