Commit 7586de62 authored by jan.koester's avatar jan.koester
Browse files

bugfix

parent de3d1683
Loading
Loading
Loading
Loading
+40 −0
Changes for include/cxx/memory: 40 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -231,6 +231,46 @@ ForwardIt uninitialized_value_construct_n(ForwardIt first, Size n) {
    return first;
}

/* std::pointer_traits -- was missing (real gap: googlemock's
 * gmock-matchers.h and gmock-internal-utils.h take Pointer::element_type
 * through it; fenrirds' tests are built on googlemock). */
namespace __pointer_traits {
    template<class Ptr> struct first_arg;
    template<template<class, class...> class Tpl, class T, class... Rest>
    struct first_arg<Tpl<T, Rest...>> { using type = T; };

    template<class Ptr, class = void> struct element { using type = typename first_arg<Ptr>::type; };
    template<class Ptr> struct element<Ptr, void_t<typename Ptr::element_type>> { using type = typename Ptr::element_type; };

    template<class Ptr, class = void> struct difference { using type = ptrdiff_t; };
    template<class Ptr> struct difference<Ptr, void_t<typename Ptr::difference_type>> { using type = typename Ptr::difference_type; };

    template<class Ptr, class U> struct rebind_arg;
    template<template<class, class...> class Tpl, class T, class... Rest, class U>
    struct rebind_arg<Tpl<T, Rest...>, U> { using type = Tpl<U, Rest...>; };

    template<class Ptr, class U, class = void> struct rebind { using type = typename rebind_arg<Ptr, U>::type; };
    template<class Ptr, class U> struct rebind<Ptr, U, void_t<typename Ptr::template rebind<U>>> { using type = typename Ptr::template rebind<U>; };
}

template<class Ptr>
struct pointer_traits {
    using pointer = Ptr;
    using element_type = typename __pointer_traits::element<Ptr>::type;
    using difference_type = typename __pointer_traits::difference<Ptr>::type;
    template<class U> using rebind = typename __pointer_traits::rebind<Ptr, U>::type;
    static pointer pointer_to(element_type &r) { return Ptr::pointer_to(r); }
};

template<class T>
struct pointer_traits<T*> {
    using pointer = T*;
    using element_type = T;
    using difference_type = ptrdiff_t;
    template<class U> using rebind = U*;
    static pointer pointer_to(T &r) noexcept { return __builtin_addressof(r); }
};

/* Real addressof() -- was missing entirely (real gap:
 * llvm/lib/CodeGen/CommandFlags.cpp's real
 * `NAME##View = std::addressof(NAME);` macro-expanded call, and