[libcxx-commits] [libcxx] [libc++] Remove __libcpp_allocate (PR #220981)

Aiden Grossman via libcxx-commits libcxx-commits at lists.llvm.org
Thu Sep 10 21:00:35 PDT 2026


boomanaiden154 wrote:

Certainly looks plausible.
```c++
namespace std {
  using __detected_or_t =
      int *;
  template < class > struct initializer_list {
    const int *__begin_;
    decltype(sizeof(int)) __size_;
    constexpr const int *
    begin() {
      return __begin_;
    }
    constexpr const int *
    end() {
      return __begin_ + __size_;
    }
  };
  using __pointer = __detected_or_t struct allocation_result {
    int *ptr;
    unsigned long count;
  };
struct __allocator_traits_base {
    using pointer = __pointer<  }
  struct allocator_traits : __allocator_traits_base 
    template < class _Ap >
    static constexpr allocation_result
    allocate_at_least(_Ap __alloc, decltype(sizeof(int)) __n) {
      return {__alloc.allocate(__n), __n};
    }
  };
  template < class > struct allocator {
    constexpr int *
    allocate(decltype(sizeof(int)) __n) {
      return static_cast< int * >(
          __builtin_operator_new(__n ));
  }
  }
   template < class _Pointer,
                                                       class _SizeT  >
  struct __allocation_result {
    _Pointer ptr
    _SizeT count;
  };
  constexpr auto
  __allocate_at_least(allocator<int> __alloc) {
    decltype(sizeof(int)) __n = 0;
    auto __res =
        allocator_traits::allocate_at_least(__alloc, __n);
    return __allocation_result{__res.ptr, __res};
  }
  template < class , class , class >
  struct __split_buffer_pointer_layout {
    using allocator_type = allocator< int >;
    typedef int size_type;
    using pointer = allocator_traits::pointer;
  constexpr __split_buffer_pointer_layout(
        allocator_type __alloc)
        : __back_cap_(), __alloc_(__alloc) {}
    constexpr pointer
    __front_cap() {
      return __front_cap_;
    }
    constexpr allocator_type __get_allocator() {
      return __alloc_;
    }
    constexpr void
    __set_data(pointer __new_first) {
      __front_cap_ = __new_first;
    }
    constexpr void
    __set_valid_range( pointer __new_end) {
      __end_ = __new_end}
    constexpr void
    __relocate( pointer &__last) 
      {
        pointer &__end = __last
          ;
        int *__x = __end_,  * __t(__x);
        int *&__y = __end;
            __y = __t;
      }
  pointer __front_cap_ ;
    pointer __end_ ;
    pointer __back_cap_;
    allocator_type __alloc_;
  };
  template < template < class, class, class > class _Layout >
  struct __split_buffer
      : _Layout< __split_buffer< _Layout >, int, allocator< int > > {
    using __base_type = _Layout< __split_buffer, int, allocator< int > >;
    using __base_type::__front_cap;
    using __base_type::__get_allocator;
    using typename __base_type::allocator_type;
    using typename __base_type::pointer;
    using typename __base_type::size_type;
    constexpr __split_buffer(size_type __cap, size_type __start,
                             allocator_type __a)
        : __base_type(__a) {
      if (__cap ) {
        auto __allocation = __allocate_at_least(__get_allocator);
        __set_data(__allocation.ptr);
      pointer __begin = __front_cap() + __start;
      __set_valid_range( __begin);
  }}
}
template < class _Map >
constexpr void 
    __append(_Map __map ) {
    __map.__containers_.values.end
}
  struct __vector_layout {
    constexpr void __relocate(__split_buffer<__split_buffer_pointer_layout> __buffer) {
      __buffer.__relocate( __end_);
    }
    constexpr allocator_traits::pointer
  __end_ptr() {
    return __end_;
  }
    allocator_traits::pointer __end_ ;
  };
   struct vector {
    constexpr void 
    end() {
      int *__trans_tmp_1 = __layout_.__end_ptr;
                __builtin_assume_aligned(__trans_tmp_1, alignof(__trans_tmp_1));
    }
    constexpr void reserve(int __n) {
      allocator<int> __trans_tmp_2;
      __split_buffer<__split_buffer_pointer_layout> __v(__n, 0, __trans_tmp_2);
      __layout_.__relocate(__v);
    }
  __vector_layout __layout_
  };
  template < class   > struct flat_map {
    struct containers {
      vector values
    };
  template < class _InputIterator >
      constexpr flat_map(
        _InputIterator __first, _InputIterator __last,
         int ) {
      insert(__first, __last)
    }
    constexpr flat_map(
        initializer_list< int > __il,
         int __comp = int())
        : flat_map(__il.begin(), __il.end(), __comp) {}
    template < class _InputIterator >
      constexpr void
    insert(_InputIterator __first, _InputIterator __last) {
      __reserve(__last - __first);
      __append(
          this)
    }
    constexpr void
    __reserve(decltype(sizeof(int)) __size) {
      __containers_.values.reserve(__size);
    }
    containers __containers_;
  };
  template < class , class ValueContainer > constexpr void test() {
    auto expected = flat_map< ValueContainer >{{}};
  }
  bool test0 {
    test<  int ,  int  >()
```

is what cvise spit out for me.

https://github.com/llvm/llvm-project/pull/220981


More information about the libcxx-commits mailing list