/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * Copyright 2018 Danny Robson */ #pragma once #include namespace cruft::alloc { /////////////////////////////////////////////////////////////////////////// /// A trait that evaluates to true if the queried type models cruft::allocator template < typename AllocatorT, typename = std::void_t<> > struct is_allocator : public std::false_type { }; //------------------------------------------------------------------------- template struct is_allocator ().allocate (0 )), decltype(std::declval ().allocate (0, 0)), //// Provides aligned an unaligned deallocation decltype(std::declval ().deallocate (nullptr, 0)), decltype(std::declval ().deallocate (nullptr, 0, 0)), //// Provides capacity/used/remain decltype(std::declval ().capacity ()), decltype(std::declval ().used ()), decltype(std::declval ().remain ()), decltype(std::declval ().begin ()), decltype(std::declval ().end ()), void > > : public std::true_type { }; //------------------------------------------------------------------------- template constexpr auto is_allocator_v = is_allocator::value; /////////////////////////////////////////////////////////////////////////// template > struct has_aligned_allocate : std::false_type {}; //------------------------------------------------------------------------- template struct has_aligned_allocate< AllocT, std::void_t< decltype ( std::declval ().allocate(16, 16) ) > >: public std::true_type {}; //------------------------------------------------------------------------- template constexpr auto has_aligned_allocate_v = has_aligned_allocate::value; }