forked from OctaForge/libostd
add memory::UsesAllocator,UsesAllocatorConstructor
parent
64cfb5b715
commit
06a91b98f5
|
@ -1068,10 +1068,51 @@ inline AllocatorType<A> allocator_container_copy(const A &a) {
|
|||
>(), a);
|
||||
}
|
||||
|
||||
/* allocator arg */
|
||||
|
||||
struct AllocatorArg {};
|
||||
|
||||
constexpr AllocatorArg allocator_arg = AllocatorArg();
|
||||
|
||||
/* uses allocator */
|
||||
|
||||
namespace detail {
|
||||
template<typename T> struct HasAllocatorType {
|
||||
template<typename U> static char test(typename U::Allocator *);
|
||||
template<typename U> static int test(...);
|
||||
static constexpr bool value = (sizeof(test<T>(0)) == 1);
|
||||
};
|
||||
|
||||
template<typename T, typename A, bool = HasAllocatorType<T>::value>
|
||||
struct UsesAllocatorBase: IntegralConstant<bool,
|
||||
IsConvertible<A, typename T::Allocator>::value
|
||||
> {};
|
||||
|
||||
template<typename T, typename A>
|
||||
struct UsesAllocatorBase<T, A, false>: False {};
|
||||
}
|
||||
|
||||
template<typename T, typename A>
|
||||
struct UsesAllocator: detail::UsesAllocatorBase<T, A> {};
|
||||
|
||||
/* uses allocator ctor */
|
||||
|
||||
namespace detail {
|
||||
template<typename T, typename A, typename ...Args>
|
||||
struct UsesAllocCtor {
|
||||
static constexpr bool ua = UsesAllocator<T, A>::value;
|
||||
static constexpr bool ic = IsConstructible<
|
||||
T, AllocatorArg, A, Args...
|
||||
>::value;
|
||||
static constexpr int value = ua ? (2 - ic) : 0;
|
||||
};
|
||||
}
|
||||
|
||||
template<typename T, typename A, typename ...Args>
|
||||
struct UsesAllocatorConstructor: IntegralConstant<int,
|
||||
detail::UsesAllocCtor<T, A, Args...>::value
|
||||
> {};
|
||||
|
||||
} /* namespace octa */
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue