198760c18f85bafd98dde7a309e1b0e677abd47d8Marshall Clow//===----------------------------------------------------------------------===//
298760c18f85bafd98dde7a309e1b0e677abd47d8Marshall Clow//
398760c18f85bafd98dde7a309e1b0e677abd47d8Marshall Clow//                     The LLVM Compiler Infrastructure
498760c18f85bafd98dde7a309e1b0e677abd47d8Marshall Clow//
598760c18f85bafd98dde7a309e1b0e677abd47d8Marshall Clow// This file is dual licensed under the MIT and the University of Illinois Open
698760c18f85bafd98dde7a309e1b0e677abd47d8Marshall Clow// Source Licenses. See LICENSE.TXT for details.
798760c18f85bafd98dde7a309e1b0e677abd47d8Marshall Clow//
898760c18f85bafd98dde7a309e1b0e677abd47d8Marshall Clow//===----------------------------------------------------------------------===//
998760c18f85bafd98dde7a309e1b0e677abd47d8Marshall Clow
1070342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant#ifndef MIN_ALLOCATOR_H
1170342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant#define MIN_ALLOCATOR_H
1270342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
1370342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant#if __cplusplus >= 201103L
1470342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
1570342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant#include <memory>
1670342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
1770342b99e227912742972b754ad86e75c5d7eefbHoward Hinnanttemplate <class T> class min_pointer;
1870342b99e227912742972b754ad86e75c5d7eefbHoward Hinnanttemplate <class T> class min_pointer<const T>;
1970342b99e227912742972b754ad86e75c5d7eefbHoward Hinnanttemplate <> class min_pointer<void>;
2070342b99e227912742972b754ad86e75c5d7eefbHoward Hinnanttemplate <> class min_pointer<const void>;
2170342b99e227912742972b754ad86e75c5d7eefbHoward Hinnanttemplate <class T> class min_allocator;
2270342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
2370342b99e227912742972b754ad86e75c5d7eefbHoward Hinnanttemplate <>
2470342b99e227912742972b754ad86e75c5d7eefbHoward Hinnantclass min_pointer<const void>
2570342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant{
2670342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    const void* ptr_;
2770342b99e227912742972b754ad86e75c5d7eefbHoward Hinnantpublic:
2870342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    min_pointer() noexcept = default;
2970342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    min_pointer(std::nullptr_t) : ptr_(nullptr) {}
3070342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    template <class T>
3170342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    min_pointer(min_pointer<T> p) : ptr_(p.ptr_) {}
3270342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
3370342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    explicit operator bool() const {return ptr_ != nullptr;}
3470342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
352c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant    friend bool operator==(min_pointer x, min_pointer y) {return x.ptr_ == y.ptr_;}
362c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant    friend bool operator!=(min_pointer x, min_pointer y) {return !(x == y);}
3770342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    template <class U> friend class min_pointer;
3870342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant};
3970342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
4070342b99e227912742972b754ad86e75c5d7eefbHoward Hinnanttemplate <>
4170342b99e227912742972b754ad86e75c5d7eefbHoward Hinnantclass min_pointer<void>
4270342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant{
4370342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    void* ptr_;
4470342b99e227912742972b754ad86e75c5d7eefbHoward Hinnantpublic:
4570342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    min_pointer() noexcept = default;
4670342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    min_pointer(std::nullptr_t) : ptr_(nullptr) {}
4770342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    template <class T,
4870342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant              class = typename std::enable_if
4970342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant                       <
5070342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant                            !std::is_const<T>::value
5170342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant                       >::type
5270342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant             >
5370342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    min_pointer(min_pointer<T> p) : ptr_(p.ptr_) {}
5470342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
5570342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    explicit operator bool() const {return ptr_ != nullptr;}
5670342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
572c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant    friend bool operator==(min_pointer x, min_pointer y) {return x.ptr_ == y.ptr_;}
582c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant    friend bool operator!=(min_pointer x, min_pointer y) {return !(x == y);}
5970342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    template <class U> friend class min_pointer;
6070342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant};
6170342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
6270342b99e227912742972b754ad86e75c5d7eefbHoward Hinnanttemplate <class T>
6370342b99e227912742972b754ad86e75c5d7eefbHoward Hinnantclass min_pointer
6470342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant{
6570342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    T* ptr_;
6670342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
6770342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    explicit min_pointer(T* p) : ptr_(p) {}
6870342b99e227912742972b754ad86e75c5d7eefbHoward Hinnantpublic:
6970342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    min_pointer() noexcept = default;
7070342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    min_pointer(std::nullptr_t) : ptr_(nullptr) {}
7170342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    explicit min_pointer(min_pointer<void> p) : ptr_(static_cast<T*>(p.ptr_)) {}
7270342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
7370342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    explicit operator bool() const {return ptr_ != nullptr;}
7470342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
7570342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    typedef std::ptrdiff_t difference_type;
7670342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    typedef T& reference;
7770342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    typedef T* pointer;
7870342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    typedef T value_type;
7970342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    typedef std::random_access_iterator_tag iterator_category;
8070342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
8170342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    reference operator*() const {return *ptr_;}
8270342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    pointer operator->() const {return ptr_;}
8370342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
8470342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    min_pointer& operator++() {++ptr_; return *this;}
8570342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    min_pointer operator++(int) {min_pointer tmp(*this); ++ptr_; return tmp;}
8670342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
8770342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    min_pointer& operator--() {--ptr_; return *this;}
8870342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    min_pointer operator--(int) {min_pointer tmp(*this); --ptr_; return tmp;}
8970342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
9070342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    min_pointer& operator+=(difference_type n) {ptr_ += n; return *this;}
9170342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    min_pointer& operator-=(difference_type n) {ptr_ -= n; return *this;}
9270342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
9370342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    min_pointer operator+(difference_type n) const
9470342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    {
9570342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant        min_pointer tmp(*this);
9670342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant        tmp += n;
9770342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant        return tmp;
9870342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    }
9970342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
10070342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    friend min_pointer operator+(difference_type n, min_pointer x)
10170342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    {
10270342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant        return x + n;
10370342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    }
10470342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
10570342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    min_pointer operator-(difference_type n) const
10670342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    {
10770342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant        min_pointer tmp(*this);
10870342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant        tmp -= n;
10970342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant        return tmp;
11070342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    }
11170342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
11270342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    friend difference_type operator-(min_pointer x, min_pointer y)
11370342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    {
11470342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant        return x.ptr_ - y.ptr_;
11570342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    }
11670342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
11770342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    reference operator[](difference_type n) const {return ptr_[n];}
11870342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
11970342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    friend bool operator< (min_pointer x, min_pointer y) {return x.ptr_ < y.ptr_;}
12070342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    friend bool operator> (min_pointer x, min_pointer y) {return y < x;}
12170342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    friend bool operator<=(min_pointer x, min_pointer y) {return !(y < x);}
12270342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    friend bool operator>=(min_pointer x, min_pointer y) {return !(x < y);}
12370342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
12470342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    static min_pointer pointer_to(T& t) {return min_pointer(std::addressof(t));}
12570342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
1262c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant    friend bool operator==(min_pointer x, min_pointer y) {return x.ptr_ == y.ptr_;}
1272c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant    friend bool operator!=(min_pointer x, min_pointer y) {return !(x == y);}
12870342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    template <class U> friend class min_pointer;
12970342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    template <class U> friend class min_allocator;
13070342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant};
13170342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
13270342b99e227912742972b754ad86e75c5d7eefbHoward Hinnanttemplate <class T>
13370342b99e227912742972b754ad86e75c5d7eefbHoward Hinnantclass min_pointer<const T>
13470342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant{
13570342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    const T* ptr_;
13670342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
13770342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    explicit min_pointer(const T* p) : ptr_(p) {}
13870342b99e227912742972b754ad86e75c5d7eefbHoward Hinnantpublic:
13970342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    min_pointer() noexcept = default;
14070342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    min_pointer(std::nullptr_t) : ptr_(nullptr) {}
14170342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    min_pointer(min_pointer<T> p) : ptr_(p.ptr_) {}
14270342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    explicit min_pointer(min_pointer<const void> p) : ptr_(static_cast<const T*>(p.ptr_)) {}
14370342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
14470342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    explicit operator bool() const {return ptr_ != nullptr;}
14570342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
14670342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    typedef std::ptrdiff_t difference_type;
14770342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    typedef const T& reference;
14870342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    typedef const T* pointer;
14970342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    typedef const T value_type;
15070342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    typedef std::random_access_iterator_tag iterator_category;
15170342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
15270342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    reference operator*() const {return *ptr_;}
15370342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    pointer operator->() const {return ptr_;}
15470342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
15570342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    min_pointer& operator++() {++ptr_; return *this;}
15670342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    min_pointer operator++(int) {min_pointer tmp(*this); ++ptr_; return tmp;}
15770342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
15870342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    min_pointer& operator--() {--ptr_; return *this;}
15970342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    min_pointer operator--(int) {min_pointer tmp(*this); --ptr_; return tmp;}
16070342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
16170342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    min_pointer& operator+=(difference_type n) {ptr_ += n; return *this;}
16270342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    min_pointer& operator-=(difference_type n) {ptr_ -= n; return *this;}
16370342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
16470342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    min_pointer operator+(difference_type n) const
16570342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    {
16670342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant        min_pointer tmp(*this);
16770342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant        tmp += n;
16870342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant        return tmp;
16970342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    }
17070342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
17170342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    friend min_pointer operator+(difference_type n, min_pointer x)
17270342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    {
17370342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant        return x + n;
17470342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    }
17570342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
17670342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    min_pointer operator-(difference_type n) const
17770342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    {
17870342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant        min_pointer tmp(*this);
17970342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant        tmp -= n;
18070342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant        return tmp;
18170342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    }
18270342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
18370342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    friend difference_type operator-(min_pointer x, min_pointer y)
18470342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    {
18570342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant        return x.ptr_ - y.ptr_;
18670342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    }
18770342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
18870342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    reference operator[](difference_type n) const {return ptr_[n];}
18970342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
19070342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    friend bool operator< (min_pointer x, min_pointer y) {return x.ptr_ < y.ptr_;}
19170342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    friend bool operator> (min_pointer x, min_pointer y) {return y < x;}
19270342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    friend bool operator<=(min_pointer x, min_pointer y) {return !(y < x);}
19370342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    friend bool operator>=(min_pointer x, min_pointer y) {return !(x < y);}
19470342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
19570342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    static min_pointer pointer_to(const T& t) {return min_pointer(std::addressof(t));}
19670342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
1972c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant    friend bool operator==(min_pointer x, min_pointer y) {return x.ptr_ == y.ptr_;}
1982c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant    friend bool operator!=(min_pointer x, min_pointer y) {return !(x == y);}
19970342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    template <class U> friend class min_pointer;
20070342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant};
20170342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
20270342b99e227912742972b754ad86e75c5d7eefbHoward Hinnanttemplate <class T>
20370342b99e227912742972b754ad86e75c5d7eefbHoward Hinnantinline
20470342b99e227912742972b754ad86e75c5d7eefbHoward Hinnantbool
20570342b99e227912742972b754ad86e75c5d7eefbHoward Hinnantoperator==(min_pointer<T> x, std::nullptr_t)
20670342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant{
20770342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    return !static_cast<bool>(x);
20870342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant}
20970342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
21070342b99e227912742972b754ad86e75c5d7eefbHoward Hinnanttemplate <class T>
21170342b99e227912742972b754ad86e75c5d7eefbHoward Hinnantinline
21270342b99e227912742972b754ad86e75c5d7eefbHoward Hinnantbool
21370342b99e227912742972b754ad86e75c5d7eefbHoward Hinnantoperator==(std::nullptr_t, min_pointer<T> x)
21470342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant{
21570342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    return !static_cast<bool>(x);
21670342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant}
21770342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
21870342b99e227912742972b754ad86e75c5d7eefbHoward Hinnanttemplate <class T>
21970342b99e227912742972b754ad86e75c5d7eefbHoward Hinnantinline
22070342b99e227912742972b754ad86e75c5d7eefbHoward Hinnantbool
22170342b99e227912742972b754ad86e75c5d7eefbHoward Hinnantoperator!=(min_pointer<T> x, std::nullptr_t)
22270342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant{
22370342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    return static_cast<bool>(x);
22470342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant}
22570342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
22670342b99e227912742972b754ad86e75c5d7eefbHoward Hinnanttemplate <class T>
22770342b99e227912742972b754ad86e75c5d7eefbHoward Hinnantinline
22870342b99e227912742972b754ad86e75c5d7eefbHoward Hinnantbool
22970342b99e227912742972b754ad86e75c5d7eefbHoward Hinnantoperator!=(std::nullptr_t, min_pointer<T> x)
23070342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant{
23170342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    return static_cast<bool>(x);
23270342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant}
23370342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
23470342b99e227912742972b754ad86e75c5d7eefbHoward Hinnanttemplate <class T>
23570342b99e227912742972b754ad86e75c5d7eefbHoward Hinnantclass min_allocator
23670342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant{
23770342b99e227912742972b754ad86e75c5d7eefbHoward Hinnantpublic:
23870342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    typedef T value_type;
23970342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    typedef min_pointer<T> pointer;
24070342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
24170342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    min_allocator() = default;
24270342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    template <class U>
24370342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    min_allocator(min_allocator<U>) {}
24470342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
24570342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    pointer allocate(std::ptrdiff_t n)
24670342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    {
24770342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant        return pointer(static_cast<T*>(::operator new(n*sizeof(T))));
24870342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    }
24970342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
25070342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    void deallocate(pointer p, std::ptrdiff_t)
25170342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    {
25270342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant        return ::operator delete(p.ptr_);
25370342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    }
25470342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
25570342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    friend bool operator==(min_allocator, min_allocator) {return true;}
25670342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant    friend bool operator!=(min_allocator x, min_allocator y) {return !(x == y);}
25770342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant};
25870342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
25970342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant#endif  // __cplusplus >= 201103L
26070342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant
26170342b99e227912742972b754ad86e75c5d7eefbHoward Hinnant#endif  // MIN_ALLOCATOR_H
262