Modernize the way we compute memory domains from type

Use a constexpr function instead of a template type
This commit is contained in:
Maxime Coste 2017-05-26 07:59:18 +01:00
parent ca38e10314
commit 6e389512f5
3 changed files with 8 additions and 9 deletions

View File

@ -6,6 +6,7 @@
#include <utility> #include <utility>
#include "assert.hh" #include "assert.hh"
#include "meta.hh"
namespace Kakoune namespace Kakoune
{ {
@ -141,14 +142,11 @@ bool operator!=(const Allocator<T1, d1>& lhs, const Allocator<T2, d2>& rhs)
return d1 != d2; return d1 != d2;
} }
constexpr MemoryDomain memory_domain(Meta::AnyType) { return MemoryDomain::Undefined; }
template<typename T> template<typename T>
struct TypeDomain constexpr decltype(T::Domain) memory_domain(Meta::Type<T>) { return T::Domain; }
{
static constexpr MemoryDomain domain() { return TypeDomain<T>::helper((T*)nullptr); }
private:
template<typename U> static decltype(U::Domain) constexpr helper(U*) { return U::Domain; }
static constexpr MemoryDomain helper(...) { return MemoryDomain::Undefined; }
};
template<MemoryDomain d> template<MemoryDomain d>
struct UseMemoryDomain struct UseMemoryDomain

View File

@ -6,7 +6,8 @@ namespace Kakoune
inline namespace Meta inline namespace Meta
{ {
template<typename T> struct Type {}; struct AnyType{};
template<typename T> struct Type : AnyType {};
} }

View File

@ -8,7 +8,7 @@
namespace Kakoune namespace Kakoune
{ {
template<typename T, MemoryDomain domain = TypeDomain<T>::domain()> template<typename T, MemoryDomain domain = memory_domain(Meta::Type<T>{})>
using Vector = std::vector<T, Allocator<T, domain>>; using Vector = std::vector<T, Allocator<T, domain>>;
} }