Parcourir la source

change(c++): remove c++ stl and boot.s

greatbridf il y a 8 mois
Parent
commit
47087f162e
44 fichiers modifiés avec 394 ajouts et 6721 suppressions
  1. 5 15
      CMakeLists.txt
  2. 370 0
      arch/src/x86_64/bootstrap.rs
  3. 15 15
      arch/src/x86_64/mm.rs
  4. 2 0
      arch/src/x86_64/mod.rs
  5. 0 5
      build.rs
  6. 2 6
      doc/mem_layout.txt
  7. 0 41
      gblibstdc++/CMakeLists.txt
  8. 0 214
      gblibstdc++/include/algorithm
  9. 0 14
      gblibstdc++/include/bit
  10. 0 70
      gblibstdc++/include/bits/compressed_pair
  11. 0 34
      gblibstdc++/include/bits/forward
  12. 0 42
      gblibstdc++/include/bits/fwd_functional
  13. 0 34
      gblibstdc++/include/bits/iter_ops
  14. 0 709
      gblibstdc++/include/bits/rbtree
  15. 0 27
      gblibstdc++/include/bits/sequence
  16. 0 82
      gblibstdc++/include/bits/tuple_tools
  17. 0 46
      gblibstdc++/include/bits/type_traits/base
  18. 0 40
      gblibstdc++/include/bits/type_traits/is_es
  19. 0 123
      gblibstdc++/include/bits/type_traits/remove_add
  20. 0 20
      gblibstdc++/include/cstddef
  21. 0 329
      gblibstdc++/include/functional
  22. 0 122
      gblibstdc++/include/initializer_list
  23. 0 502
      gblibstdc++/include/list
  24. 0 309
      gblibstdc++/include/map
  25. 0 740
      gblibstdc++/include/memory
  26. 0 11
      gblibstdc++/include/new
  27. 0 150
      gblibstdc++/include/queue
  28. 0 253
      gblibstdc++/include/set
  29. 0 543
      gblibstdc++/include/string
  30. 0 483
      gblibstdc++/include/tuple
  31. 0 356
      gblibstdc++/include/type_traits
  32. 0 185
      gblibstdc++/include/utility
  33. 0 502
      gblibstdc++/include/vector
  34. 0 0
      gblibstdc++/src/stdc++.cpp
  35. 0 47
      include/kernel/async/lock.hpp
  36. 0 102
      include/kernel/mem/paging.hpp
  37. 0 25
      include/kernel/mem/paging_asm.h
  38. 0 34
      include/kernel/mem/phys.hpp
  39. 0 37
      include/kernel/mem/slab.hpp
  40. 0 37
      include/types/allocator.hpp
  41. 0 46
      include/types/list.hpp
  42. 0 31
      include/types/types.h
  43. 0 1
      rust-headers.hpp
  44. 0 339
      src/boot.s

+ 5 - 15
CMakeLists.txt

@@ -9,7 +9,7 @@ set(CMAKE_CXX_LINK_EXECUTABLE
 set(C_CXX_FLAGS "-nostdinc -nostdlib -mno-sse -mno-mmx -W -Wall -Wextra -Wno-stringop-overflow -Wno-builtin-declaration-mismatch -Wno-format -fverbose-asm -fno-exceptions -ffreestanding -fno-pic -mno-red-zone -mstack-protector-guard=global -mcmodel=kernel")
 set(CMAKE_C_FLAGS "${C_CXX_FLAGS} -Werror=implicit-int -Werror=implicit-function-declaration -Werror=strict-aliasing")
 set(CMAKE_CXX_FLAGS "${C_CXX_FLAGS} -fno-use-cxa-atexit -fno-rtti")
-set(CMAKE_CXX_LINK_FLAGS "-z noexecstack --gc-sections")
+set(CMAKE_CXX_LINK_FLAGS "-z noexecstack --gc-sections --no-check-sections")
 SET(CMAKE_ASM_FLAGS "${CFLAGS} -x assembler-with-cpp")
 set(CMAKE_CXX_STANDARD 20)
 
@@ -30,24 +30,13 @@ if (NOT DEFINED FDISK_BIN)
 endif()
 
 add_subdirectory(gblibc)
-add_subdirectory(gblibstdc++)
 add_subdirectory(user-space-program)
 
-set(BOOTLOADER_SOURCES src/boot.s
-                       src/mbr.S
-                       )
+set(BOOTLOADER_SOURCES src/mbr.S)
 
-set(KERNEL_MAIN_SOURCES include/kernel/async/lock.hpp
-                        include/kernel/mem/paging.hpp
-                        include/kernel/mem/slab.hpp
-                        include/types/list.hpp
-                        include/types/types.h
-                        include/types/allocator.hpp
-                        )
-
-add_executable(kernel.out ${KERNEL_MAIN_SOURCES} ${BOOTLOADER_SOURCES})
+add_executable(kernel.out ${BOOTLOADER_SOURCES})
 add_dependencies(kernel.out rustpart)
-target_link_libraries(kernel.out gblibc gblibstdc++ gbos_rust_part)
+target_link_libraries(kernel.out gblibc gbos_rust_part)
 target_include_directories(kernel.out PRIVATE ${PROJECT_SOURCE_DIR}/include)
 target_link_options(kernel.out PRIVATE
     -T "${CMAKE_SOURCE_DIR}/src/kernel.ld"
@@ -55,6 +44,7 @@ target_link_options(kernel.out PRIVATE
     --no-check-sections
     )
 set_target_properties(kernel.out PROPERTIES LINK_DEPENDS "${CMAKE_SOURCE_DIR}/src/kernel.ld")
+set_target_properties(kernel.out PROPERTIES LINKER_LANGUAGE CXX)
 set_source_files_properties(src/mbr.S PROPERTIES OBJECT_DEPENDS
     "${CMAKE_BINARY_DIR}/x86_64-unknown-none/${CARGO_BUILD_TYPE}/libgbos_rust_part.a"
     )

+ 370 - 0
arch/src/x86_64/bootstrap.rs

@@ -0,0 +1,370 @@
+use super::mm::{PA_G, PA_NXE, PA_P, PA_PS, PA_RW};
+use core::arch::{global_asm, naked_asm};
+
+const KERNEL_IMAGE_PADDR: usize = 0x400000;
+const KERNEL_PML4: usize = 0x1000;
+const KERNEL_PDPT_PHYS_MAPPING: usize = 0x2000;
+const KERNEL_PDPT_KERNEL_SPACE: usize = 0x3000;
+const KERNEL_PD_KIMAGE: usize = 0x4000;
+const KERNEL_PT_KIMAGE: usize = 0x5000;
+const KERNEL_PD_STRUCT_PAGE_ARR: usize = 0x6000;
+
+extern "C" {
+    static EARLY_GDT: [u64; 7];
+    static EARLY_GDT_DESCRIPTOR: [u8; 6];
+    static BIOS_IDT_DESCRIPTOR: [u8; 6];
+    static E820_MEM_MAP_DATA: [u8; 1024];
+    fn _kernel_init() -> !;
+
+    fn KIMAGE_32K_COUNT();
+    fn KIMAGE_PAGES();
+}
+
+global_asm!(
+    r"
+    .pushsection .stage1
+    .code16
+    .Lhalt:
+        hlt
+        jmp .
+    
+    # scratch %eax
+    # return address should be of 2 bytes, and will be zero extended to 4 bytes
+    .Lgo_32bit:
+        cli
+        # borrow the null entry from the early gdt
+        lidt {EARLY_GDT}
+
+        # set PE bit
+        mov %cr0, %eax
+        or $1, %eax
+        mov %eax, %cr0
+
+        ljmp $0x18, $.Lgo_32bit0
+
+    .Lgo_16bit0:
+        mov $0x30, %ax
+        mov %ax, %ds
+        mov %ax, %es
+        mov %ax, %ss
+
+        lidt {BIOS_IDT_DESCRIPTOR}
+
+        mov %cr0, %eax
+        and $0xfffffffe, %eax
+        mov %eax, %cr0
+
+        ljmp $0x00, $2f
+
+    2:
+        xor %ax, %ax
+        mov %ax, %ds
+        mov %ax, %ss
+        mov %ax, %es
+
+        sti
+
+        pop %eax
+        push %ax
+        ret
+
+    .code32
+    # scratch %eax
+    # return address should be of 4 bytes, and extra 2 bytes will be popped from the stack
+    .Lgo_16bit:
+        cli
+        ljmp $0x28, $.Lgo_16bit0
+
+    .Lgo_32bit0:
+        mov $0x20, %ax
+        mov %ax, %ds
+        mov %ax, %es
+        mov %ax, %ss
+
+        pop %ax
+        movzw %ax, %eax
+        push %eax
+        ret
+
+    # build read disk packet on the stack and perform read operation
+    #
+    # read 16k to 0x8000 and then copy to destination
+    #
+    # %edi: lba start
+    # %esi: destination
+    .code32
+    read_disk:
+        push %ebp
+        mov %esp, %ebp
+
+        lea -24(%esp), %esp
+
+        mov $0x00200010, %eax # packet size 0, sector count 64
+        mov %eax, (%esp)
+
+        mov $0x08000000, %eax # destination address 0x0800:0x0000
+        mov %eax, 4(%esp)
+
+        mov %edi, 8(%esp)  # lba low 4bytes
+
+        xor %eax, %eax
+        mov %eax, 12(%esp) # lba high 2bytes
+
+        mov %esi, %edi
+        mov %esp, %esi # packet address
+
+        call .Lgo_16bit
+    .code16
+        mov $0x42, %ah
+        mov $0x80, %dl
+        int $0x13
+        jc .Lhalt
+
+        call .Lgo_32bit
+    .code32
+        # move data to destination
+        mov $0x8000, %esi
+        mov $4096, %ecx
+        rep movsl
+
+        mov %ebp, %esp
+        pop %ebp
+        ret
+
+    .align 8
+    .Lgdt_data:
+        .8byte 0x00209a0000000000 # 64bit code selector
+        .8byte 0x0000920000000000 # 64bit data selector
+        .8byte 0x00cf9a000000ffff # 32bit code selector
+        .8byte 0x00cf92000000ffff # 32bit data selector
+        .8byte 0x000f9a000000ffff # 16bit code selector
+        .8byte 0x000f92000000ffff # 16bit data selector
+
+    .globl start_32bit
+    start_32bit:
+        mov $0x10, %ax
+        mov %ax, %ds
+        mov %ax, %es
+        mov %ax, %ss
+
+        mov ${EARLY_GDT_DESCRIPTOR}, %edi
+        mov $0x37, %ax
+        mov %ax, (%edi)
+
+        mov ${EARLY_GDT}, %eax
+        mov %eax, 2(%edi)
+
+        # fill in early kernel GDT
+        xchg %eax, %edi
+        xor %eax, %eax
+        mov $2, %ecx
+
+        # null segment
+        rep stosl
+
+        # other data
+        mov $.Lgdt_data, %esi
+        mov $12, %ecx
+
+        rep movsl
+
+        lgdt {EARLY_GDT_DESCRIPTOR}
+        ljmp $0x18, $2f
+
+    2:
+        mov $0x20, %ax
+        mov %ax, %ds
+        mov %ax, %es
+        mov %ax, %ss
+
+        # temporary kernel stack
+        mov $0x1000, %esp
+
+        # read kimage into memory
+        lea -16(%esp), %esp
+        mov ${KIMAGE_32K_COUNT}, %ecx
+        shl $1, %ecx
+        movl ${KERNEL_IMAGE_PADDR}, 4(%esp) # destination address
+        movl $9, (%esp) # LBA
+
+    2:
+        mov (%esp), %edi
+        mov 4(%esp), %esi
+
+        mov %ecx, %ebx
+        call read_disk
+        mov %ebx, %ecx
+
+        addl $0x4000, 4(%esp)
+        addl $32, (%esp)
+
+        loop 2b
+
+        lea 16(%esp), %esp
+
+        cld
+        xor %eax, %eax
+
+        # clear paging structures
+        mov $0x1000, %edi
+        mov $0x6000, %ecx
+        shr $2, %ecx # %ecx /= 4
+        rep stosl
+
+        # set P, RW, G
+        mov $({PA_P} | {PA_RW} | {PA_G}), %ebx
+        xor %edx, %edx
+        mov ${KERNEL_PDPT_PHYS_MAPPING}, %esi
+
+        # PML4E 0x000
+        # we need the first 1GB identically mapped
+        # so that we won't trigger a triple fault after
+        # enabling paging
+        mov ${KERNEL_PML4}, %edi
+        call fill_pxe
+
+        # PML4E 0xff0
+        mov $({PA_NXE} >> 32), %edx
+        lea 0xff0(%edi), %edi
+        call fill_pxe
+        xor %edx, %edx
+
+        # setup PDPT for physical memory mapping
+        mov ${KERNEL_PDPT_PHYS_MAPPING}, %edi
+
+        # set PS
+        or ${PA_PS}, %ebx
+        mov $512, %ecx
+        xor %esi, %esi
+    2:
+        call fill_pxe
+        lea 8(%edi), %edi
+        add $0x40000000, %esi # 1GB
+        adc $0, %edx
+        loop 2b
+
+        xor %edx, %edx
+
+        # PML4E 0xff8
+        mov ${KERNEL_PDPT_KERNEL_SPACE}, %esi
+        mov ${KERNEL_PML4}, %edi
+        lea 0xff8(%edi), %edi
+        # clear PS
+        and $(~{PA_PS}), %ebx
+        call fill_pxe
+
+        # PDPTE 0x008
+        mov ${KERNEL_PDPT_KERNEL_SPACE}, %edi
+        lea 0x8(%edi), %edi
+        mov ${KERNEL_PD_STRUCT_PAGE_ARR}, %esi
+        call fill_pxe
+
+        # PDPTE 0xff8
+        lea 0xff0(%edi), %edi
+        mov ${KERNEL_PD_KIMAGE}, %esi
+        call fill_pxe
+
+        # PDE 0xff0
+        mov ${KERNEL_PD_KIMAGE}, %edi
+        lea 0xff0(%edi), %edi
+        mov ${KERNEL_PT_KIMAGE}, %esi # 0x104000
+        call fill_pxe
+
+        # fill PT (kernel image)
+        mov ${KERNEL_PT_KIMAGE}, %edi
+        mov ${KERNEL_IMAGE_PADDR}, %esi
+
+        mov ${KIMAGE_PAGES}, %ecx
+
+    2:
+        call fill_pxe
+        lea 8(%edi), %edi
+        lea 0x1000(%esi), %esi
+        loop 2b
+
+        # set msr
+        mov $0xc0000080, %ecx
+        rdmsr
+        or $0x901, %eax # set LME, NXE, SCE
+        wrmsr
+
+        # set cr4
+        mov %cr4, %eax
+        or $0xa0, %eax # set PAE, PGE
+        mov %eax, %cr4
+
+        # load new page table
+        mov ${KERNEL_PML4}, %eax
+        mov %eax, %cr3
+
+        mov %cr0, %eax
+        // SET PE, WP, PG
+        or $0x80010001, %eax
+        mov %eax, %cr0
+
+        ljmp $0x08, $2f
+
+    # %ebx: attribute low
+    # %edx: attribute high
+    # %esi: page physical address
+    # %edi: page x entry address
+    fill_pxe:
+        lea (%ebx, %esi, 1), %eax
+        mov %eax, (%edi)
+        mov %edx, 4(%edi)
+
+        ret
+
+    .code64
+    2:
+        jmp {start_64bit}
+    
+    .popsection
+    ",
+    EARLY_GDT = sym EARLY_GDT,
+    EARLY_GDT_DESCRIPTOR = sym EARLY_GDT_DESCRIPTOR,
+    BIOS_IDT_DESCRIPTOR = sym BIOS_IDT_DESCRIPTOR,
+    KIMAGE_32K_COUNT = sym KIMAGE_32K_COUNT,
+    KIMAGE_PAGES = sym KIMAGE_PAGES,
+    KERNEL_IMAGE_PADDR = const KERNEL_IMAGE_PADDR,
+    KERNEL_PML4 = const KERNEL_PML4,
+    PA_P = const PA_P,
+    PA_RW = const PA_RW,
+    PA_G = const PA_G,
+    PA_PS = const PA_PS,
+    PA_NXE = const PA_NXE,
+    KERNEL_PDPT_PHYS_MAPPING = const KERNEL_PDPT_PHYS_MAPPING,
+    KERNEL_PDPT_KERNEL_SPACE = const KERNEL_PDPT_KERNEL_SPACE,
+    KERNEL_PD_STRUCT_PAGE_ARR = const KERNEL_PD_STRUCT_PAGE_ARR,
+    KERNEL_PD_KIMAGE = const KERNEL_PD_KIMAGE,
+    KERNEL_PT_KIMAGE = const KERNEL_PT_KIMAGE,
+    start_64bit = sym start_64bit,
+    options(att_syntax),
+);
+
+#[naked]
+unsafe extern "C" fn start_64bit() {
+    naked_asm!(
+        "mov $0x10, %ax",
+        "mov %ax, %ds",
+        "mov %ax, %es",
+        "mov %ax, %ss",
+        "",
+        "mov ${kernel_identical_base}, %rax",
+        "mov ${stack_paddr}, %rsp",
+        "add %rax, %rsp",
+        "",
+        "xor %rbp, %rbp", // Clear previous stack frame
+        "push %rbp", // NULL return address
+        "",
+        "mov ${e820_data_addr}, %rdi",
+        "add %rax, %rdi",
+        "",
+        "jmp {kernel_init}",
+        kernel_identical_base = const 0xffffff0000000000u64,
+        stack_paddr = const 0x80000,
+        e820_data_addr = sym E820_MEM_MAP_DATA,
+        kernel_init = sym _kernel_init,
+        options(att_syntax)
+    )
+}

+ 15 - 15
arch/src/x86_64/mm.rs

@@ -9,24 +9,24 @@ use eonix_mm::{
 
 pub const PAGE_SIZE: usize = 0x1000;
 
-const KERNEL_PML4_PFN: PFN = PFN::from_val(0x1000 >> 12);
+pub const KERNEL_PML4_PFN: PFN = PFN::from_val(0x1000 >> 12);
 
-const PA_P: u64 = 0x001;
-const PA_RW: u64 = 0x002;
-const PA_US: u64 = 0x004;
+pub const PA_P: u64 = 0x001;
+pub const PA_RW: u64 = 0x002;
+pub const PA_US: u64 = 0x004;
 #[allow(dead_code)]
-const PA_PWT: u64 = 0x008;
+pub const PA_PWT: u64 = 0x008;
 #[allow(dead_code)]
-const PA_PCD: u64 = 0x010;
-const PA_A: u64 = 0x020;
-const PA_D: u64 = 0x040;
-const PA_PS: u64 = 0x080;
-const PA_G: u64 = 0x100;
-const PA_COW: u64 = 0x200;
-const PA_MMAP: u64 = 0x400;
-const PA_ANON: u64 = 0x800;
-const PA_NXE: u64 = 0x8000_0000_0000_0000;
-const PA_MASK: u64 = 0xfff0_0000_0000_0fff;
+pub const PA_PCD: u64 = 0x010;
+pub const PA_A: u64 = 0x020;
+pub const PA_D: u64 = 0x040;
+pub const PA_PS: u64 = 0x080;
+pub const PA_G: u64 = 0x100;
+pub const PA_COW: u64 = 0x200;
+pub const PA_MMAP: u64 = 0x400;
+pub const PA_ANON: u64 = 0x800;
+pub const PA_NXE: u64 = 0x8000_0000_0000_0000;
+pub const PA_MASK: u64 = 0xfff0_0000_0000_0fff;
 
 #[repr(transparent)]
 pub struct PTE64(u64);

+ 2 - 0
arch/src/x86_64/mod.rs

@@ -1,3 +1,4 @@
+mod bootstrap;
 mod context;
 mod fence;
 mod fpu;
@@ -20,6 +21,7 @@ pub use self::init::*;
 pub use self::interrupt::*;
 pub use self::io::*;
 pub use self::user::*;
+pub use bootstrap::*;
 pub use fence::*;
 pub use fpu::*;
 pub use mm::*;

+ 0 - 5
build.rs

@@ -4,18 +4,13 @@ use std::{
 };
 
 fn main() {
-    println!("cargo:rustc-link-search=native=./build/gblibstdc++");
-    println!("cargo:rustc-link-lib=static=gblibstdc++");
-
     let headers = ["rust-headers.hpp"];
 
     let bindings = bindgen::Builder::default()
         .use_core()
         .ctypes_prefix("core::ffi")
         .headers(headers)
-        .clang_arg("-I./gblibstdc++/include")
         .clang_arg("-I./gblibc/include")
-        .clang_arg("-I./include")
         .clang_arg("-std=c++20")
         .opaque_type("std::.*")
         .enable_cxx_namespaces()

+ 2 - 6
doc/mem_layout.txt

@@ -17,14 +17,10 @@ physical memory
 
 virtual address space
 
-0xffff ff0 000 000 000 - 0xffff ff3 fff fff fff  256GB physical memory (cached)
-0xffff ff4 000 000 000 - 0xffff ff7 fff fff fff  256GB physical memory (not cached)
+0xffff ff0 000 000 000 - 0xffff ff7 fff fff fff  512GB physical memory
 0xffff ff8 000 000 000 - 0xffff ff8 03f fff fff    1GB unused
 0xffff ff8 040 000 000 - 0xffff ff8 13f fff fff    4GB struct page array
-0xffff ff8 140 000 000 - 0xffff ff8 17f fff fff    1GB unused
-0xffff ff8 180 000 000 - 0xffff ffb fff fff fff  250GB kernel heap
-
-0xffff ffc 000 000 000 - 0xffff fff fbf fff fff  255GB unused
+0xffff ff8 140 000 000 - 0xffff fff fbf fff fff    506GB unused
 
 0xffff fff fc0 000 000 - 0xffff fff fc0 1ff fff    2MB unused
 0xffff fff fc0 200 000 - 0xffff fff fff 9ff fff 1016MB kernel bss

+ 0 - 41
gblibstdc++/CMakeLists.txt

@@ -1,41 +0,0 @@
-cmake_minimum_required(VERSION 3.15)
-project(gblibstdc++)
-
-set(CMAKE_CXX_STANDARD 20)
-
-add_library(gblibstdc++ STATIC src/stdc++.cpp)
-
-set(GBSTDLIBCPP_PUBLIC_HEADERS
-    gblibstdc++/include
-    gblibstdc++/include/bit
-    gblibstdc++/include/memory
-    gblibstdc++/include/tuple
-    gblibstdc++/include/type_traits
-    gblibstdc++/include/algorithm
-    gblibstdc++/include/cstddef
-    gblibstdc++/include/map
-    gblibstdc++/include/bits
-    gblibstdc++/include/bits/compressed_pair
-    gblibstdc++/include/bits/fwd_functional
-    gblibstdc++/include/bits/rbtree
-    gblibstdc++/include/bits/iter_ops
-    gblibstdc++/include/bits/type_traits
-    gblibstdc++/include/bits/type_traits/is_es
-    gblibstdc++/include/bits/type_traits/remove_add
-    gblibstdc++/include/bits/type_traits/base
-    gblibstdc++/include/bits/tuple_tools
-    gblibstdc++/include/bits/sequence
-    gblibstdc++/include/bits/forward
-    gblibstdc++/include/list
-    gblibstdc++/include/initializer_list
-    gblibstdc++/include/new
-    gblibstdc++/include/queue
-    gblibstdc++/include/string
-    gblibstdc++/include/set
-    gblibstdc++/include/vector
-    gblibstdc++/include/functional
-    gblibstdc++/include/utility
-    )
-
-target_include_directories(gblibstdc++ PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
-set_target_properties(gblibstdc++ PROPERTIES PUBLIC_HEADER "${GBSTDLIBCPP_PUBLIC_HEADERS}")

+ 0 - 214
gblibstdc++/include/algorithm

@@ -1,214 +0,0 @@
-#ifndef __GBLIBCPP_ALGORITHM__
-#define __GBLIBCPP_ALGORITHM__
-
-#include <functional>
-#include <utility>
-#include <initializer_list>
-#include <cstddef>
-
-namespace std {
-
-template <typename RandomIter, typename Compare>
-constexpr void make_heap(RandomIter first, RandomIter last, Compare comp)
-{
-    auto len = last - first;
-    if (len < 2)
-        return;
-
-    auto idx = len / 2 - 1;
-    for (;;) {
-        auto& val = first[idx];
-        auto left = idx * 2 + 1;
-        auto right = left + 1;
-
-        if (right < len) {
-            auto& left_val = first[left];
-            auto& right_val = first[right];
-
-            if (comp(left_val, right_val)) {
-                if (comp(val, right_val)) {
-                    std::swap(val, right_val);
-                    idx = right;
-                    continue;
-                }
-            } else {
-                if (comp(val, left_val)) {
-                    std::swap(val, left_val);
-                    idx = left;
-                    continue;
-                }
-            }
-        } else if (left < len) {
-            auto& left_val = first[left];
-
-            if (comp(val, left_val)) {
-                std::swap(val, left_val);
-                idx = left;
-                continue;
-            }
-        }
-
-        if (idx == 0)
-            break;
-        --idx;
-    }
-}
-template <typename RandomIter>
-constexpr void make_heap(RandomIter first, RandomIter last)
-{
-    make_heap(first, last, std::less<typename std::decay_t<decltype(*first)>>());
-}
-
-template <typename RandomIter, typename Compare>
-constexpr void push_heap(RandomIter first, RandomIter last, Compare comp)
-{
-    auto len = last - first;
-    if (len < 2)
-        return;
-
-    auto idx = len - 1;
-    for (;;) {
-        auto parent = (idx - 1) / 2;
-        if (parent == idx)
-            break;
-
-        auto& val = first[idx];
-        auto& parent_val = first[parent];
-
-        if (comp(parent_val, val)) {
-            std::swap(val, parent_val);
-            idx = parent;
-            continue;
-        }
-
-        break;
-    }
-}
-template <typename RandomIter>
-constexpr void push_heap(RandomIter first, RandomIter last)
-{
-    push_heap(first, last, std::less<typename std::decay_t<decltype(*first)>>());
-}
-
-template <typename RandomIter, typename Compare>
-constexpr void pop_heap(RandomIter first, RandomIter last, Compare comp)
-{
-    auto len = last - first;
-    if (len < 2)
-        return;
-
-    std::swap(first[0], first[len - 1]);
-
-    auto idx = 0;
-    for (;;) {
-        auto& val = first[idx];
-        auto left = idx * 2 + 1;
-        auto right = left + 1;
-
-        if (right < len - 1) {
-            auto& left_val = first[left];
-            auto& right_val = first[right];
-
-            if (comp(left_val, right_val)) {
-                if (comp(val, right_val)) {
-                    std::swap(val, right_val);
-                    idx = right;
-                    continue;
-                }
-            } else {
-                if (comp(val, left_val)) {
-                    std::swap(val, left_val);
-                    idx = left;
-                    continue;
-                }
-            }
-        } else if (left < len - 1) {
-            auto& left_val = first[left];
-
-            if (comp(val, left_val)) {
-                std::swap(val, left_val);
-                idx = left;
-                continue;
-            }
-        }
-
-        if (idx == 0)
-            break;
-        --idx;
-    }
-}
-template <typename RandomIter>
-constexpr void pop_heap(RandomIter first, RandomIter last)
-{
-    pop_heap(first, last, std::less<typename std::decay_t<decltype(*first)>>());
-}
-
-template <typename RandomIter, typename Compare>
-constexpr void sort(RandomIter first, RandomIter last, Compare comp)
-{
-    auto len = last - first;
-    std::make_heap(first, last, comp);
-
-    for (auto i = len - 1; i > 0; --i) {
-        std::swap(first[0], first[i]);
-
-        auto idx = 0;
-        for (;;) {
-            auto& val = first[idx];
-            auto left = idx * 2 + 1;
-            auto right = left + 1;
-
-            if (right < i) {
-                auto& left_val = first[left];
-                auto& right_val = first[right];
-
-                if (comp(left_val, right_val)) {
-                    if (comp(val, right_val)) {
-                        std::swap(val, right_val);
-                        idx = right;
-                        continue;
-                    }
-                } else {
-                    if (comp(val, left_val)) {
-                        std::swap(val, left_val);
-                        idx = left;
-                        continue;
-                    }
-                }
-            } else if (left < i) {
-                auto& left_val = first[left];
-
-                if (comp(val, left_val)) {
-                    std::swap(val, left_val);
-                    idx = left;
-                    continue;
-                }
-            }
-
-            if (idx == 0)
-                break;
-            --idx;
-        }
-    }
-}
-template <typename RandomIter>
-constexpr void sort(RandomIter first, RandomIter last)
-{
-    sort(first, last, std::less<typename std::decay_t<decltype(*first)>>());
-}
-
-template <typename T>
-constexpr const T& min(const T& a, const T& b)
-{
-    return a < b ? a : b;
-}
-
-template <typename T>
-constexpr const T& max(const T& a, const T& b)
-{
-    return a > b ? a : b;
-}
-
-} // namespace std
-
-#endif

+ 0 - 14
gblibstdc++/include/bit

@@ -1,14 +0,0 @@
-#ifndef __GBLIBCPP_BIT__
-#define __GBLIBCPP_BIT__
-
-namespace std {
-
-template <typename To, typename From>
-constexpr To bit_cast(const From& from) noexcept
-{
-    return __builtin_bit_cast(To, from);
-}
-
-} // namespace std
-
-#endif

+ 0 - 70
gblibstdc++/include/bits/compressed_pair

@@ -1,70 +0,0 @@
-#ifndef __GBLIBCPP_BITS_COMPRESSED_PAIR__
-#define __GBLIBCPP_BITS_COMPRESSED_PAIR__
-
-#include <utility>
-
-namespace std::impl {
-
-struct default_construct_t { };
-
-template <typename T, int, bool is_empty = __is_empty(T)>
-struct compressed_pair_element
-{
-    constexpr compressed_pair_element() = default;
-    constexpr compressed_pair_element(const compressed_pair_element&) = default;
-    constexpr compressed_pair_element(compressed_pair_element&&) = default;
-    constexpr compressed_pair_element& operator=(const compressed_pair_element&) = default;
-    constexpr compressed_pair_element& operator=(compressed_pair_element&&) = default;
-
-    constexpr compressed_pair_element(default_construct_t): value{} { }
-    constexpr compressed_pair_element(const T& x): value{x} { }
-    constexpr compressed_pair_element(T&& x): value{std::move(x)} { }
-
-    constexpr T& get() noexcept { return value; }
-    constexpr const T& get() const noexcept { return value; }
-
-    T value;
-};
-
-template <typename T, int N>
-struct compressed_pair_element<T, N, true> : private T
-{
-    constexpr compressed_pair_element() = default;
-    constexpr compressed_pair_element(const compressed_pair_element&) = default;
-    constexpr compressed_pair_element(compressed_pair_element&&) = default;
-    constexpr compressed_pair_element& operator=(const compressed_pair_element&) = default;
-    constexpr compressed_pair_element& operator=(compressed_pair_element&&) = default;
-
-    constexpr compressed_pair_element(default_construct_t): T{} { }
-    constexpr compressed_pair_element(const T& x): T{x} { }
-    constexpr compressed_pair_element(T&& x): T{std::move(x)} { }
-
-    constexpr T& get() noexcept { return *this; }
-    constexpr const T& get() const noexcept { return *this; }
-};
-
-template <typename T1, typename T2>
-struct compressed_pair
-    : private compressed_pair_element<T1, 0>, private compressed_pair_element<T2, 1> {
-    using Base1 = compressed_pair_element<T1, 0>;
-    using Base2 = compressed_pair_element<T2, 1>;
-
-    constexpr compressed_pair() = default;
-    constexpr compressed_pair(const compressed_pair&) = default;
-    constexpr compressed_pair(compressed_pair&&) = default;
-    constexpr compressed_pair& operator=(const compressed_pair&) = default;
-    constexpr compressed_pair& operator=(compressed_pair&&) = default;
-
-    constexpr compressed_pair(default_construct_t): Base1{default_construct_t{}}, Base2{default_construct_t{}} { }
-    constexpr compressed_pair(const T1& x, const T2& y): Base1{x}, Base2{y} { }
-    constexpr compressed_pair(T1&& x, T2&& y): Base1{std::move(x)}, Base2{std::move(y)} { }
-
-    constexpr T1& first() noexcept { return Base1::get(); }
-    constexpr const T1& first() const noexcept { return Base1::get(); }
-    constexpr T2& second() noexcept { return Base2::get(); }
-    constexpr const T2& second() const noexcept { return Base2::get(); }
-};
-
-} // namespace std::impl
-
-#endif

+ 0 - 34
gblibstdc++/include/bits/forward

@@ -1,34 +0,0 @@
-#ifndef __GBLIBCPP_BITS_FORWARD__
-#define __GBLIBCPP_BITS_FORWARD__
-
-#include <bits/type_traits/remove_add>
-
-namespace std {
-
-template <typename T>
-constexpr std::remove_reference_t<T>&& move(T&& val) noexcept
-{
-    return static_cast<std::remove_reference_t<T>&&>(val);
-}
-
-template <typename T>
-constexpr T&& forward(std::remove_reference_t<T>& val) noexcept
-{
-    return static_cast<T&&>(val);
-}
-template <typename T>
-constexpr T&& forward(std::remove_reference_t<T>&& val) noexcept
-{
-    return static_cast<T&&>(val);
-}
-
-template <typename T>
-add_rvalue_reference_t<T> declval(void) noexcept
-{
-    static_assert(__helpers::template_false_type<T>::value,
-        "declval cannot be evaluated.");
-}
-
-} // namespace std
-
-#endif

+ 0 - 42
gblibstdc++/include/bits/fwd_functional

@@ -1,42 +0,0 @@
-#ifndef __GBLIBCPP_BITS_FWD_FUNCTIONAL__
-#define __GBLIBCPP_BITS_FWD_FUNCTIONAL__
-
-#include <cstddef>
-
-namespace std {
-
-template <typename T>
-class reference_wrapper;
-
-template <typename>
-class function;
-
-template <typename Ret, typename... Args>
-bool operator==(const std::function<Ret(Args...)>& func, std::nullptr_t) noexcept;
-
-template <typename Ret, typename... Args>
-void swap(std::function<Ret(Args...)>& lhs, std::function<Ret(Args...)>& rhs) noexcept;
-
-template <typename T>
-constexpr std::reference_wrapper<T> ref(T& t) noexcept;
-
-template <typename T>
-constexpr std::reference_wrapper<T>
-    ref(std::reference_wrapper<T> t) noexcept;
-
-template <typename T>
-void ref(const T&&) = delete;
-
-template <typename T>
-constexpr std::reference_wrapper<const T> cref(const T& t) noexcept;
-
-template <typename T>
-constexpr std::reference_wrapper<const T>
-    cref(std::reference_wrapper<T> t) noexcept;
-
-template <typename T>
-void cref(const T&&) = delete;
-
-} // namespace std
-
-#endif

+ 0 - 34
gblibstdc++/include/bits/iter_ops

@@ -1,34 +0,0 @@
-#ifndef __GBLIBCPP_BITS_ITER_OPS__
-#define __GBLIBCPP_BITS_ITER_OPS__
-
-namespace std {
-
-template <typename Container>
-constexpr auto begin(Container& c) -> decltype(c.begin())
-{ return c.begin(); }
-
-template <typename Container>
-constexpr auto begin(const Container& c) -> decltype(c.begin())
-{ return c.begin(); }
-
-template <typename Container>
-constexpr auto end(Container& c) -> decltype(c.end())
-{ return c.end(); }
-
-template <typename Container>
-constexpr auto end(const Container& c) -> decltype(c.end())
-{ return c.end(); }
-
-template <typename Container>
-constexpr auto cbegin(const Container& c)
-    noexcept(noexcept(std::begin(c))) -> decltype(c.begin())
-{ return c.begin(); }
-
-template <typename Container>
-constexpr auto cend(const Container& c)
-    noexcept(noexcept(std::end(c))) -> decltype(c.end())
-{ return c.end(); }
-
-} // namespace std
-
-#endif

+ 0 - 709
gblibstdc++/include/bits/rbtree

@@ -1,709 +0,0 @@
-#ifndef __GBLIBCPP_BITS_RBTREE__
-#define __GBLIBCPP_BITS_RBTREE__
-
-#include "compressed_pair"
-
-#include <cstddef>
-#include <functional>
-#include <utility>
-#include <memory>
-
-namespace std::impl {
-
-template <typename T, typename Compare, typename Allocator>
-struct rbtree {
-    struct node {
-        node* parent;
-        node* left;
-        node* right;
-        T value;
-        enum class node_color : unsigned char { RED, BLACK, } color;
-
-        constexpr node(const T& val)
-            : parent {}, left {}, right {}
-            , value { val } , color {node_color::RED} {}
-
-        constexpr node(T&& val)
-            : parent {}, left {}, right {}
-            , value { std::move(val) } , color {node_color::RED} {}
-
-        template <typename... Args, std::enable_if_t<
-            (sizeof...(Args) > 1)
-            || !(... && std::is_same_v<T, std::remove_cvref_t<Args>>)
-        , bool> = true>
-        constexpr node(Args&&... args)
-            : parent {}, left {}, right {}
-            , value { std::forward<Args>(args)... }, color { node_color::RED } {}
-
-        constexpr node* grandparent(void) const
-        { return this->parent->parent; }
-
-        constexpr node* uncle(void) const
-        {
-            node* pp = this->grandparent();
-            if (this->parent == pp->left)
-                return pp->right;
-            return pp->left;
-        }
-
-        constexpr node* leftmost(void)
-        {
-            node* nd = this;
-            while (nd->left)
-                nd = nd->left;
-            return nd;
-        }
-
-        constexpr node* rightmost(void)
-        {
-            node* nd = this;
-            while (nd->right)
-                nd = nd->right;
-            return nd;
-        }
-
-        constexpr node* next(void)
-        {
-            if (this->right)
-                return this->right->leftmost();
-            if (this->is_root())
-                return nullptr;
-            if (this->is_left_child())
-                return this->parent;
-            node* ret = this;
-            do {
-                ret = ret->parent;
-            } while (!ret->is_root() && !ret->is_left_child());
-            return ret->parent;
-        }
-
-        constexpr node* prev(void)
-        {
-            if (this->left)
-                return this->left->rightmost();
-            if (this->is_root())
-                return nullptr;
-            if (this->is_right_child())
-                return this->parent;
-            node* ret = this;
-            do {
-                ret = ret->parent;
-            } while (!ret->is_root() && !ret->is_right_child());
-            return ret->parent;
-        }
-
-        static constexpr bool is_red(node* nd)
-        { return nd && nd->color == node_color::RED; }
-        static constexpr bool is_black(node* nd)
-        { return !node::is_red(nd); }
-
-        constexpr bool is_root(void) const
-        { return this->parent == nullptr; }
-        constexpr bool is_full(void) const
-        { return this->left && this->right; }
-        constexpr bool has_child(void) const
-        { return this->left || this->right; }
-        constexpr bool is_leaf(void) const
-        { return !this->has_child(); }
-
-        constexpr bool is_left_child(void) const
-        { return this == this->parent->left; }
-        constexpr bool is_right_child(void) const
-        { return this == this->parent->right; }
-
-        constexpr void tored(void)
-        { this->color = node_color::RED; }
-        constexpr void toblack(void)
-        { this->color = node_color::BLACK; }
-
-        static constexpr void swap(node* first, node* second)
-        {
-            if (node::is_red(first)) {
-                first->color = second->color;
-                second->color = node_color::RED;
-            } else {
-                first->color = second->color;
-                second->color = node_color::BLACK;
-            }
-
-            if (first->parent == second) {
-                node* tmp = first;
-                first = second;
-                second = tmp;
-            }
-
-            bool f_is_left_child = first->parent ? first->is_left_child() : false;
-            bool s_is_left_child = second->parent ? second->is_left_child() : false;
-
-            node* fp = first->parent;
-            node* fl = first->left;
-            node* fr = first->right;
-
-            node* sp = second->parent;
-            node* sl = second->left;
-            node* sr = second->right;
-
-            if (second->parent != first) {
-                first->parent = sp;
-                if (sp) {
-                    if (s_is_left_child)
-                        sp->left = first;
-                    else
-                        sp->right = first;
-                }
-                first->left = sl;
-                if (sl)
-                    sl->parent = first;
-                first->right = sr;
-                if (sr)
-                    sr->parent = first;
-
-                second->parent = fp;
-                if (fp) {
-                    if (f_is_left_child)
-                        fp->left = second;
-                    else
-                        fp->right = second;
-                }
-
-                second->left = fl;
-                if (fl)
-                    fl->parent = second;
-                second->right = fr;
-                if (fr)
-                    fr->parent = second;
-            } else {
-                first->left = sl;
-                if (sl)
-                    sl->parent = first;
-                first->right = sr;
-                if (sr)
-                    sr->parent = first;
-
-                second->parent = fp;
-                if (fp) {
-                    if (f_is_left_child)
-                        fp->left = second;
-                    else
-                        fp->right = second;
-                }
-                first->parent = second;
-
-                if (s_is_left_child) {
-                    second->left = first;
-                    second->right = fr;
-                    if (fr)
-                        fr->parent = second;
-                } else {
-                    second->right = first;
-                    second->left = fl;
-                    if (fl)
-                        fl->parent = second;
-                }
-            }
-        }
-    };
-
-    template <bool Const>
-    class _iterator {
-    public:
-        using node_pointer = node*;
-        using value_type = std::conditional_t<Const, const T, T>;
-        using pointer = std::add_pointer_t<value_type>;
-        using reference = std::add_lvalue_reference_t<value_type>;
-
-        friend rbtree;
-
-    private:
-        node_pointer p;
-
-    public:
-        constexpr _iterator() = default;
-        explicit constexpr _iterator(node_pointer ptr)
-            : p { ptr } {}
-        constexpr _iterator(const _iterator& iter) = default;
-        constexpr _iterator(_iterator&& iter) = default;
-        constexpr ~_iterator() = default;
-        constexpr _iterator& operator=(const _iterator& iter) = default;
-        constexpr _iterator& operator=(_iterator&& iter) = default;
-        constexpr bool operator==(const _iterator& iter) const = default;
-
-        constexpr reference operator*(void) const { return p->value; }
-        constexpr pointer operator&(void) const { return std::addressof(p->value); }
-        constexpr pointer operator->(void) const { return this->operator&(); }
-        constexpr _iterator& operator++(void)
-        { p = p->next(); return *this; }
-        constexpr _iterator operator++(int)
-        { _iterator ret(p); (void)this->operator++(); return ret; }
-        constexpr _iterator& operator--(void)
-        { p = p->prev(); return *this; }
-        constexpr _iterator operator--(int)
-        { _iterator ret(p); (void)this->operator--(); return ret; }
-        constexpr operator bool() const
-        { return p; }
-        constexpr operator _iterator<true>() const
-        { return _iterator<true> { p }; }
-    };
-
-    using iterator = _iterator<false>;
-    using const_iterator = _iterator<true>;
-
-    using node_allocator = typename
-        std::allocator_traits<Allocator>::template rebind_alloc<node>;
-    using node_alloc_traits = std::allocator_traits<node_allocator>;
-
-    compressed_pair<node*, node_allocator> root_data;
-    compressed_pair<std::size_t, Compare> size_data;
-
-private:
-    constexpr node*& _root() noexcept { return root_data.first(); }
-    constexpr node* const& _root() const noexcept { return root_data.first(); }
-
-    constexpr std::size_t& _size() noexcept { return size_data.first(); }
-    constexpr const std::size_t& _size() const noexcept { return size_data.first(); }
-
-    constexpr node_allocator& _alloc() noexcept { return root_data.second(); }
-    constexpr const node_allocator& _alloc() const noexcept { return root_data.second(); }
-
-    constexpr Compare& _comp() noexcept { return size_data.second(); }
-    constexpr const Compare& _comp() const noexcept { return size_data.second(); }
-
-    template <typename... Args>
-    constexpr node* newnode(Args&&... key)
-    {
-        node* ptr = node_alloc_traits::allocate(_alloc(), 1);
-        node_alloc_traits::construct(_alloc(), ptr, std::forward<Args>(key)...);
-        return ptr;
-    }
-
-    constexpr void delnode(node* nd)
-    {
-        node_alloc_traits::destroy(_alloc(), nd);
-        node_alloc_traits::deallocate(_alloc(), nd, 1);
-    }
-
-    constexpr void do_insertion(node* parent,
-        node*& child_inserted, node* nd)
-    {
-        nd->parent = parent;
-        child_inserted = nd;
-        this->balance(nd);
-        ++_size();
-    }
-
-public:
-    constexpr iterator end(void) noexcept
-    { return iterator(nullptr); }
-    constexpr const_iterator end(void) const noexcept
-    { return const_iterator(nullptr); }
-    constexpr const_iterator cend(void) const noexcept
-    { return const_iterator(nullptr); }
-
-    constexpr iterator begin(void) noexcept
-    { return _root() ? iterator(_root()->leftmost()) : end(); }
-    constexpr const_iterator begin(void) const noexcept
-    { return _root() ? const_iterator(_root()->leftmost()) : end(); }
-    constexpr const_iterator cbegin(void) const noexcept
-    { return _root() ? const_iterator(_root()->leftmost()) : end(); }
-
-    constexpr void destroy(node* nd)
-    {
-        if (!nd)
-            return;
-        destroy(nd->left);
-        destroy(nd->right);
-        delnode(nd);
-    }
-
-    constexpr void destroy() { destroy(_root()); _root() = nullptr; _size() = 0; }
-
-    constexpr node* copy(node* nd)
-    {
-        if (!nd)
-            return nullptr;
-
-        node* newnd = newnode(nd->value);
-        newnd->color = nd->color;
-        ++_size();
-
-        newnd->left = copy(nd->left);
-        if (newnd->left)
-            newnd->left->parent = newnd;
-
-        newnd->right = copy(nd->right);
-        if (newnd->right)
-            newnd->right->parent = newnd;
-
-        return newnd;
-    }
-
-    explicit constexpr rbtree(const Compare& comp, const node_allocator& alloc)
-        : root_data{nullptr, alloc}, size_data{0, comp} { }
-
-    constexpr rbtree(const rbtree& other)
-        : rbtree(other._comp(), other._alloc())
-    {
-        _root() = copy(other._root());
-        if (_root())
-            _root()->parent = nullptr;
-    }
-
-    constexpr rbtree(const rbtree& other, const node_allocator& alloc)
-        : rbtree(other._comp(), alloc)
-    {
-        _root() = copy(other._root());
-        if (_root())
-            _root()->parent = nullptr;
-    }
-
-    constexpr rbtree(rbtree&& other) noexcept
-        : root_data{std::exchange(other._root(), nullptr), std::move(other._alloc())}
-        , size_data{std::exchange(other._size(), 0), std::move(other._comp())} { }
-
-    constexpr rbtree(rbtree&& other, const node_allocator& alloc) noexcept
-        : root_data{std::exchange(other._root(), nullptr), alloc}
-        , size_data{std::exchange(other._size(), 0), std::move(other._comp())} { }
-
-    constexpr ~rbtree() { destroy(); }
-
-    constexpr rbtree& operator=(const rbtree& other)
-    {
-        destroy(_root());
-
-        _comp() = other._comp();
-        if constexpr (node_alloc_traits::
-            propagate_on_container_copy_assignment::value)
-            _alloc() = other._alloc();
-
-        _root() = copy(other._root());
-        if (_root())
-            _root()->parent = nullptr;
-
-        return *this;
-    }
-
-    constexpr rbtree& operator=(rbtree&& other) noexcept
-    {
-        destroy(_root());
-        _root() = std::exchange(other._root(), nullptr);
-        _size() = std::exchange(other._size(), 0);
-        _comp() = std::move(other._comp());
-        if constexpr (node_alloc_traits::
-            propagate_on_container_move_assignment::value)
-            _alloc() = std::move(other._alloc());
-
-        return *this;
-    }
-
-    constexpr void rotateleft(node* rt)
-    {
-        node* nrt = rt->right;
-
-        if (!rt->is_root()) {
-            if (rt->is_left_child())
-                rt->parent->left = nrt;
-            else
-                rt->parent->right = nrt;
-        } else {
-            _root() = nrt;
-        }
-
-        nrt->parent = rt->parent;
-        rt->parent = nrt;
-
-        rt->right = nrt->left;
-        if (rt->right)
-            rt->right->parent = rt;
-
-        nrt->left = rt;
-    }
-
-    constexpr void rotateright(node* rt)
-    {
-        node* nrt = rt->left;
-
-        if (!rt->is_root()) {
-            if (rt->is_left_child())
-                rt->parent->left = nrt;
-            else
-                rt->parent->right = nrt;
-        } else {
-            _root() = nrt;
-        }
-
-        nrt->parent = rt->parent;
-        rt->parent = nrt;
-
-        rt->left = nrt->right;
-        if (rt->left)
-            rt->left->parent = rt;
-        nrt->right = rt;
-    }
-
-    constexpr void balance(node* nd)
-    {
-        if (nd->is_root()) {
-            nd->toblack();
-            return;
-        }
-
-        if (node::is_black(nd->parent))
-            return;
-
-        node* p = nd->parent;
-        node* pp = nd->grandparent();
-        node* uncle = nd->uncle();
-
-        if (node::is_red(uncle)) {
-            p->toblack();
-            uncle->toblack();
-            pp->tored();
-            this->balance(pp);
-            return;
-        }
-
-        if (p->is_left_child()) {
-            if (nd->is_left_child()) {
-                p->toblack();
-                pp->tored();
-                this->rotateright(pp);
-            } else {
-                this->rotateleft(p);
-                this->balance(p);
-            }
-        } else {
-            if (nd->is_right_child()) {
-                p->toblack();
-                pp->tored();
-                this->rotateleft(pp);
-            } else {
-                this->rotateright(p);
-                this->balance(p);
-            }
-        }
-    }
-
-    template <typename U>
-    constexpr node* _find(const U& key) const
-    {
-        for (node* cur = _root(); cur; ) {
-            if (_comp()(key, cur->value))
-                cur = cur->left;
-            else if (_comp()(cur->value, key))
-                cur = cur->right;
-            else
-                return cur;
-        }
-
-        return nullptr;
-    }
-
-    template <typename U>
-    constexpr iterator find(const U& key) const
-    { return iterator { _find(key) }; }
-
-    // RBTREE RECURSIVE DELETE
-    // THIS FUNCTION DOES NOT DELLOCATE THE NODE
-    // CALLER IS RESPONSIBLE FOR FREEING THE MEMORY
-    // @param: nd is guaranteed to be a leaf node
-    constexpr void _erase(node* nd)
-    {
-        if (nd->is_root())
-            return;
-
-        if (node::is_black(nd)) {
-            node* p = nd->parent;
-            node* s = nullptr;
-            if (nd->is_left_child())
-                s = p->right;
-            else
-                s = p->left;
-
-            if (node::is_red(s)) {
-                p->tored();
-                s->toblack();
-                if (nd->is_right_child()) {
-                    this->rotateright(p);
-                    s = p->left;
-                } else {
-                    this->rotateleft(p);
-                    s = p->right;
-                }
-            }
-
-            node* r = nullptr;
-            if (node::is_red(s->left)) {
-                r = s->left;
-                if (s->is_left_child()) {
-                    r->toblack();
-                    s->color = p->color;
-                    this->rotateright(p);
-                    p->toblack();
-                } else {
-                    r->color = p->color;
-                    this->rotateright(s);
-                    this->rotateleft(p);
-                    p->toblack();
-                }
-            } else if (node::is_red(s->right)) {
-                r = s->right;
-                if (s->is_left_child()) {
-                    r->color = p->color;
-                    this->rotateleft(s);
-                    this->rotateright(p);
-                    p->toblack();
-                } else {
-                    r->toblack();
-                    s->color = p->color;
-                    this->rotateleft(p);
-                    p->toblack();
-                }
-            } else {
-                s->tored();
-                if (node::is_black(p))
-                    this->_erase(p);
-                else
-                    p->toblack();
-            }
-        }
-    }
-
-    // delete nd from the tree. make nd safe to deallocate
-    // THIS FUNCTION DOES NOT DELLOCATE THE NODE
-    // CALLER IS RESPONSIBLE FOR FREEING THE MEMORY
-    constexpr node* erase(node* nd)
-    {
-        if (nd->is_root() && nd->is_leaf()) {
-            _root() = nullptr;
-            return nullptr;
-        }
-
-        node* next = nd->next();
-
-        while (!nd->is_leaf()) {
-            node* alt = nd->right ? nd->right->leftmost() : nd->left;
-            if (nd->is_root())
-                _root() = alt;
-            node::swap(nd, alt);
-        }
-
-        this->_erase(nd);
-
-        if (nd->is_left_child())
-            nd->parent->left = nullptr;
-        else
-            nd->parent->right = nullptr;
-
-        return next;
-    }
-
-    constexpr iterator erase(iterator pos) noexcept
-    {
-        node* nextpos = erase(pos.p);
-        delnode(pos.p);
-        --_size();
-        return iterator { nextpos };
-    }
-
-    constexpr iterator erase(const_iterator pos) noexcept
-    {
-        node* nextpos = erase(pos.p);
-        delnode(pos.p);
-        --_size();
-        return iterator { nextpos };
-    }
-
-    template <typename U>
-    constexpr iterator lower_bound(U&& val) const
-    {
-        node* cur = _root();
-        node* result = nullptr;
-
-        while (cur) {
-            if (!_comp()(cur->value, val)) {
-                result = cur;
-                cur = cur->left;
-            }
-            else {
-                cur = cur->right;
-            }
-        }
-
-        return iterator { result };
-    }
-
-    template <typename U>
-    constexpr iterator upper_bound(U&& val) const
-    {
-        iterator iter = lower_bound(std::forward<U>(val));
-        if (iter && !_comp()(*iter, val) && !_comp()(val, *iter))
-            return ++iter;
-        return iter;
-    }
-
-    // value in nd MUST NOT exist in the rbtree,
-    // that is, if a < b, then a > b
-    constexpr void insert(node* nd)
-    {
-        node* cur = _root();
-
-        while (cur) {
-            if (_comp()(nd->value, cur->value)) {
-                if (!cur->left) {
-                    do_insertion(cur, cur->left, nd);
-                    return;
-                }
-                cur = cur->left;
-            } else {
-                if (!cur->right) {
-                    do_insertion(cur, cur->right, nd);
-                    return;
-                }
-                cur = cur->right;
-            }
-        }
-        do_insertion(cur, _root(), nd);
-    }
-
-    template <typename U>
-    constexpr std::pair<iterator, bool> insert(U&& value)
-    {
-        auto iter = find(value);
-        if (iter)
-            return { iter, false };
-
-        node* ptr = newnode(std::forward<U>(value));
-        insert(ptr);
-
-        return { iterator { ptr }, true };
-    }
-
-    template <typename... Args>
-    constexpr std::pair<iterator, bool> emplace(Args&&... args)
-    {
-        node* nd = newnode(std::forward<Args>(args)...);
-        node* exist_nd = _find(nd->value);
-        if (exist_nd) {
-            delnode(nd);
-            return { iterator { exist_nd }, false };
-        }
-        insert(nd);
-        return { iterator { nd }, true };
-    }
-
-    constexpr bool empty() const noexcept { return !_root(); }
-    constexpr std::size_t size() const noexcept { return _size(); }
-
-    constexpr void swap(rbtree& other)
-    {
-        std::swap(_root(), other._root());
-        std::swap(_size(), other._size());
-        std::swap(_comp(), other._comp());
-        if constexpr (node_alloc_traits::propagate_on_container_swap::value)
-            std::swap(_alloc(), other._alloc());
-    }
-};
-
-} // namespace std::impl
-
-#endif

+ 0 - 27
gblibstdc++/include/bits/sequence

@@ -1,27 +0,0 @@
-#ifndef __GBLIBCPP_BITS_SEQUENCE__
-#define __GBLIBCPP_BITS_SEQUENCE__
-
-#include <cstddef>
-
-namespace std {
-
-template <typename T, T... Ints>
-struct integer_sequence {
-    static constexpr std::size_t size() noexcept { return sizeof...(Ints); }
-};
-
-template <std::size_t... Indicies>
-using index_sequence = integer_sequence<std::size_t, Indicies...>;
-
-template <std::size_t N, std::size_t... Indicies>
-struct make_index_sequence : public make_index_sequence<N-1, N-1, Indicies...> {};
-
-template <std::size_t... Indicies>
-struct make_index_sequence<0, Indicies...> : public index_sequence<Indicies...> {};
-
-template <typename... Ts>
-using index_sequence_for = make_index_sequence<sizeof...(Ts)>;
-
-} // namespace std
-
-#endif

+ 0 - 82
gblibstdc++/include/bits/tuple_tools

@@ -1,82 +0,0 @@
-#ifndef __GBLIBCPP_BITS_TUPLE_TOOLS__
-#define __GBLIBCPP_BITS_TUPLE_TOOLS__
-
-#include <cstddef>
-
-#include <bits/type_traits/remove_add>
-
-#include <bits/forward>
-#include <bits/sequence>
-
-#include <bits/fwd_functional>
-
-namespace std {
-
-template <typename... Types>
-class tuple;
-
-template <std::size_t I, typename T>
-struct tuple_element;
-
-template <std::size_t I, typename T>
-using tuple_element_t = typename tuple_element<I, T>::type;
-
-template <typename T>
-struct tuple_size;
-
-template <typename T>
-inline constexpr std::size_t tuple_size_v = tuple_size<T>::value;
-
-template <std::size_t I, typename... Types>
-constexpr auto get(std::tuple<Types...>& tpl) noexcept
-    -> tuple_element_t<I, std::tuple<Types...>>&
-{ return tpl.template _getl<I>(); }
-
-template <std::size_t I, typename... Types>
-constexpr auto get(std::tuple<Types...>&& tpl) noexcept
-    -> tuple_element_t<I, std::tuple<Types...>>&&
-{ return tpl.template _getr<I>(); }
-
-template <std::size_t I, typename... Types>
-constexpr auto get(const std::tuple<Types...>& tpl) noexcept
-    -> tuple_element_t<I, std::tuple<Types...>> const&
-{ return tpl.template _getl<I>(); }
-
-template <std::size_t I, typename... Types>
-constexpr auto get(const std::tuple<Types...>&& tpl) noexcept
-    -> tuple_element_t<I, std::tuple<Types...>> const&&
-{ return tpl.template _getr<I>(); }
-
-namespace __helpers {
-
-template <typename T, typename Tuple, std::size_t... I>
-constexpr T make_from_tuple_impl(Tuple&& tpl, std::index_sequence<I...>)
-{
-    return T(std::get<I>(std::forward<Tuple>(tpl))...);
-}
-
-template <typename _T, typename T = std::decay_t<_T>>
-struct __to_tuple_type { using type = T; };
-
-template <typename _T, typename T>
-struct __to_tuple_type<_T, std::reference_wrapper<T>>
-{ using type = std::add_lvalue_reference_t<T>; };
-
-template <typename T>
-using to_tuple_type_t = typename __to_tuple_type<T>::type;
-
-} // namespace __helpers
-
-template <typename T, typename Tuple>
-constexpr T make_from_tuple(Tuple&& tpl)
-{
-    return __helpers::make_from_tuple_impl<T>(
-        std::forward<Tuple>(tpl),
-        std::make_index_sequence<
-            std::tuple_size_v<std::remove_cvref_t<Tuple>>> {}
-    );
-}
-
-}
-
-#endif

+ 0 - 46
gblibstdc++/include/bits/type_traits/base

@@ -1,46 +0,0 @@
-#ifndef __GBLIBCPP_BITS_TYPE_TRAITS_BASE__
-#define __GBLIBCPP_BITS_TYPE_TRAITS_BASE__
-
-#include <cstddef>
-
-namespace std {
-
-template <typename... Ts>
-using void_t = void;
-
-template <typename T, T _value>
-struct integral_constant {
-    using value_type = T;
-    using type = integral_constant;
-
-    static constexpr value_type value = _value;
-    constexpr operator value_type() const noexcept { return value; }
-    constexpr value_type operator()() const noexcept { return value; }
-};
-
-template <bool _value>
-using bool_constant = integral_constant<bool, _value>;
-
-using true_type = bool_constant<true>;
-using false_type = bool_constant<false>;
-
-template <bool condition, typename T, typename F>
-struct conditional { using type = F; };
-template <typename T, typename F>
-struct conditional<true, T, F> { using type = T; };
-
-template <bool condition, typename T, typename F>
-using conditional_t = typename conditional<condition, T, F>::type;
-
-namespace __helpers {
-
-template <typename>
-struct template_true_type : public true_type {};
-template <typename>
-struct template_false_type : public false_type {};
-
-} // namespace __helpers
-
-} // namespace std
-
-#endif

+ 0 - 40
gblibstdc++/include/bits/type_traits/is_es

@@ -1,40 +0,0 @@
-#ifndef __GBLIBCPP_BITS_TYPE_TRAITS_IS_ES__
-#define __GBLIBCPP_BITS_TYPE_TRAITS_IS_ES__
-
-#include <cstddef>
-
-#include <bits/type_traits/base>
-
-namespace std {
-
-template <typename T>
-struct is_array : public false_type {};
-template <typename T>
-struct is_array<T[]> : public true_type {};
-template <typename T, size_t N>
-struct is_array<T[N]> : public true_type {};
-
-template <typename T>
-inline constexpr bool is_array_v = is_array<T>::value;
-
-template <typename T>
-struct is_const : public false_type {};
-template <typename T>
-struct is_const<T const> : public true_type {};
-
-template <typename T>
-inline constexpr bool is_const_v = is_const<T>::value;
-
-template <typename T>
-struct is_function : public bool_constant<!is_const_v<const T>> {};
-template <typename T>
-struct is_function<T&> : public false_type {};
-template <typename T>
-struct is_function<T&&> : public false_type {};
-
-template <typename T>
-inline constexpr bool is_function_v = is_function<T>::value;
-
-} // namespace std
-
-#endif

+ 0 - 123
gblibstdc++/include/bits/type_traits/remove_add

@@ -1,123 +0,0 @@
-#ifndef __GBLIBCPP_BITS_TYPE_TRAITS_REMOVE_ADD__
-#define __GBLIBCPP_BITS_TYPE_TRAITS_REMOVE_ADD__
-
-#include <cstddef>
-
-#include <bits/type_traits/is_es>
-
-namespace std {
-
-// REMOVES
-
-template <typename T>
-struct remove_reference { using type = T; };
-template <typename T>
-struct remove_reference<T&> { using type = T; };
-template <typename T>
-struct remove_reference<T&&> { using type = T; };
-
-template <typename T>
-using remove_reference_t = typename remove_reference<T>::type;
-
-template <typename T>
-struct remove_pointer { using type = T; };
-template <typename T>
-struct remove_pointer<T*> { using type = T; };
-template <typename T>
-struct remove_pointer<T* const> { using type = T; };
-template <typename T>
-struct remove_pointer<T* volatile> { using type = T; };
-template <typename T>
-struct remove_pointer<T* const volatile> { using type = T; };
-
-template <typename T>
-using remove_pointer_t = typename remove_pointer<T>::type;
-
-template <typename T>
-struct remove_extent { using type = T; };
-template <typename T>
-struct remove_extent<T[]> { using type = T; };
-template <typename T, std::size_t N>
-struct remove_extent<T[N]> { using type = T; };
-
-template <typename T>
-using remove_extent_t = typename remove_extent<T>::type;
-
-template <typename T>
-struct remove_cv { using type = T; };
-template <typename T>
-struct remove_cv<T const> { using type = T; };
-template <typename T>
-struct remove_cv<T volatile> { using type = T; };
-template <typename T>
-struct remove_cv<T const volatile> { using type = T; };
-
-template <typename T>
-using remove_cv_t = typename remove_cv<T>::type;
-
-template <typename T>
-struct remove_cvref {
-    using type = remove_cv_t<remove_reference_t<T>>;
-};
-
-template <typename T>
-using remove_cvref_t = typename remove_cvref<T>::type;
-
-// ADDS
-
-template <typename T>
-struct add_pointer { using type = remove_reference_t<T>*; };
-
-template <typename T>
-using add_pointer_t = typename add_pointer<T>::type;
-
-namespace __helpers {
-
-template <typename T, typename = void> // for cv-void
-struct add_rvalue_reference { using type = T; };
-template <typename T> // cv-void will fail in substitution
-struct add_rvalue_reference<T, void_t<T&&> > { using type = T&&; };
-
-template <typename T, typename = void> // for cv-void
-struct add_lvalue_reference { using type = T; };
-template <typename T> // cv-void will fail in substitution
-struct add_lvalue_reference<T, void_t<T&> > { using type = T&; };
-
-} // namespace __helpers
-
-template <typename T>
-struct add_rvalue_reference {
-    using type = typename __helpers::add_rvalue_reference<T>::type;
-};
-template <typename T>
-struct add_lvalue_reference {
-    using type = typename __helpers::add_lvalue_reference<T>::type;
-};
-
-template <typename T>
-using add_rvalue_reference_t = typename add_rvalue_reference<T>::type;
-template <typename T>
-using add_lvalue_reference_t = typename add_lvalue_reference<T>::type;
-
-template <typename T>
-struct decay {
-private:
-    using U = remove_reference_t<T>;
-public:
-    using type = conditional_t<
-        is_array_v<U>,
-        add_pointer_t<remove_extent_t<U>>,
-        conditional_t<
-            is_function_v<U>,
-            add_pointer_t<U>,
-            remove_cv_t<U>
-        >
-    >;
-};
-
-template <typename T>
-using decay_t = typename decay<T>::type;
-
-} // namespace std
-
-#endif

+ 0 - 20
gblibstdc++/include/cstddef

@@ -1,20 +0,0 @@
-#ifndef __GBLIBCPP_CSTDDEF__
-#define __GBLIBCPP_CSTDDEF__
-
-#define __GBLIBCPP_CONSTEXPR constexpr
-
-#undef NULL
-#define NULL (nullptr)
-
-namespace std {
-
-using nullptr_t = decltype(nullptr);
-
-using size_t = __SIZE_TYPE__;
-using ptrdiff_t = __PTRDIFF_TYPE__;
-
-enum class byte : unsigned char {};
-
-}; // namespace std
-
-#endif

+ 0 - 329
gblibstdc++/include/functional

@@ -1,329 +0,0 @@
-#ifndef __GBLIBCPP_FUNCTIONAL__
-#define __GBLIBCPP_FUNCTIONAL__
-
-#include <bits/fwd_functional>
-
-#include <cstddef>
-#include <memory>
-#include <new>
-#include <utility>
-#include <type_traits>
-
-namespace std {
-
-template <typename Func, typename... Args>
-constexpr auto invoke(Func&& func, Args&&... args)
-    noexcept(std::is_nothrow_invocable_v<Func, Args...>)
-    -> std::enable_if_t<std::is_invocable_v<Func, Args...>,
-        std::invoke_result_t<Func, Args...>>
-{
-    return __helpers::INVOKE(std::forward<Func>(func), std::forward<Args>(args)...);
-}
-
-template <typename R, typename Func, typename... Args>
-constexpr auto invoke_r(Func&& func, Args&&... args)
-    noexcept(std::is_nothrow_invocable_r_v<R, Func, Args...>)
-    -> std::enable_if_t<std::is_invocable_r_v<R, Func, Args...>, R>
-{
-    return __helpers::INVOKE_R<R>(std::forward<Func>(func), std::forward<Args>(args)...);
-}
-
-namespace __helpers {
-template <typename T> constexpr void __reference_wrapper_check(T&) noexcept {}
-template <typename T> void __reference_wrapper_check(T&&) = delete;
-} // namespace __helpers
-
-template <typename T>
-class reference_wrapper {
-private:
-    T* _ptr;
-
-    template <typename Ref, typename =
-        decltype(__helpers::__reference_wrapper_check<T>(std::declval<Ref>()))>
-    struct __check_reference_valid
-        : public bool_constant<!std::is_same_v<reference_wrapper, std::decay_t<Ref>>> {};
-
-public:
-    using type = T;
-
-    constexpr T& get(void) const noexcept { return *_ptr; }
-    constexpr operator T&(void) const noexcept { return *_ptr; }
-
-    template <typename U, std::enable_if_t<__check_reference_valid<U>::value, bool> = true>
-    constexpr reference_wrapper(U&& ref)
-        noexcept(noexcept(__helpers::__reference_wrapper_check<T>(std::declval<U>())))
-        : _ptr(std::addressof(ref)) {}
-
-    constexpr reference_wrapper(const reference_wrapper& val) noexcept
-    {
-        _ptr = val._ptr;
-    }
-    constexpr reference_wrapper& operator=(const reference_wrapper& val) noexcept = default;
-
-    // TODO: std::invoke_result_t
-    template <typename... Args>
-    constexpr invoke_result_t<type&, Args...>
-    operator()(Args&&... args) const noexcept(is_nothrow_invocable_v<type&, Args...>)
-    {
-        return std::invoke(get(), std::forward<Args>(args)...);
-    }
-};
-template <typename T>
-reference_wrapper(T&) -> reference_wrapper<T>;
-
-namespace __inner {
-
-    template <typename Ret, typename... Args>
-    class _function_base {
-    public:
-        virtual constexpr ~_function_base() = default;
-        virtual constexpr Ret operator()(Args... args) const = 0;
-        virtual constexpr void copy_to(_function_base* func) = 0;
-        virtual constexpr void move_to(_function_base* func) = 0;
-        virtual explicit constexpr operator bool(void) const = 0;
-    };
-
-    template <typename FuncLike, typename Ret, typename... Args>
-    class _function : public _function_base<Ret, Args...> {
-    private:
-        using __enable = std::enable_if_t<
-            std::is_invocable_r_v<Ret, std::decay_t<FuncLike>, Args...>
-        >;
-        FuncLike func;
-
-    public:
-        constexpr _function(const FuncLike& _func) : func(_func) {}
-        constexpr _function(FuncLike&& _func) : func(std::move(_func)) {}
-
-        constexpr Ret operator()(Args... args) const override
-        {
-            return std::invoke(func, std::forward<Args>(args)...);
-        }
-
-        constexpr void copy_to(_function_base<Ret, Args...>* dst) override
-        {
-            new (reinterpret_cast<_function*>(dst)) _function(*this);
-        }
-
-        constexpr void move_to(_function_base<Ret, Args...>* dst) override
-        {
-            new (reinterpret_cast<_function*>(dst)) _function(std::move(*this));
-        }
-
-        constexpr explicit operator bool(void) const override
-        {
-            return true;
-        }
-    };
-
-    template <typename Ret, typename... Args>
-    class _function<nullptr_t, Ret, Args...> : public _function_base<Ret, Args...> {
-    public:
-        [[noreturn]] Ret operator()(Args...) const override
-        {
-            // TODO: exception
-            *((int*)(100^100)) = 1; // triggers access to null pointer
-            for (;;);
-        }
-        constexpr void copy_to(_function_base<Ret, Args...>* dst) override
-        {
-            new (reinterpret_cast<_function*>(dst)) _function(*this);
-        }
-        constexpr void move_to(_function_base<Ret, Args...>* dst) override
-        {
-            new (reinterpret_cast<_function*>(dst)) _function(std::move(*this));
-        }
-        constexpr explicit operator bool(void) const override
-        {
-            return false;
-        }
-    };
-
-} // namespace __inner
-
-template <typename Ret, typename... Args>
-class function<Ret(Args...)> {
-public:
-    using result_type = Ret;
-
-private:
-    static constexpr std::size_t STACK_ALLOCATED_SIZE = 24;
-
-    char _data[STACK_ALLOCATED_SIZE];
-    using fb_t = __inner::_function_base<Ret, Args...>;
-    constexpr fb_t* _f(void) const
-    {
-        return (fb_t*)_data;
-    }
-
-    constexpr void _clear(void)
-    {
-        _f()->~_function_base();
-    }
-
-public:
-    constexpr function() noexcept
-    {
-        new (_f()) __inner::_function<nullptr_t, Ret, Args...>();
-    }
-    constexpr function(nullptr_t) noexcept : function() {}
-    constexpr function(const function& func)
-    {
-        func._f()->copy_to(_f());
-    }
-    constexpr function(function&& func) noexcept
-    {
-        func._f()->move_to(_f());
-    }
-
-    template <typename FuncLike, std::enable_if_t
-        <
-            // TODO: check its behavior for nullptr
-            std::is_invocable_r_v<Ret, std::decay_t<FuncLike>, Args...>
-            && (sizeof(std::decay_t<FuncLike>) <= STACK_ALLOCATED_SIZE - sizeof(void*))
-            && !std::is_same_v<std::decay_t<FuncLike>, function>
-        , bool> = true
-    >
-    constexpr function(FuncLike&& func)
-    {
-        new (_f()) __inner::_function<std::decay_t<FuncLike>, Ret, Args...>(std::forward<FuncLike>(func));
-    }
-
-    constexpr ~function()
-    {
-        _clear();
-    }
-
-    constexpr Ret operator()(Args... args) const
-    {
-        return (*_f())(std::forward<Args>(args)...);
-    }
-
-    explicit operator bool(void) const noexcept
-    {
-        return !!*_f();
-    }
-
-    function& operator=(function&& rhs)
-    {
-        _clear();
-        rhs._f()->move_to(_f());
-        return *this;
-    }
-
-    void swap(function& other) noexcept
-    {
-        function tmp(std::move(other));
-        other = std::move(*this);
-        *this = std::move(tmp);
-    }
-
-    function& operator=(const function& rhs)
-    {
-        _clear();
-        rhs._f()->copy_to(_f());
-        return *this;
-    }
-
-    function& operator=(nullptr_t) noexcept
-    {
-        _clear();
-        new (_f()) __inner::_function<nullptr_t, Ret, Args...>();
-        return *this;
-    }
-
-    template <typename FuncLike, std::enable_if_t
-        <
-            std::is_same_v<
-                Ret,
-                decltype(std::declval<std::decay_t<FuncLike>>()(std::declval<Args>()...))
-            >
-            && (sizeof(std::decay_t<FuncLike>) <= sizeof(_data))
-            && !std::is_same_v<std::decay_t<FuncLike>, function>
-        , bool> = true
-    >
-    function& operator=(FuncLike&& func)
-    {
-        function{std::forward<FuncLike>(func)}.swap(*this);
-        return *this;
-    }
-
-    template <typename FuncLike>
-    function& operator=(std::reference_wrapper<FuncLike> func) noexcept
-    {
-        function{func}.swap(*this);
-        return *this;
-    }
-};
-
-template <typename Ret, typename... Args>
-bool operator==(const std::function<Ret(Args...)>& func, std::nullptr_t) noexcept
-{
-    return !func;
-}
-
-template <typename Ret, typename... Args>
-void swap(std::function<Ret(Args...)>& lhs, std::function<Ret(Args...)>& rhs) noexcept
-{
-    return lhs.swap(rhs);
-}
-
-template <typename T>
-constexpr std::reference_wrapper<T> ref(T& t) noexcept
-{
-    return std::reference_wrapper<T>((t));
-}
-
-template <typename T>
-constexpr std::reference_wrapper<T>
-    ref(std::reference_wrapper<T> t) noexcept
-{
-    return t;
-}
-
-template <typename T>
-constexpr std::reference_wrapper<const T> cref(const T& t) noexcept
-{
-    return std::reference_wrapper<const T>((t));
-}
-
-template <typename T>
-constexpr std::reference_wrapper<const T>
-    cref(std::reference_wrapper<T> t) noexcept
-{
-    return t;
-}
-
-// Comparators
-
-template <typename T = void>
-struct less {
-    constexpr bool operator()(const T& lhs, const T& rhs) const
-    { return lhs < rhs; }
-};
-
-template <>
-struct less<void> {
-    template <typename T, typename U>
-    constexpr auto operator()(T&& lhs, U&& rhs) const
-        -> decltype(std::forward<T>(lhs) < std::forward<U>(rhs))
-    { return std::forward<T>(lhs) < std::forward<U>(rhs); }
-};
-
-template <typename T = void>
-struct greater {
-    constexpr bool operator()(const T& lhs, const T& rhs) const
-    { return lhs > rhs; }
-};
-
-template <>
-struct greater<void> {
-    template <typename T, typename U>
-    constexpr auto operator()(T&& lhs, U&& rhs) const
-        -> decltype(std::forward<T>(lhs) > std::forward<U>(rhs))
-    { return std::forward<T>(lhs) > std::forward<U>(rhs); }
-};
-
-} // namespace std
-
-#endif

+ 0 - 122
gblibstdc++/include/initializer_list

@@ -1,122 +0,0 @@
-#ifndef __GBLIBCPP_INITIALIZER_LIST__
-#define __GBLIBCPP_INITIALIZER_LIST__
-
-#include <cstddef>
-
-namespace std {
-
-#if defined(__GNUC__)
-
-template <typename T>
-class initializer_list {
-public:
-    using value_type = T;
-    using reference = const T&;
-    using const_reference = const T&;
-    using size_type = std::size_t;
-    using iterator = const T*;
-    using const_iterator = const T*;
-
-private:
-    const T* __begin;
-    std::size_t __size;
-
-public:
-    constexpr initializer_list() noexcept
-        : __begin { }, __size { } { };
-
-    constexpr const T* begin() const noexcept
-    { return __begin; }
-    constexpr const T* end() const noexcept
-    { return __begin + __size; }
-    constexpr size_type size() const noexcept
-    { return __size; }
-
-};
-
-#elif defined(__clang__)
-
-template <typename T>
-class initializer_list {
-public:
-    using value_type = T;
-    using reference = const T&;
-    using const_reference = const T&;
-    using size_type = std::size_t;
-    using iterator = const T*;
-    using const_iterator = const T*;
-
-private:
-    const T* __begin;
-    const T* __end;
-
-public:
-    constexpr initializer_list() noexcept
-        : __begin { }, __end { } { };
-
-    constexpr const T* begin() const noexcept
-    { return __begin; }
-    constexpr const T* end() const noexcept
-    { return __end; }
-    constexpr size_type size() const noexcept
-    { return static_cast<size_type>(__end - __begin); }
-
-};
-
-#elif defined(_MSC_VER)
-
-template <typename T>
-class initializer_list {
-public:
-    using value_type = T;
-    using reference = const T&;
-    using const_reference = const T&;
-    using size_type = std::size_t;
-    using iterator = const T*;
-    using const_iterator = const T*;
-
-private:
-    const T* __begin;
-    const T* __end;
-
-public:
-    constexpr initializer_list() noexcept
-        : __begin { }, __end { } { };
-
-    constexpr const T* begin() const noexcept
-    { return __begin; }
-    constexpr const T* end() const noexcept
-    { return __end; }
-    constexpr size_type size() const noexcept
-    { return static_cast<size_type>(__end - __begin); }
-
-};
-
-#else
-
-template <typename T>
-class initializer_list;
-
-#endif
-
-template <typename T>
-constexpr const T* begin(initializer_list<T> il) noexcept
-{ return il.begin(); }
-
-template <typename T>
-constexpr const T* end(initializer_list<T> il) noexcept
-{ return il.end(); }
-
-template <typename T>
-[[nodiscard]] constexpr bool empty(initializer_list<T> il) noexcept
-{ return il.size() == 0; }
-
-template <typename T>
-constexpr const T* data(initializer_list<T> il) noexcept
-{ return il.begin(); }
-
-// TODO: std::rbegin() and std::rend() for std::initializer_list
-
-} // namespace std
-
-#endif

+ 0 - 502
gblibstdc++/include/list

@@ -1,502 +0,0 @@
-#ifndef __GBLIBCPP_LIST__
-#define __GBLIBCPP_LIST__
-
-#include <bits/compressed_pair>
-#include <bits/iter_ops>
-
-#include <memory>
-#include <initializer_list>
-#include <type_traits>
-#include <utility>
-#include <cstddef>
-
-namespace std {
-
-template <typename T, typename Allocator = std::allocator<T>>
-class list {
-private:
-    struct node_base {
-        node_base* prev;
-        node_base* next;
-        constexpr node_base() noexcept
-            : prev { this }, next { this } {}
-
-        constexpr void connect(node_base* _next) noexcept
-        {
-            this->next = _next;
-            _next->prev = static_cast<node_base*>(this);
-        }
-
-        constexpr void swap(node_base& other) noexcept
-        {
-            std::swap(prev, other.prev);
-            std::swap(next, other.next);
-        }
-    };
-
-    struct node : public node_base {
-        T value;
-        template <typename... Args>
-        explicit constexpr node(Args&&... args)
-            : value(std::forward<Args>(args)...) { }
-    };
-
-public:
-    template <bool Const>
-    class _iterator;
-
-public:
-    using value_type = T;
-    using allocator_type = Allocator;
-    using size_type = std::size_t;
-    using difference_type = std::ptrdiff_t;
-    using reference = T&;
-    using const_reference = const T&;
-    using pointer = typename std::allocator_traits<Allocator>::pointer;
-    using const_pointer = typename
-        std::allocator_traits<Allocator>::const_pointer;
-    using iterator = _iterator<false>;
-    using const_iterator = _iterator<true>;
-
-private:
-    using alloc_traits = std::allocator_traits<allocator_type>;
-    using node_alloc_type = typename
-        std::allocator_traits<Allocator>::template rebind_alloc<node>;
-    using node_alloc_traits = std::allocator_traits<node_alloc_type>;
-
-public:
-    template <bool Const>
-    class _iterator {
-    public:
-        using const_node_pointer = const node_base*;
-        using node_pointer = node_base*;
-        using value_type = std::conditional_t<Const, const T, T>;
-        using pointer = std::add_pointer_t<value_type>;
-        using reference = std::add_lvalue_reference_t<value_type>;
-
-        friend class list;
-
-    private:
-        node_pointer p;
-
-    public:
-        constexpr _iterator() noexcept = default;
-        explicit constexpr _iterator(const_node_pointer p)
-            : p { const_cast<node_pointer>(p) } {}
-        constexpr _iterator(const _iterator& iter) noexcept = default;
-        constexpr _iterator(_iterator&& iter) noexcept = default;
-        constexpr ~_iterator() = default;
-        constexpr _iterator& operator=(const _iterator& iter) noexcept = default;
-        constexpr _iterator& operator=(_iterator&& iter) noexcept = default;
-        constexpr bool operator==(const _iterator& iter) const noexcept = default;
-
-        constexpr reference operator*() const noexcept
-        { return ((node*)p)->value; }
-        constexpr pointer operator&() const noexcept
-        { return std::addressof(this->operator*()); }
-        constexpr pointer operator->() const noexcept
-        { return this->operator&(); }
-        constexpr _iterator& operator++() noexcept
-        { p = p->next; return *this; }
-        constexpr _iterator operator++(int) noexcept
-        { _iterator ret(p); (void)this->operator++(); return ret; }
-        constexpr _iterator& operator--(void) noexcept
-        { p = p->prev; return *this; }
-        constexpr _iterator operator--(int) noexcept
-        { _iterator ret(p); (void)this->operator--(); return ret; }
-        constexpr operator bool() const { return p; }
-        constexpr operator _iterator<true>() const { return _iterator<true> { p }; }
-    };
-
-private:
-    node_base m_head;
-    impl::compressed_pair<size_type, node_alloc_type> m_pair;
-
-private:
-    // move m_head and m_size of other to *this
-    // other MUST NOT be empty, *this MUST be empty
-    constexpr void _move_from(list&& other) noexcept
-    {
-        std::swap(_size(), other._size());
-        other.m_head.prev->connect(&m_head);
-        m_head.connect(other.m_head.next);
-        other.m_head.next = other.m_head.prev = &other.m_head;
-    }
-
-    constexpr size_type& _size() noexcept { return m_pair.first(); }
-    constexpr const size_type& _size() const noexcept { return m_pair.first(); }
-
-    constexpr node_alloc_type& _alloc() noexcept { return m_pair.second(); }
-    constexpr const node_alloc_type& _alloc() const noexcept { return m_pair.second(); }
-
-public:
-    __GBLIBCPP_CONSTEXPR
-    iterator end(void) noexcept { return iterator { &m_head }; }
-    __GBLIBCPP_CONSTEXPR
-    const_iterator cend(void) const noexcept { return const_iterator { &m_head }; }
-    __GBLIBCPP_CONSTEXPR
-    const_iterator end(void) const noexcept { return cend(); }
-
-    __GBLIBCPP_CONSTEXPR
-    iterator begin(void) noexcept { return iterator { m_head.next }; }
-    __GBLIBCPP_CONSTEXPR
-    const_iterator cbegin(void) const noexcept
-    { return const_iterator { m_head.next }; }
-    __GBLIBCPP_CONSTEXPR
-    const_iterator begin(void) const noexcept { return cbegin(); }
-
-    template <typename... Args>
-    __GBLIBCPP_CONSTEXPR
-    iterator emplace(const_iterator pos, Args&&... args)
-    {
-        node* nd = node_alloc_traits::allocate(_alloc(), 1);
-        node_alloc_traits::construct(_alloc(), nd, std::forward<Args>(args)...);
-
-        nd->next = pos.p;
-        nd->prev = pos.p->prev;
-        nd->next->prev = nd;
-        nd->prev->next = nd;
-
-        ++_size();
-        return iterator { nd };
-    }
-
-    explicit __GBLIBCPP_CONSTEXPR
-    list(const Allocator& alloc): m_head{}, m_pair{0, alloc} { }
-
-    __GBLIBCPP_CONSTEXPR
-    list(): list(Allocator()) {}
-
-    __GBLIBCPP_CONSTEXPR
-    explicit list(size_type count, const Allocator& alloc = Allocator()): list(alloc)
-    {
-        while (count--)
-            emplace_back();
-    }
-
-    __GBLIBCPP_CONSTEXPR
-    list(size_type count, const T& value, const Allocator& alloc = Allocator()): list(alloc)
-    {
-        while (count--)
-            emplace_back(value);
-    }
-
-    template <typename InputIter>
-    __GBLIBCPP_CONSTEXPR
-    list(InputIter first, InputIter last, const Allocator& alloc = Allocator())
-        : list(alloc) { insert(first, last); }
-
-    __GBLIBCPP_CONSTEXPR
-    list(const list& other, const Allocator& alloc): list(alloc)
-    {
-        // TODO: select_on_container_copy_construction
-        for (const auto& item : other)
-            emplace_back(item);
-    }
-    __GBLIBCPP_CONSTEXPR
-    list(const list& other): list(other,
-            alloc_traits::select_on_container_copy_construction(_alloc())) { }
-
-    __GBLIBCPP_CONSTEXPR
-    list(list&& other): m_head{}, m_pair{0, std::move(other._alloc())}
-    {
-        if (other.empty())
-            return;
-        _move_from(std::move(other));
-    }
-
-    __GBLIBCPP_CONSTEXPR
-    list(list&& other, const Allocator& alloc): m_head{}, m_pair{0, alloc}
-    {
-        if (other._alloc() != alloc) {
-            for (auto iter = other.begin(); iter != other.end(); ++iter)
-                emplace(cend(), std::move(*iter));
-            other.clear();
-            return;
-        }
-        // other._alloc() == alloc
-        if (other.empty())
-            return;
-
-        _move_from(std::move(other));
-    }
-
-    __GBLIBCPP_CONSTEXPR
-    list(std::initializer_list<T> ilist,
-        const Allocator& alloc = Allocator())
-        : list(alloc)
-    {
-        for (const auto& item : ilist)
-            emplace_back(item);
-    }
-
-    __GBLIBCPP_CONSTEXPR
-    ~list()
-    {
-        clear();
-        m_head.next = m_head.prev = nullptr;
-    }
-
-    __GBLIBCPP_CONSTEXPR
-    list& operator=(const list& other)
-    {
-        // TODO: reuse memory if _alloc() == other._alloc()
-        clear();
-
-        if constexpr (alloc_traits::
-            propagate_on_container_copy_assignment::value)
-            _alloc() = other._alloc();
-
-        for (const auto& item : other)
-            emplace_back(item);
-
-        return *this;
-    }
-    __GBLIBCPP_CONSTEXPR
-    list& operator=(list&& other)
-    {
-        if (alloc_traits::
-            propagate_on_container_move_assignment::value) {
-            clear();
-            _alloc() = std::move(other._alloc());
-
-            if (other.empty())
-                return *this;
-
-            _move_from(std::move(other));
-            return *this;
-        }
-
-        // TODO: reuse memory if _alloc() == other._alloc()
-        clear();
-
-        if (_alloc() != other._alloc()) {
-            for (auto iter = other.begin(); iter != other.end(); ++iter)
-                emplace(cend(), std::move(*iter));
-            other.clear();
-            return *this;
-        }
-
-        _move_from(std::move(other));
-        return *this;
-    }
-
-    __GBLIBCPP_CONSTEXPR
-    list& operator=(std::initializer_list<T> ilist)
-    {
-        // TODO: reuse memory
-        clear();
-        for (const auto& item : ilist)
-            emplace_back(item);
-        return *this;
-    }
-
-    __GBLIBCPP_CONSTEXPR
-    void assign(size_type count, const T& value)
-    {
-        clear();
-        while (count--)
-            emplace_back(value);
-    }
-
-    template <typename InputIter>
-    __GBLIBCPP_CONSTEXPR
-    void assign(InputIter first, InputIter last)
-    {
-        clear();
-        insert(first, last);
-    }
-
-    __GBLIBCPP_CONSTEXPR
-    void assign(std::initializer_list<T> ilist)
-    {
-        clear();
-        for (const auto& item : ilist)
-            emplace_back(item);
-    }
-
-    __GBLIBCPP_CONSTEXPR
-    allocator_type get_allocator() const noexcept { return _alloc(); }
-
-    __GBLIBCPP_CONSTEXPR
-    reference front() { return *begin(); }
-    __GBLIBCPP_CONSTEXPR
-    const_reference front() const { return *cbegin(); }
-
-    __GBLIBCPP_CONSTEXPR
-    reference back() { return *--end(); }
-    __GBLIBCPP_CONSTEXPR
-    const_reference back() const { return *--cend(); }
-
-    __GBLIBCPP_CONSTEXPR
-    iterator insert(const_iterator pos, const T& value)
-    { return emplace(pos, value); }
-    __GBLIBCPP_CONSTEXPR
-    iterator insert(const_iterator pos, T&& value)
-    { return emplace(pos, std::move(value)); }
-
-    __GBLIBCPP_CONSTEXPR
-    iterator insert(const_iterator pos, size_type count, const T& value)
-    {
-        if (!(count--))
-            return pos;
-        auto ret = insert(pos, value);
-        while (count--)
-            insert(pos, value);
-        return ret;
-    }
-
-    template <typename InputIter>
-    __GBLIBCPP_CONSTEXPR
-    void insert(InputIter first, InputIter last)
-    {
-        for ( ; first != last; ++first)
-            emplace_back(*first);
-    }
-
-    template <typename... Args>
-    __GBLIBCPP_CONSTEXPR
-    reference emplace_back(Args&&... args)
-    { return *emplace(end(), std::forward<Args>(args)...); }
-
-    template <typename... Args>
-    __GBLIBCPP_CONSTEXPR
-    reference emplace_front(Args&&... args)
-    { return *emplace(begin(), std::forward<Args>(args)...); }
-
-    __GBLIBCPP_CONSTEXPR
-    void push_back(const T& value)
-    { emplace_back(value); }
-    __GBLIBCPP_CONSTEXPR
-    void push_back(T&& value)
-    { emplace_back(std::move(value)); }
-
-    __GBLIBCPP_CONSTEXPR
-    void push_front(const T& value)
-    { emplace_front(value); }
-    __GBLIBCPP_CONSTEXPR
-    void push_front(T&& value)
-    { emplace_front(std::move(value)); }
-
-    __GBLIBCPP_CONSTEXPR
-    void pop_back() { erase(--end()); }
-    __GBLIBCPP_CONSTEXPR
-    void pop_front() { erase(begin()); }
-
-    __GBLIBCPP_CONSTEXPR
-    iterator erase(const_iterator pos) noexcept
-    {
-        iterator ret { pos.p->next };
-
-        pos.p->next->prev = pos.p->prev;
-        pos.p->prev->next = pos.p->next;
-
-        node_alloc_traits::destroy(_alloc(), (node*)pos.p);
-        node_alloc_traits::deallocate(_alloc(), (node*)pos.p, 1);
-
-        --_size();
-        return ret;
-    }
-
-    __GBLIBCPP_CONSTEXPR
-    iterator erase(const_iterator first, const_iterator last) noexcept
-    {
-        while (first != last)
-            first = erase(first);
-        return first;
-    }
-
-    __GBLIBCPP_CONSTEXPR
-    void clear() noexcept
-    {
-        for (auto iter = begin(); iter != end(); )
-            iter = erase(iter);
-    }
-
-    __GBLIBCPP_CONSTEXPR
-    size_type size() const noexcept { return _size(); }
-
-    __GBLIBCPP_CONSTEXPR
-    bool empty() const noexcept { return size() == 0; }
-
-    __GBLIBCPP_CONSTEXPR
-    void swap(list& other)
-    {
-        if constexpr (alloc_traits::propagate_on_container_swap::value)
-            std::swap(_alloc(), other._alloc());
-
-        std::swap(_size(), other.m_size);
-        std::swap(m_head, other.m_head);
-        std::swap(m_head.next->prev, other.m_head.next->prev);
-        std::swap(m_head.prev->next, other.m_head.prev->next);
-    }
-
-    __GBLIBCPP_CONSTEXPR
-    void resize(size_type count)
-    {
-        while (count > size())
-            emplace_back();
-        while (count < size())
-            pop_back();
-    }
-
-    __GBLIBCPP_CONSTEXPR
-    void resize(size_type count, const value_type& value)
-    {
-        while (count > size())
-            emplace_back(value);
-        while (count < size())
-            pop_back();
-    }
-
-    __GBLIBCPP_CONSTEXPR
-    size_type remove(const T& value)
-    {
-        size_type retval = 0;
-        for (auto iter = begin(); iter != end(); ) {
-            if (value != *iter) {
-                ++iter;
-                continue;
-            }
-            ++retval;
-            iter = erase(iter);
-        }
-        return retval;
-    }
-
-    template <typename UnaryPredicate>
-    __GBLIBCPP_CONSTEXPR
-    size_type remove_if(UnaryPredicate p)
-    {
-        size_type retval = 0;
-        for (auto iter = begin(); iter != end(); ) {
-            if (!p(*iter)) {
-                ++iter;
-                continue;
-            }
-            ++retval;
-            iter = erase(iter);
-        }
-        return retval;
-    }
-};
-
-template <typename T, typename Allocator>
-void swap(std::list<T, Allocator>& lhs,
-    std::list<T, Allocator>& rhs) { lhs.swap(rhs); }
-
-template <typename T, typename Allocator, typename U>
-typename std::list<T, Allocator>::size_type
-    erase(std::list<T, Allocator>& l, const U& value)
-{
-    return l.remove_if([&](auto& elem) { return elem == value; });
-}
-
-template <typename T, typename Allocator, typename Predicate>
-typename std::list<T, Allocator>::size_type
-    erase_if(std::list<T, Allocator>& l, Predicate p)
-{ return l.remove_if(p); }
-
-} // namespace std
-
-#endif

+ 0 - 309
gblibstdc++/include/map

@@ -1,309 +0,0 @@
-#ifndef __GBLIBCPP_MAP__
-#define __GBLIBCPP_MAP__
-
-#include <bits/iter_ops>
-
-#include <bits/rbtree>
-#include <functional>
-#include <memory>
-#include <initializer_list>
-#include <tuple>
-#include <type_traits>
-#include <utility>
-#include <cstddef>
-
-namespace std {
-
-template <typename Key, typename T,
-    typename Compare = std::less<Key>,
-    typename Allocator = std::allocator<std::pair<const Key, T>>>
-class map {
-public:
-    using key_type = Key;
-    using mapped_type = T;
-    using value_type = std::pair<const Key, T>;
-    using size_type = std::size_t;
-    using allocator_type = Allocator;
-
-private:
-    class value_compare : public Compare {
-    protected:
-        constexpr value_compare(Compare c): Compare{c} {}
-
-        friend class map;
-
-    public:
-        constexpr bool operator()(
-            const value_type& lhs, const value_type& rhs) const
-        { return Compare::operator()(lhs.first, rhs.first); }
-
-        constexpr bool operator()(
-            const Key& lhs, const value_type& rhs) const
-        { return Compare::operator()(lhs, rhs.first); }
-
-        constexpr bool operator()(
-            const value_type& lhs, const Key& rhs) const
-        { return Compare::operator()(lhs.first, rhs); }
-    };
-
-    using rbtree_type = impl::rbtree<value_type, value_compare, Allocator>;
-    using node_allocator = typename rbtree_type::node_allocator;
-
-private:
-    rbtree_type tree;
-
-public:
-    using iterator = typename rbtree_type::iterator;
-    using const_iterator = typename rbtree_type::const_iterator;
-
-public:
-    __GBLIBCPP_CONSTEXPR
-    iterator end(void) noexcept { return tree.end(); }
-    __GBLIBCPP_CONSTEXPR
-    const_iterator end(void) const noexcept { return tree.cend(); }
-    __GBLIBCPP_CONSTEXPR
-    const_iterator cend(void) const noexcept { return tree.cend(); }
-
-    __GBLIBCPP_CONSTEXPR
-    iterator begin(void) noexcept { return tree.begin(); }
-    __GBLIBCPP_CONSTEXPR
-    const_iterator begin(void) const noexcept { return tree.cbegin(); }
-    __GBLIBCPP_CONSTEXPR
-    const_iterator cbegin(void) const noexcept { return tree.cbegin(); }
-
-    explicit __GBLIBCPP_CONSTEXPR
-    map(const Compare& comp,
-        const Allocator& alloc = Allocator())
-        : tree(comp, alloc) {}
-
-    explicit __GBLIBCPP_CONSTEXPR
-    map(const Allocator& alloc)
-        : map(Compare(), alloc) {}
-
-    __GBLIBCPP_CONSTEXPR
-    map() : map(Compare()) {}
-
-    template <typename InputIter>
-    __GBLIBCPP_CONSTEXPR
-    map(InputIter first, InputIter last,
-        const Compare& comp = Compare(),
-        const Allocator& alloc = Allocator())
-        : map(comp, alloc)
-    {
-        insert(first, last);
-    }
-
-    template <typename InputIter>
-    __GBLIBCPP_CONSTEXPR
-    map(InputIter first, InputIter last,
-        const Allocator& alloc = Allocator())
-        : map(first, last, Compare(), alloc) {}
-
-    __GBLIBCPP_CONSTEXPR
-    map(const map& other) : tree(other.tree) {}
-    __GBLIBCPP_CONSTEXPR
-    map(const map& other, const Allocator& alloc)
-        : tree(other.tree, alloc) { }
-
-    __GBLIBCPP_CONSTEXPR
-    map(map&& other) : tree(std::move(other.tree)) {}
-    __GBLIBCPP_CONSTEXPR
-    map(map&& other, const Allocator& alloc)
-        : tree(std::move(other.tree), alloc) {}
-
-    __GBLIBCPP_CONSTEXPR
-    map(std::initializer_list<value_type> init,
-        const Compare& comp = Compare(),
-        const Allocator& alloc = Allocator())
-        : map(comp, alloc)
-    { insert(init.begin(), init.end()); }
-
-    __GBLIBCPP_CONSTEXPR
-    map(std::initializer_list<value_type> init,
-        const Allocator& alloc)
-        : map(init, Compare(), alloc) {}
-
-    __GBLIBCPP_CONSTEXPR
-    ~map() { clear(); }
-
-    __GBLIBCPP_CONSTEXPR
-    map& operator=(const map& other) = default;
-    __GBLIBCPP_CONSTEXPR
-    map& operator=(map&& other) = default;
-    __GBLIBCPP_CONSTEXPR
-    map& operator=(std::initializer_list<value_type> ilist)
-    {
-        clear();
-        insert(ilist.begin(), ilist.end());
-        return *this;
-    }
-
-    __GBLIBCPP_CONSTEXPR
-    iterator find(const Key& key) { return tree.find(key); }
-    __GBLIBCPP_CONSTEXPR
-    const_iterator find(const Key& key) const { return tree.find(key); }
-
-    // if the container does not have an element with
-    // the specified key, it should throw an exception
-    // TODO: exceptions
-    __GBLIBCPP_CONSTEXPR
-    T& at(const Key& key) { return find(key)->second; }
-
-    // if the container does not have an element with
-    // the specified key, it should throw an exception
-    // TODO: exceptions
-    __GBLIBCPP_CONSTEXPR
-    const T& at(const Key& key) const { return find(key)->second; }
-
-    __GBLIBCPP_CONSTEXPR
-    std::pair<iterator, bool> insert(const value_type& value)
-    { return tree.insert(value); }
-    __GBLIBCPP_CONSTEXPR
-    std::pair<iterator, bool> insert(value_type&& value)
-    { return tree.insert(std::move(value)); }
-
-    template <typename Pair>
-    __GBLIBCPP_CONSTEXPR
-    std::enable_if_t<std::is_constructible_v<value_type, Pair&&>,
-        std::pair<iterator, bool>> insert(Pair&& p)
-    { return emplace(std::forward<Pair>(p)); }
-
-    template <typename InputIter>
-    __GBLIBCPP_CONSTEXPR
-    void insert(InputIter first, InputIter last)
-    {
-        for ( ; first != last; ++first)
-            insert(*first);
-    }
-
-    template <typename... Args>
-    __GBLIBCPP_CONSTEXPR
-    std::pair<iterator, bool> emplace(Args&&... args)
-    { return tree.emplace(std::forward<Args>(args)...); }
-
-    template <typename... Args>
-    __GBLIBCPP_CONSTEXPR
-    std::pair<iterator, bool> try_emplace(const Key& key, Args&&... args)
-    {
-        auto iter = find(key);
-        if (iter)
-            return { iter, false };
-        return emplace(
-            std::piecewise_construct,
-            std::forward_as_tuple(key),
-            std::forward_as_tuple(std::forward<Args>(args)...));
-    }
-
-    template <typename... Args>
-    __GBLIBCPP_CONSTEXPR
-    std::pair<iterator, bool> try_emplace(Key&& key, Args&&... args)
-    {
-        auto iter = find(key);
-        if (iter)
-            return { iter, false };
-        return emplace(
-            std::piecewise_construct,
-            std::forward_as_tuple(std::move(key)),
-            std::forward_as_tuple(std::forward<Args>(args)...));
-    }
-
-    __GBLIBCPP_CONSTEXPR
-    T& operator[](const Key& key)
-    { return try_emplace(key).first->second; }
-
-    __GBLIBCPP_CONSTEXPR
-    T& operator[](Key&& key)
-    { return try_emplace(std::move(key)).first->second; }
-
-    __GBLIBCPP_CONSTEXPR
-    iterator erase(iterator pos) noexcept { return tree.erase(pos); }
-    __GBLIBCPP_CONSTEXPR
-    iterator erase(const_iterator pos) noexcept { return tree.erase(pos); }
-    __GBLIBCPP_CONSTEXPR
-    iterator erase(const_iterator first, const_iterator last) noexcept
-    {
-        while (first != last)
-            first = erase(first);
-        return first;
-    }
-
-    __GBLIBCPP_CONSTEXPR
-    size_type erase(const Key& key)
-    {
-        auto iter = find(key);
-        if (!iter)
-            return 0;
-        erase(iter);
-        return 1;
-    }
-
-    __GBLIBCPP_CONSTEXPR
-    void clear() noexcept { tree.destroy(); }
-
-    __GBLIBCPP_CONSTEXPR
-    bool empty() const noexcept { return tree.empty(); }
-
-    __GBLIBCPP_CONSTEXPR
-    size_type size() const noexcept { return tree.size(); }
-
-    __GBLIBCPP_CONSTEXPR
-    void swap(map& other) { tree.swap(other.tree); }
-
-    __GBLIBCPP_CONSTEXPR
-    size_type count(const Key& key) const
-    { return find(key) ? 1 : 0; }
-
-    __GBLIBCPP_CONSTEXPR
-    bool contains(const Key& key) const { return count(key) != 0; }
-
-    __GBLIBCPP_CONSTEXPR
-    iterator upper_bound(const Key& key)
-    { return tree.upper_bound(key); }
-    __GBLIBCPP_CONSTEXPR
-    const_iterator upper_bound(const Key& key) const
-    { return tree.upper_bound(key); }
-
-    __GBLIBCPP_CONSTEXPR
-    iterator lower_bound(const Key& key)
-    { return tree.lower_bound(key); }
-    __GBLIBCPP_CONSTEXPR
-    const_iterator lower_bound(const Key& key) const
-    { return tree.lower_bound(key); }
-};
-
-template <typename Key, typename T, typename Compare, typename Allocator>
-void swap(std::map<Key, T, Compare, Allocator>& lhs,
-    std::map<Key, T, Compare, Allocator>& rhs)
-{ lhs.swap(rhs); }
-
-template <typename Key, typename T,
-    typename Compare, typename Allocator, typename Pred>
-typename std::map<Key, T, Compare, Allocator>::size_type
-erase_if(std::map<Key, T, Compare, Allocator>& c, Pred pred)
-{
-    auto iter = c.begin();
-    typename std::map<Key, T, Compare, Allocator>::size_type count = 0;
-    while (iter != c.end()) {
-        if (pred(*iter)) {
-            iter = c.erase(iter);
-            ++count;
-        } else
-            ++iter;
-    }
-    return count;
-}
-
-template <typename Key, typename T,
-    typename Compare = std::less<Key>,
-    typename Allocator = std::allocator<std::pair<const Key, T>>>
-map(std::initializer_list<std::pair<Key, T>>,
-    Compare = Compare(), Allocator = Allocator())
-    -> map<Key, T, Compare, Allocator>;
-
-template <typename Key, typename T, typename Allocator>
-map(std::initializer_list<std::pair<Key, T>>, Allocator)
-    -> map<Key, T, std::less<Key>, Allocator>;
-
-} // namespace std
-
-#endif

+ 0 - 740
gblibstdc++/include/memory

@@ -1,740 +0,0 @@
-#ifndef __GBLIBCPP_MEMORY__
-#define __GBLIBCPP_MEMORY__
-
-#include <bits/compressed_pair>
-#include <cstddef>
-#include <new>
-#include <type_traits>
-#include <utility>
-
-namespace std {
-
-template <typename T>
-constexpr T* addressof(T& arg) noexcept {
-    return __builtin_addressof(arg);
-}
-
-// template <typename T>
-// constexpr enable_if_t<is_function_v<remove_reference_t<T>>, T*>
-// addressof(T& arg) noexcept
-// {
-//     return &arg;
-// }
-
-// template <typename T>
-// constexpr enable_if_t<!is_function_v<remove_reference_t<T>>, T*>
-// addressof(T& arg) noexcept
-// {
-//     return reinterpret_cast<T*>(
-//         &const_cast<char&>(
-//             reinterpret_cast<const volatile char&>(arg)
-//         )
-//     );
-// }
-
-template <typename T>
-const T* addressof(const T&&) = delete;
-
-namespace __helpers {
-
-    template <typename Ptr, typename = void>
-    struct pointer_difference_type {
-        using type = std::ptrdiff_t;
-    };
-
-    template <typename Ptr>
-    struct pointer_difference_type<Ptr,
-                                   std::void_t<typename Ptr::difference_type>> {
-        using type = typename Ptr::difference_type;
-    };
-
-    template <typename Ptr>
-    using pointer_difference_type_t =
-        typename pointer_difference_type<Ptr>::type;
-
-    template <typename Base, typename T>
-    struct rebind;
-
-    template <template <typename, typename...> typename Template,
-              typename NewType, typename OldType, typename... Args>
-    struct rebind<Template<OldType, Args...>, NewType> {
-        using type = Template<NewType, Args...>;
-    };
-
-    template <typename Ptr, typename T, typename = void>
-    struct try_rebind {
-        using type = typename rebind<Ptr, T>::type;
-    };
-
-    template <typename Ptr, typename T>
-    struct try_rebind<Ptr, T, std::void_t<typename Ptr::template rebind<T>>> {
-        using type = typename Ptr::template rebind<T>;
-    };
-
-    template <typename Ptr, typename = void>
-    struct pointer_element {};
-
-    template <typename Ptr>
-    struct pointer_element<
-        Ptr, std::enable_if_t<std::is_same_v<
-                 void, std::void_t<typename Ptr::element_type>>>> {
-        using type = typename Ptr::element_type;
-    };
-
-    template <template <typename, typename...> typename Template, typename T,
-              typename... Args>
-    struct pointer_element<Template<T, Args...>, void> {
-        using type = T;
-    };
-
-    template <typename Ptr, typename = void>
-    struct pointer_traits_impl {};
-
-    template <typename Ptr>
-    struct pointer_traits_impl<
-        Ptr, std::void_t<typename pointer_element<Ptr>::type>> {
-        using pointer = Ptr;
-        using element_type = typename pointer_element<Ptr>::type;
-        using difference_type = pointer_difference_type_t<Ptr>;
-
-        template <typename U>
-        using rebind = typename try_rebind<Ptr, U>::type;
-
-        static pointer pointer_to(element_type& ref) {
-            return Ptr::pointer_to(ref);
-        }
-    };
-
-    template <typename T>
-    struct pointer_traits_impl<T*, void> {
-        using pointer = T*;
-        using element_type = T;
-        using difference_type = std::ptrdiff_t;
-
-        template <typename U>
-        using rebind = U*;
-
-        static pointer pointer_to(element_type& ref) {
-            return std::addressof(ref);
-        }
-    };
-
-} // namespace __helpers
-
-template <typename Ptr>
-struct pointer_traits : public __helpers::pointer_traits_impl<Ptr> {};
-
-namespace __helpers {
-
-    template <typename Alloc, typename = void>
-    struct allocator_pointer {
-        using type = typename Alloc::value_type*;
-    };
-
-    template <typename Alloc>
-    struct allocator_pointer<Alloc, std::void_t<typename Alloc::pointer>> {
-        using type = typename Alloc::pointer;
-    };
-
-    template <typename Alloc>
-    using allocator_pointer_t = typename allocator_pointer<Alloc>::type;
-
-    template <typename Alloc, typename Pointer, typename = void>
-    struct allocator_const_pointer {
-        using type = typename std::pointer_traits<Pointer>::template rebind<
-            const typename Alloc::value_type>;
-    };
-
-    template <typename Alloc, typename Pointer>
-    struct allocator_const_pointer<Alloc, Pointer,
-                                   std::void_t<typename Alloc::const_pointer>> {
-        using type = typename Alloc::const_pointer;
-    };
-
-    template <typename Alloc, typename Pointer>
-    using allocator_const_pointer_t =
-        typename allocator_const_pointer<Alloc, Pointer>::type;
-
-    template <typename Alloc, typename Pointer, typename = void>
-    struct allocator_void_pointer {
-        using type =
-            typename std::pointer_traits<Pointer>::template rebind<void>;
-    };
-
-    template <typename Alloc, typename Pointer>
-    struct allocator_void_pointer<Alloc, Pointer,
-                                  std::void_t<typename Alloc::void_pointer>> {
-        using type = typename Alloc::void_pointer;
-    };
-
-    template <typename Alloc, typename Pointer>
-    using allocator_void_pointer_t =
-        typename allocator_void_pointer<Alloc, Pointer>::type;
-
-    template <typename Alloc, typename Pointer, typename = void>
-    struct allocator_const_void_pointer {
-        using type =
-            typename std::pointer_traits<Pointer>::template rebind<const void>;
-    };
-
-    template <typename Alloc, typename Pointer>
-    struct allocator_const_void_pointer<
-        Alloc, Pointer, std::void_t<typename Alloc::const_void_pointer>> {
-        using type = typename Alloc::const_void_pointer;
-    };
-
-    template <typename Alloc, typename Pointer>
-    using allocator_const_void_pointer_t =
-        typename allocator_const_void_pointer<Alloc, Pointer>::type;
-
-    template <typename Alloc, typename = void>
-    struct allocator_difference_type {
-        using type = std::ptrdiff_t;
-    };
-    template <typename Alloc>
-    struct allocator_difference_type<
-        Alloc, std::void_t<typename Alloc::difference_type>> {
-        using type = typename Alloc::difference_type;
-    };
-    template <typename Alloc>
-    using allocator_difference_type_t =
-        typename allocator_difference_type<Alloc>::type;
-
-    template <typename Alloc, typename = void>
-    struct allocator_size_type {
-        using type = std::size_t;
-    };
-    template <typename Alloc>
-    struct allocator_size_type<Alloc, std::void_t<typename Alloc::size_type>> {
-        using type = typename Alloc::size_type;
-    };
-    template <typename Alloc>
-    using allocator_size_type_t = typename allocator_size_type<Alloc>::type;
-
-    template <typename Alloc, typename = void>
-    struct allocator_prop_copy {
-        using type = std::false_type;
-    };
-    template <typename Alloc>
-    struct allocator_prop_copy<
-        Alloc,
-        std::void_t<typename Alloc::propagate_on_container_copy_assignment>> {
-        using type = typename Alloc::propagate_on_container_copy_assignment;
-    };
-    template <typename Alloc>
-    using allocator_prop_copy_t = typename allocator_prop_copy<Alloc>::type;
-
-    template <typename Alloc, typename = void>
-    struct allocator_prop_move {
-        using type = std::false_type;
-    };
-    template <typename Alloc>
-    struct allocator_prop_move<
-        Alloc,
-        std::void_t<typename Alloc::propagate_on_container_move_assignment>> {
-        using type = typename Alloc::propagate_on_container_move_assignment;
-    };
-    template <typename Alloc>
-    using allocator_prop_move_t = typename allocator_prop_move<Alloc>::type;
-
-    template <typename Alloc, typename = void>
-    struct allocator_prop_swap {
-        using type = std::false_type;
-    };
-    template <typename Alloc>
-    struct allocator_prop_swap<
-        Alloc, std::void_t<typename Alloc::propagate_on_container_swap>> {
-        using type = typename Alloc::propagate_on_container_swap;
-    };
-    template <typename Alloc>
-    using allocator_prop_swap_t = typename allocator_prop_swap<Alloc>::type;
-
-    template <typename Alloc, typename = void>
-    struct is_always_equal {
-        using type = std::false_type;
-    };
-    template <typename Alloc>
-    struct is_always_equal<Alloc,
-                           std::void_t<typename Alloc::is_always_equal>> {
-        using type = typename Alloc::is_always_equal;
-    };
-    template <typename Alloc>
-    using is_always_equal_t = typename is_always_equal<Alloc>::type;
-
-    template <typename Alloc, typename = void>
-    struct allocator_select_on_copy {
-        static constexpr Alloc get(const Alloc& alloc) { return alloc; }
-    };
-
-    template <typename Alloc>
-    struct allocator_select_on_copy<
-        Alloc,
-        std::enable_if_t<std::is_same_v<
-            void,
-            std::void_t<
-                decltype(std::declval<Alloc>()
-                             .select_on_container_copy_construction())>>>> {
-        static constexpr Alloc get(const Alloc& alloc) {
-            return alloc.select_on_container_copy_construction();
-        }
-    };
-
-    template <typename Allocator, typename T, typename = void>
-    struct allocator_rebind_type {
-        using type = typename rebind<Allocator, T>::type;
-    };
-
-    template <typename Allocator, typename T>
-    struct allocator_rebind_type<
-        Allocator, T,
-        std::void_t<typename Allocator::template rebind<T>::other>> {
-        using type = typename Allocator::template rebind<T>::other;
-    };
-
-} // namespace __helpers
-
-template <typename T>
-struct allocator {
-    using value_type = T;
-    using propagate_on_container_move_assignment = std::true_type;
-
-    constexpr allocator() noexcept = default;
-    constexpr allocator(const allocator& other) noexcept = default;
-
-    template <typename U>
-    constexpr allocator(const allocator<U>&) noexcept {}
-
-    constexpr ~allocator() = default;
-
-    // throws std::bad_alloc
-    [[nodiscard]] constexpr T* allocate(std::size_t n) {
-        return static_cast<T*>(::operator new(n * sizeof(T)));
-    }
-
-    // TODO: check allocated size
-    constexpr void deallocate(T* ptr, std::size_t) { ::operator delete(ptr); }
-};
-
-template <typename T1, typename T2>
-constexpr bool operator==(const allocator<T1>&, const allocator<T2>&) noexcept {
-    return true;
-}
-
-template <typename T, typename... Args>
-constexpr std::enable_if_t<
-    std::is_same_v<T*, decltype(::new(std::declval<void*>())
-                                    T(std::declval<Args>()...))>,
-    T*>
-construct_at(T* p, Args&&... args) {
-    return ::new (static_cast<void*>(p)) T(std::forward<Args>(args)...);
-}
-
-template <typename T>
-constexpr void destroy_at(T* p) {
-    // TODO: destroy array
-    p->~T();
-}
-
-template <typename Allocator>
-struct allocator_traits {
-    using allocator_type = Allocator;
-    using value_type = typename Allocator::value_type;
-    using pointer = __helpers::allocator_pointer_t<Allocator>;
-    using const_pointer =
-        __helpers::allocator_const_pointer_t<Allocator, pointer>;
-    using void_pointer =
-        __helpers::allocator_void_pointer_t<Allocator, pointer>;
-    using const_void_pointer =
-        __helpers::allocator_const_void_pointer_t<Allocator, pointer>;
-    using difference_type = __helpers::allocator_difference_type_t<Allocator>;
-    using size_type = __helpers::allocator_size_type_t<Allocator>;
-    using propagate_on_container_copy_assignment =
-        __helpers::allocator_prop_copy_t<Allocator>;
-    using propagate_on_container_move_assignment =
-        __helpers::allocator_prop_move_t<Allocator>;
-    using propagate_on_container_swap =
-        __helpers::allocator_prop_swap_t<Allocator>;
-    using is_always_equal = __helpers::is_always_equal_t<Allocator>;
-
-    template <typename T>
-    using rebind_alloc =
-        typename __helpers::allocator_rebind_type<Allocator, T>::type;
-
-    [[nodiscard]] static constexpr pointer allocate(Allocator& alloc,
-                                                    size_type n) {
-        return alloc.allocate(n);
-    }
-    static constexpr void deallocate(Allocator& alloc, pointer p, size_type n) {
-        return alloc.deallocate(p, n);
-    }
-    template <typename T, typename... Args>
-    static constexpr void construct(Allocator&, T* p, Args&&... args) {
-        std::construct_at(p, std::forward<Args>(args)...);
-    }
-    template <typename T>
-    static constexpr void destroy(Allocator&, T* p) {
-        std::destroy_at(p);
-    }
-
-    static constexpr Allocator select_on_container_copy_construction(
-        const Allocator& alloc) {
-        return __helpers::allocator_select_on_copy<Allocator>::get(alloc);
-    }
-};
-
-template <typename T>
-struct default_delete {
-    __GBLIBCPP_CONSTEXPR default_delete() noexcept = default;
-
-    template <typename U,
-              std::enable_if_t<std::is_convertible_v<U*, T*>, bool> = true>
-    __GBLIBCPP_CONSTEXPR default_delete(const default_delete<U>&) noexcept {}
-
-    __GBLIBCPP_CONSTEXPR void operator()(T* p) const { delete p; }
-};
-
-// TODO: weak_ptr
-template <typename T>
-class shared_ptr {
-   public:
-    using element_type = std::remove_extent_t<T>;
-    using pointer = element_type*; // TODO: pointer_traits
-    using const_pointer = const element_type*;
-    using reference = element_type&;
-    using const_reference = const element_type&;
-
-   private:
-    struct control_block_base {
-        std::size_t ref_count;
-        std::size_t weak_count;
-        pointer ptr;
-
-        constexpr control_block_base(std::size_t ref_count,
-                                     std::size_t weak_count, pointer ptr)
-            : ref_count(ref_count), weak_count(weak_count), ptr(ptr) {}
-
-        virtual constexpr ~control_block_base() = default;
-        virtual constexpr void do_delete() = 0;
-
-        // template <typename U, std::enable_if_t<std::is_convertible_v<T*, U*>,
-        // bool> = true> constexpr operator typename
-        // shared_ptr<U>::control_block_base*() const
-        // {
-        //     return this;
-        // }
-    };
-
-    template <typename Deleter>
-    struct control_block : public virtual control_block_base, private Deleter {
-        using Base = control_block_base;
-
-        virtual constexpr ~control_block() = default;
-
-        constexpr control_block(std::size_t ref_count, std::size_t weak_count,
-                                pointer ptr)
-            : control_block_base{ref_count, weak_count, ptr}, Deleter{} {}
-
-        template <typename UDeleter>
-        constexpr control_block(std::size_t ref_count, std::size_t weak_count,
-                                pointer ptr, UDeleter&& deleter)
-            : control_block_base{ref_count, weak_count, ptr}
-            , Deleter(std::forward<UDeleter>(deleter)) {}
-
-        virtual constexpr void do_delete() override {
-            if (this->Base::ptr)
-                this->Deleter::operator()(this->Base::ptr);
-            this->Base::ptr = nullptr;
-        }
-    };
-
-    control_block_base* cb{};
-    pointer ptr{};
-
-    void inc_ref() {
-        if (cb)
-            ++cb->ref_count; // TODO: lock and atomic
-    }
-
-    void dec_ref() {
-        if (cb && --cb->ref_count == 0) {
-            cb->do_delete();
-            if (cb->weak_count == 0)
-                delete cb;
-        }
-    }
-
-   private:
-    template <typename Allocator, typename Deleter>
-    using rebound_allocator = typename std::allocator_traits<
-        Allocator>::template rebind_alloc<control_block<Deleter>>;
-
-    template <typename Allocator, typename Deleter>
-    using rebound_traits =
-        typename std::allocator_traits<rebound_allocator<Allocator, Deleter>>;
-
-    template <typename U>
-    friend class shared_ptr;
-
-   public:
-    __GBLIBCPP_CONSTEXPR shared_ptr() noexcept = default;
-    __GBLIBCPP_CONSTEXPR shared_ptr(std::nullptr_t) noexcept : shared_ptr{} {}
-
-    template <typename U, enable_if_t<is_convertible_v<U*, T*>, bool> = true>
-    __GBLIBCPP_CONSTEXPR explicit shared_ptr(U* p) // TODO: array type
-        : cb(new control_block<default_delete<T>>{1, 0, p}), ptr(p) {}
-
-    template <typename U, typename Deleter,
-              enable_if_t<is_convertible_v<U*, T*>, bool> = true>
-    __GBLIBCPP_CONSTEXPR explicit shared_ptr(U* p, Deleter d)
-        : cb(new control_block<Deleter>{1, 0, p, d}), ptr(p) {}
-
-    template <typename Deleter>
-    __GBLIBCPP_CONSTEXPR explicit shared_ptr(std::nullptr_t, Deleter d)
-        : cb(new control_block<Deleter>{1, 0, nullptr, d}) {}
-
-    template <typename U, typename Deleter, typename Alloc,
-              enable_if_t<is_convertible_v<U*, T*>, bool> = true>
-    __GBLIBCPP_CONSTEXPR explicit shared_ptr(U* p, Deleter d, Alloc alloc) {
-        cb = rebound_traits<Alloc, Deleter>::allocate(alloc, 1);
-        rebound_traits<Alloc, Deleter>::construct(alloc, cb, 1, 0, p, d);
-
-        ptr = p;
-    }
-
-    template <typename Deleter, typename Alloc>
-    __GBLIBCPP_CONSTEXPR explicit shared_ptr(std::nullptr_t, Deleter d,
-                                             Alloc alloc) {
-        cb = rebound_traits<Alloc, Deleter>::allocate(alloc, 1);
-        rebound_traits<Alloc, Deleter>::construct(alloc, cb, 1, 0, nullptr, d);
-    }
-
-    __GBLIBCPP_CONSTEXPR
-    shared_ptr(const shared_ptr& other) noexcept
-        : cb(other.cb), ptr(other.ptr) {
-        inc_ref();
-    }
-
-    __GBLIBCPP_CONSTEXPR
-    shared_ptr(shared_ptr&& other) noexcept
-        : cb(std::exchange(other.cb, nullptr))
-        , ptr(std::exchange(other.ptr, nullptr)) {}
-
-    template <typename U, enable_if_t<is_convertible_v<U*, T*>, bool> = true>
-    __GBLIBCPP_CONSTEXPR shared_ptr(const shared_ptr<U>& other) noexcept
-        : cb((control_block_base*)other.cb), ptr((T*)other.ptr) {
-        inc_ref();
-    }
-
-    template <typename U, enable_if_t<is_convertible_v<U*, T*>, bool> = true>
-    __GBLIBCPP_CONSTEXPR shared_ptr(shared_ptr<U>&& other) noexcept
-        : cb((control_block_base*)std::exchange(other.cb, nullptr))
-        , ptr((T*)std::exchange(other.ptr, nullptr)) {}
-
-    // TODO: weak_ptr and unique_ptr
-
-    __GBLIBCPP_CONSTEXPR
-    ~shared_ptr() {
-        dec_ref();
-        cb = nullptr;
-        ptr = nullptr;
-    }
-
-    __GBLIBCPP_CONSTEXPR
-    shared_ptr& operator=(const shared_ptr& other) noexcept {
-        shared_ptr{other}.swap(*this);
-        return *this;
-    }
-
-    template <typename U, enable_if_t<is_convertible_v<U*, T*>, bool> = true>
-    __GBLIBCPP_CONSTEXPR shared_ptr& operator=(
-        const shared_ptr<U>& other) noexcept {
-        shared_ptr{other}.swap(*this);
-        return *this;
-    }
-
-    __GBLIBCPP_CONSTEXPR
-    shared_ptr& operator=(shared_ptr&& other) noexcept {
-        shared_ptr{move(other)}.swap(*this);
-        return *this;
-    }
-
-    template <typename U, enable_if_t<is_convertible_v<U*, T*>, bool> = true>
-    __GBLIBCPP_CONSTEXPR shared_ptr& operator=(shared_ptr<U>&& other) noexcept {
-        shared_ptr{move(other)}.swap(*this);
-        return *this;
-    }
-
-    __GBLIBCPP_CONSTEXPR
-    element_type* get() const noexcept { return cb ? ptr : nullptr; }
-
-    __GBLIBCPP_CONSTEXPR
-    explicit operator bool() const noexcept { return get(); }
-
-    __GBLIBCPP_CONSTEXPR
-    T& operator*() const noexcept { return *get(); }
-    __GBLIBCPP_CONSTEXPR
-    T* operator->() const noexcept { return get(); }
-    __GBLIBCPP_CONSTEXPR
-    element_type& operator[](std::size_t i) const noexcept { return get()[i]; }
-
-    __GBLIBCPP_CONSTEXPR
-    long use_count() const noexcept { return cb ? cb->ref_count : 0; }
-
-    __GBLIBCPP_CONSTEXPR
-    bool owner_before(const shared_ptr& other) const noexcept {
-        return cb < other.cb;
-    }
-
-    __GBLIBCPP_CONSTEXPR
-    void swap(shared_ptr& other) noexcept {
-        std::swap(cb, other.cb);
-        std::swap(ptr, other.ptr);
-    }
-
-    __GBLIBCPP_CONSTEXPR
-    void reset() noexcept { shared_ptr{}.swap(*this); }
-
-    template <typename U, enable_if_t<is_convertible_v<U*, T*>, bool> = true>
-    __GBLIBCPP_CONSTEXPR void reset(U* p) noexcept {
-        shared_ptr{p}.swap(*this);
-    }
-
-    template <typename U, typename Deleter,
-              enable_if_t<is_convertible_v<U*, T*>, bool> = true>
-    __GBLIBCPP_CONSTEXPR void reset(U* p, Deleter d) noexcept {
-        shared_ptr{p, d}.swap(*this);
-    }
-
-    template <typename U, typename Deleter, typename Allocator,
-              enable_if_t<is_convertible_v<U*, T*>, bool> = true>
-    __GBLIBCPP_CONSTEXPR void reset(U* p, Deleter d, Allocator alloc) {
-        shared_ptr{p, d, alloc}.swap(*this);
-    }
-};
-
-template <typename T, typename Deleter = std::default_delete<T>>
-class unique_ptr {
-   public:
-    using element_type = T;
-    using deleter_type = Deleter;
-    using pointer = element_type*;
-
-    template <typename U, typename UDeleter>
-    friend class unique_ptr;
-
-   private:
-    impl::compressed_pair<pointer, deleter_type> data;
-
-   public:
-    __GBLIBCPP_CONSTEXPR unique_ptr() noexcept
-        : data{impl::default_construct_t{}} {}
-    __GBLIBCPP_CONSTEXPR unique_ptr(std::nullptr_t) noexcept : unique_ptr{} {}
-    __GBLIBCPP_CONSTEXPR unique_ptr(pointer p) noexcept
-        : data{p, deleter_type{}} {}
-    __GBLIBCPP_CONSTEXPR unique_ptr(pointer p, const deleter_type& d) noexcept
-        : data{p, d} {}
-    __GBLIBCPP_CONSTEXPR unique_ptr(pointer p, deleter_type&& d) noexcept
-        : data{p, std::move(d)} {}
-    __GBLIBCPP_CONSTEXPR unique_ptr(const unique_ptr&) = delete;
-
-    __GBLIBCPP_CONSTEXPR unique_ptr(unique_ptr&& other) noexcept
-        : data{std::exchange(other.data.first(), nullptr),
-               std::move(other.data.second())} {}
-
-    template <
-        typename U, typename E,
-        std::enable_if_t<!std::is_array_v<U> && std::is_convertible_v<U*, T*> &&
-                             std::is_convertible_v<E, Deleter>,
-                         bool> = true>
-    __GBLIBCPP_CONSTEXPR unique_ptr(unique_ptr<U, E>&& other) noexcept
-        : data{std::exchange(other.data.first(), nullptr),
-               std::move(other.data.second())} {}
-
-    __GBLIBCPP_CONSTEXPR ~unique_ptr() { reset(); }
-
-    __GBLIBCPP_CONSTEXPR unique_ptr& operator=(const unique_ptr&) = delete;
-    __GBLIBCPP_CONSTEXPR unique_ptr& operator=(std::nullptr_t) noexcept {
-        reset();
-        return *this;
-    }
-
-    __GBLIBCPP_CONSTEXPR unique_ptr& operator=(unique_ptr&& other) noexcept {
-        reset(other.release());
-        get_deleter() = std::move(other.get_deleter());
-        return *this;
-    }
-
-    template <
-        typename U, typename E,
-        std::enable_if_t<!std::is_array_v<U> && std::is_convertible_v<U*, T*> &&
-                             std::is_assignable_v<Deleter&, E&&>,
-                         bool> = true>
-    __GBLIBCPP_CONSTEXPR unique_ptr& operator=(
-        unique_ptr<U, E>&& other) noexcept {
-        reset(other.release());
-        get_deleter() = std::move(other.get_deleter());
-        return *this;
-    }
-
-    __GBLIBCPP_CONSTEXPR void swap(unique_ptr& other) noexcept {
-        std::swap(data, other.data);
-    }
-
-    __GBLIBCPP_CONSTEXPR pointer get() const noexcept { return data.first(); }
-    __GBLIBCPP_CONSTEXPR deleter_type& get_deleter() noexcept {
-        return data.second();
-    }
-    __GBLIBCPP_CONSTEXPR const deleter_type& get_deleter() const noexcept {
-        return data.second();
-    }
-
-    __GBLIBCPP_CONSTEXPR pointer release() noexcept {
-        pointer ret = get();
-        data.first() = nullptr;
-        return ret;
-    }
-
-    __GBLIBCPP_CONSTEXPR void reset(pointer p = pointer{}) noexcept {
-        pointer old = release();
-        data.first() = p;
-        if (old)
-            get_deleter()(old);
-    }
-
-    __GBLIBCPP_CONSTEXPR explicit operator bool() const noexcept {
-        return get();
-    }
-    __GBLIBCPP_CONSTEXPR pointer operator->() const noexcept { return get(); }
-
-    __GBLIBCPP_CONSTEXPR std::add_lvalue_reference_t<T> operator*() const
-        noexcept(noexcept(*std::declval<pointer>())) {
-        return *get();
-    }
-};
-
-// TODO: use only one allocation
-template <typename T, typename... Args>
-std::shared_ptr<T> make_shared(Args&&... args) {
-    return std::shared_ptr<T>(new T(std::forward<Args>(args)...));
-}
-
-template <typename T, typename... Args>
-__GBLIBCPP_CONSTEXPR std::unique_ptr<T> make_unique(Args&&... args) {
-    return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
-}
-
-template <typename T>
-__GBLIBCPP_CONSTEXPR void swap(std::shared_ptr<T>& lhs,
-                               std::shared_ptr<T>& rhs) noexcept {
-    lhs.swap(rhs);
-}
-
-template <typename T, typename D>
-__GBLIBCPP_CONSTEXPR void swap(std::unique_ptr<T, D>& lhs,
-                               std::unique_ptr<T, D>& rhs) noexcept {
-    lhs.swap(rhs);
-}
-
-} // namespace std
-
-#endif

+ 0 - 11
gblibstdc++/include/new

@@ -1,11 +0,0 @@
-#ifndef __GBLIBCPP_NEW__
-#define __GBLIBCPP_NEW__
-
-#include <cstddef>
-
-constexpr void* operator new(std::size_t, void* ptr) noexcept
-{
-    return ptr;
-}
-
-#endif

+ 0 - 150
gblibstdc++/include/queue

@@ -1,150 +0,0 @@
-#ifndef __GBLIBCPP_QUEUE__
-#define __GBLIBCPP_QUEUE__
-
-#include <vector>
-#include <functional>
-#include <memory>
-#include <algorithm>
-#include <initializer_list>
-#include <cstddef>
-
-namespace std {
-
-template <typename T,
-    typename Container = std::vector<T>,
-    typename Compare = std::less<typename Container::value_type>>
-class priority_queue {
-public:
-    using container_type = Container;
-    using value_compare = Compare;
-    using value_type = typename Container::value_type;
-    using size_type = typename Container::size_type;
-    using reference = typename Container::reference;
-    using const_reference = typename Container::const_reference;
-    using allocator_type = typename Container::allocator_type;
-
-protected:
-    container_type c;
-    value_compare comp;
-
-public:
-    __GBLIBCPP_CONSTEXPR
-    priority_queue(const Compare& comp, const Container& c)
-        : c(c), comp(comp)
-    {
-        std::make_heap(c.begin(), c.end(), comp);
-    }
-
-    __GBLIBCPP_CONSTEXPR
-    explicit priority_queue(const Compare& comp, Container&& c)
-        : c(std::move(c)), comp(comp)
-    {
-        std::make_heap(c.begin(), c.end(), comp);
-    }
-
-    __GBLIBCPP_CONSTEXPR
-    priority_queue() : priority_queue(Compare(), Container()) {}
-
-    __GBLIBCPP_CONSTEXPR
-    explicit priority_queue(const Compare& comp)
-        : priority_queue(comp, Container()) {}
-
-    template <typename InputIter>
-    __GBLIBCPP_CONSTEXPR
-    priority_queue(InputIter first, InputIter last,
-        const Compare& comp = Compare())
-        : c(first, last), comp(comp)
-    {
-        std::make_heap(c.begin(), c.end(), comp);
-    }
-
-    template <typename InputIter>
-    __GBLIBCPP_CONSTEXPR
-    priority_queue(InputIter first, InputIter last,
-        const Compare& comp, const Container& c)
-        : c(c), comp(comp)
-    {
-        c.insert(c.end(), first, last);
-        std::make_heap(c.begin(), c.end(), comp);
-    }
-
-    template <typename InputIter>
-    __GBLIBCPP_CONSTEXPR
-    priority_queue(InputIter first, InputIter last,
-        const Compare& comp, Container&& c)
-        : c(std::move(c)), comp(comp)
-    {
-        c.insert(c.end(), first, last);
-        std::make_heap(c.begin(), c.end(), comp);
-    }
-
-    __GBLIBCPP_CONSTEXPR
-    priority_queue(const priority_queue&) = default;
-    __GBLIBCPP_CONSTEXPR
-    priority_queue(priority_queue&&) = default;
-
-    __GBLIBCPP_CONSTEXPR
-    priority_queue& operator=(const priority_queue&) = default;
-    __GBLIBCPP_CONSTEXPR
-    priority_queue& operator=(priority_queue&&) = default;
-
-    [[nodiscard]]
-    __GBLIBCPP_CONSTEXPR
-    bool empty(void) const noexcept { return c.empty(); }
-    __GBLIBCPP_CONSTEXPR
-    size_type size(void) const noexcept { return c.size(); }
-    __GBLIBCPP_CONSTEXPR
-    const_reference top(void) const { return c.front(); }
-
-    __GBLIBCPP_CONSTEXPR
-    void push(const value_type& val)
-    {
-        c.push_back(val);
-        std::push_heap(c.begin(), c.end(), comp);
-    }
-    __GBLIBCPP_CONSTEXPR
-    void push(value_type&& val)
-    {
-        c.push_back(std::move(val));
-        std::push_heap(c.begin(), c.end(), comp);
-    }
-
-    template <typename... Args>
-    __GBLIBCPP_CONSTEXPR
-    void emplace(Args&&... args)
-    {
-        c.emplace_back(std::forward<Args>(args)...);
-        std::push_heap(c.begin(), c.end(), comp);
-    }
-
-    __GBLIBCPP_CONSTEXPR
-    void pop(void)
-    {
-        std::pop_heap(c.begin(), c.end(), comp);
-        c.pop_back();
-    }
-
-    __GBLIBCPP_CONSTEXPR
-    void swap(priority_queue& other) noexcept(
-        noexcept(std::swap(c, other.c)) &&
-        noexcept(std::swap(comp, other.comp)))
-    {
-        std::swap(c, other.c);
-        std::swap(comp, other.comp);
-    }
-};
-
-template <typename Compare, typename Container>
-priority_queue(Compare, Container)
-    -> priority_queue<typename Container::value_type,
-        Container, Compare>;
-
-template <typename T, typename Container, typename Compare>
-void swap(priority_queue<T, Container, Compare>& lhs,
-    priority_queue<T, Container, Compare>& rhs)
-    noexcept(noexcept(lhs.swap(rhs)))
-{ lhs.swap(rhs); }
-
-} // namespace std
-
-#endif

+ 0 - 253
gblibstdc++/include/set

@@ -1,253 +0,0 @@
-#ifndef __GBLIBCPP_SET__
-#define __GBLIBCPP_SET__
-
-#include <bits/iter_ops>
-
-#include <bits/rbtree>
-#include <functional>
-#include <initializer_list>
-#include <memory>
-#include <cstddef>
-
-namespace std {
-
-template <typename Key,
-    typename Compare = std::less<Key>,
-    typename Allocator = std::allocator<Key>>
-class set {
-private:
-    using rbtree_type = impl::rbtree<Key, Compare, Allocator>;
-    using node_allocator = typename rbtree_type::node_allocator;
-
-private:
-    rbtree_type tree;
-
-public:
-    using key_type = Key;
-    using value_type = Key;
-    using size_type = std::size_t;
-    using allocator_type = Allocator;
-    using iterator = typename rbtree_type::iterator;
-    using const_iterator = typename rbtree_type::const_iterator;
-
-public:
-    __GBLIBCPP_CONSTEXPR
-    iterator end(void) noexcept { return tree.end(); }
-    __GBLIBCPP_CONSTEXPR
-    const_iterator end(void) const noexcept { return tree.cend(); }
-    __GBLIBCPP_CONSTEXPR
-    const_iterator cend(void) const noexcept { return tree.cend(); }
-
-    __GBLIBCPP_CONSTEXPR
-    iterator begin(void) noexcept { return tree.begin(); }
-    __GBLIBCPP_CONSTEXPR
-    const_iterator begin(void) const noexcept { return tree.cbegin(); }
-    __GBLIBCPP_CONSTEXPR
-    const_iterator cbegin(void) const noexcept { return tree.cbegin(); }
-
-    explicit __GBLIBCPP_CONSTEXPR
-    set(const Compare& comp,
-        const Allocator& alloc = Allocator())
-        : tree(comp, alloc) {}
-
-    explicit __GBLIBCPP_CONSTEXPR
-    set(const Allocator& alloc)
-        : set(Compare(), alloc) {}
-
-    __GBLIBCPP_CONSTEXPR
-    set() : set(Compare()) {}
-
-    template <typename InputIter>
-    __GBLIBCPP_CONSTEXPR
-    set(InputIter first, InputIter last,
-        const Compare& comp = Compare(),
-        const Allocator& alloc = Allocator())
-        : set(comp, alloc)
-    {
-        insert(first, last);
-    }
-
-    template <typename InputIter>
-    __GBLIBCPP_CONSTEXPR
-    set(InputIter first, InputIter last,
-        const Allocator& alloc = Allocator())
-        : set(first, last, Compare(), alloc) {}
-
-    __GBLIBCPP_CONSTEXPR
-    set(const set& other) : tree(other.tree) {}
-    __GBLIBCPP_CONSTEXPR
-    set(const set& other, const Allocator& alloc)
-        : tree(other.tree, alloc) { }
-
-    __GBLIBCPP_CONSTEXPR
-    set(set&& other) : tree(std::move(other.tree)) {}
-    __GBLIBCPP_CONSTEXPR
-    set(set&& other, const Allocator& alloc)
-        : tree(std::move(other.tree), alloc) {}
-
-    __GBLIBCPP_CONSTEXPR
-    set(std::initializer_list<Key> ilist,
-        const Compare& comp = Compare(),
-        const Allocator& alloc = Allocator())
-        : set(comp, alloc)
-    { insert(ilist.begin(), ilist.end()); }
-
-    __GBLIBCPP_CONSTEXPR
-    set(std::initializer_list<Key> ilist,
-        const Allocator& alloc)
-        : set(ilist, Compare(), alloc) {}
-
-    __GBLIBCPP_CONSTEXPR
-    ~set() { clear(); }
-
-    __GBLIBCPP_CONSTEXPR
-    set& operator=(const set& other) = default;
-    __GBLIBCPP_CONSTEXPR
-    set& operator=(set&& other) = default;
-    __GBLIBCPP_CONSTEXPR
-    set& operator=(std::initializer_list<Key> ilist)
-    {
-        clear();
-        insert(ilist.begin(), ilist.end());
-        return *this;
-    }
-
-    __GBLIBCPP_CONSTEXPR
-    iterator find(const Key& key) { return tree.find(key); }
-    __GBLIBCPP_CONSTEXPR
-    const_iterator find(const Key& key) const { return tree.find(key); }
-    template <typename K>
-    __GBLIBCPP_CONSTEXPR
-    iterator find(const K& key) { return tree.find(key); }
-    template <typename K>
-    __GBLIBCPP_CONSTEXPR
-    const_iterator find(const K& key) const { return tree.find(key); }
-
-    __GBLIBCPP_CONSTEXPR
-    std::pair<iterator, bool> insert(const value_type& value)
-    { return tree.insert(value); }
-    __GBLIBCPP_CONSTEXPR
-    std::pair<iterator, bool> insert(value_type&& value)
-    { return tree.insert(std::move(value)); }
-
-    template <typename InputIter>
-    __GBLIBCPP_CONSTEXPR
-    void insert(InputIter first, InputIter last)
-    {
-        for ( ; first != last; ++first)
-            insert(*first);
-    }
-
-    template <typename... Args>
-    __GBLIBCPP_CONSTEXPR
-    std::pair<iterator, bool> emplace(Args&&... args)
-    { return tree.emplace(std::forward<Args>(args)...); }
-
-    __GBLIBCPP_CONSTEXPR
-    iterator erase(iterator pos) noexcept { return tree.erase(pos); }
-    __GBLIBCPP_CONSTEXPR
-    iterator erase(const_iterator pos) noexcept { return tree.erase(pos); }
-    __GBLIBCPP_CONSTEXPR
-    iterator erase(const_iterator first, const_iterator last) noexcept
-    {
-        while (first != last)
-            first = erase(first);
-        return first;
-    }
-
-    __GBLIBCPP_CONSTEXPR
-    size_type erase(const Key& key)
-    {
-        auto iter = find(key);
-        if (!iter)
-            return 0;
-        erase(iter);
-        return 1;
-    }
-
-    __GBLIBCPP_CONSTEXPR
-    void clear() noexcept { tree.destroy(); }
-
-    __GBLIBCPP_CONSTEXPR
-    bool empty() const noexcept { return tree.empty(); }
-
-    __GBLIBCPP_CONSTEXPR
-    size_type size() const noexcept { return tree.size(); }
-
-    __GBLIBCPP_CONSTEXPR
-    void swap(set& other) { tree.swap(other.tree); }
-
-    __GBLIBCPP_CONSTEXPR
-    size_type count(const Key& key) const
-    { return find(key) ? 1 : 0; }
-
-    __GBLIBCPP_CONSTEXPR
-    bool contains(const Key& key) const { return count(key) != 0; }
-
-    __GBLIBCPP_CONSTEXPR
-    iterator upper_bound(const Key& key)
-    { return tree.upper_bound(key); }
-    __GBLIBCPP_CONSTEXPR
-    const_iterator upper_bound(const Key& key) const
-    { return tree.upper_bound(key); }
-    template <typename K>
-    __GBLIBCPP_CONSTEXPR
-    iterator upper_bound(const K& key)
-    { return tree.upper_bound(key); }
-    template <typename K>
-    __GBLIBCPP_CONSTEXPR
-    const_iterator upper_bound(const K& key) const
-    { return tree.upper_bound(key); }
-
-    __GBLIBCPP_CONSTEXPR
-    iterator lower_bound(const Key& key)
-    { return tree.lower_bound(key); }
-    __GBLIBCPP_CONSTEXPR
-    const_iterator lower_bound(const Key& key) const
-    { return tree.lower_bound(key); }
-    template <typename K>
-    __GBLIBCPP_CONSTEXPR
-    iterator lower_bound(const K& key)
-    { return tree.lower_bound(key); }
-    template <typename K>
-    __GBLIBCPP_CONSTEXPR
-    const_iterator lower_bound(const K& key) const
-    { return tree.lower_bound(key); }
-};
-
-template <typename Key, typename Compare, typename Allocator>
-void swap(std::set<Key, Compare, Allocator>& lhs,
-    std::set<Key, Compare, Allocator>& rhs)
-{ lhs.swap(rhs); }
-
-template <typename Key, typename Compare,
-    typename Allocator, typename Pred>
-typename std::set<Key, Compare, Allocator>::size_type
-erase_if(std::set<Key, Compare, Allocator>& set, Pred pred)
-{
-    auto iter = set.begin();
-    typename std::set<Key, Compare, Allocator>::size_type count = 0;
-    while (iter != set.end()) {
-        if (pred(*iter)) {
-            iter = set.erase(iter);
-            ++count;
-        } else {
-            ++iter;
-        }
-    }
-    return count;
-}
-
-template <typename Key,
-    typename Compare = std::less<Key>,
-    typename Allocator = std::allocator<Key>>
-set(std::initializer_list<Key>, Compare = Compare(),
-    Allocator = Allocator()) -> set<Key, Compare, Allocator>;
-
-template <typename Key, typename Allocator>
-set(std::initializer_list<Key>, Allocator)
-    -> set<Key, std::less<Key>, Allocator>;
-
-} // namespace std
-
-#endif

+ 0 - 543
gblibstdc++/include/string

@@ -1,543 +0,0 @@
-#ifndef __GBLIBCPP_STRING__
-#define __GBLIBCPP_STRING__
-
-#include <bits/compressed_pair>
-#include <bits/iter_ops>
-
-#include <algorithm>
-#include <functional>
-#include <memory>
-#include <initializer_list>
-#include <cstddef>
-
-#include <string.h>
-
-namespace std {
-
-template <typename T>
-class char_traits;
-
-template <>
-class char_traits<char>
-{
-public:
-    static std::size_t length(const char* str) { return strlen(str); }
-
-    static int compare(const char* s1, const char* s2, std::size_t cnt)
-    {
-        return strncmp(s1, s2, cnt);
-    }
-};
-
-template <typename Char,
-         typename Traits = std::char_traits<Char>,
-         typename Allocator = std::allocator<Char>>
-class basic_string {
-public:
-    using traits_type = Traits;
-    using value_type = Char;
-    using allocator_type = Allocator;
-    using size_type = typename std::allocator_traits<Allocator>::size_type;
-    using difference_type = typename std::allocator_traits<Allocator>::difference_type;
-    using reference = value_type&;
-    using const_reference = const value_type&;
-    using pointer = typename std::allocator_traits<Allocator>::pointer;
-    using const_pointer = typename std::allocator_traits<Allocator>::const_pointer;
-
-    template <bool Const>
-    class _iterator {
-    public:
-        // TODO:
-        // using iterator_category = std::random_access_iterator_tag;
-        using _reference = std::conditional_t<Const, const_reference, reference>;
-
-    private:
-        pointer m_ptr;
-
-    public:
-        constexpr _iterator(void) noexcept : m_ptr() {}
-        constexpr explicit _iterator(pointer ptr) noexcept
-            : m_ptr(ptr) {}
-        constexpr _iterator(const _iterator& other) noexcept = default;
-        constexpr _iterator(_iterator&& other) noexcept = default;
-        constexpr _iterator& operator=(const _iterator& other) noexcept = default;
-        constexpr _iterator& operator=(_iterator&& other) noexcept = default;
-        constexpr bool operator==(const _iterator& other) const noexcept = default;
-
-        constexpr _reference operator*() const noexcept { return *m_ptr; }
-        constexpr pointer operator&() const noexcept
-        { return std::addressof(this->operator*()); }
-        constexpr pointer operator->() const noexcept
-        { return this->operator&(); }
-        constexpr _iterator& operator++() noexcept
-        { ++m_ptr; return *this; }
-        constexpr _iterator operator++(int) noexcept
-        { _iterator ret(m_ptr); (void)this->operator++(); return ret; }
-        constexpr _iterator& operator--(void) noexcept
-        { --m_ptr; return *this; }
-        constexpr _iterator operator--(int) noexcept
-        { _iterator ret(m_ptr); (void)this->operator--(); return ret; }
-        constexpr _iterator& operator+=(difference_type n) noexcept
-        { m_ptr += n; return *this; }
-        constexpr _iterator& operator-=(difference_type n) noexcept
-        { m_ptr -= n; return *this; }
-        constexpr _iterator operator+(difference_type n) const noexcept
-        { return _iterator { m_ptr + n }; }
-        constexpr _iterator operator-(difference_type n) const noexcept
-        { return _iterator { m_ptr - n }; }
-        constexpr difference_type operator-(const _iterator& other) const noexcept
-        { return m_ptr - other.m_ptr; }
-        constexpr _reference operator[](difference_type n) const noexcept
-        { return m_ptr[n]; }
-        constexpr operator bool() { return m_ptr; }
-        constexpr operator _iterator<true>() { return _iterator<true> { m_ptr }; }
-        constexpr operator _iterator<false>() { return _iterator<false> { m_ptr }; }
-        constexpr operator pointer() { return m_ptr; }
-    };
-
-private:
-    using alloc_traits = std::allocator_traits<Allocator>;
-
-public:
-    using iterator = _iterator<false>;
-    using const_iterator = _iterator<true>;
-
-private:
-    static constexpr std::size_t STATIC_SIZE = 32;
-    static constexpr std::size_t STATIC_COUNT =
-        STATIC_SIZE / sizeof(Char) - 2;
-
-    struct string_data_type { union {
-        std::byte __data[STATIC_SIZE];
-
-        struct {
-            union {
-                Char __data;
-                unsigned char n;
-            } m_size;
-            Char str[STATIC_COUNT];
-            Char end;
-        } stackdata;
-
-        struct {
-            std::size_t m_size;
-            std::size_t m_capacity;
-            Char* m_ptr;
-        } heapdata;
-
-    } in; };
-    impl::compressed_pair<string_data_type, Allocator> m_data;
-
-    constexpr Allocator& _alloc() noexcept { return m_data.second(); }
-    constexpr const Allocator& _alloc() const noexcept { return m_data.second(); }
-
-    constexpr bool _stack_data() const
-    {
-        return m_data.first().in.stackdata.end == 0;
-    }
-
-    constexpr bool _stack_data(bool val)
-    {
-        return (m_data.first().in.stackdata.end = !val), val;
-    }
-
-    constexpr void _release()
-    {
-        if (_stack_data()) {
-            _size(0);
-            return;
-        }
-
-        alloc_traits::deallocate(m_data.second(), data(), capacity()+1);
-
-        _stack_data(true);
-        _size(0);
-        _data()[0] = 0;
-    }
-
-    constexpr void _reserve(std::size_t cnt)
-    {
-        std::size_t cursize = size();
-        Char* newdata = alloc_traits::allocate(_alloc(), cnt+1);
-
-        memcpy(newdata, data(), size());
-        newdata[cursize] = 0;
-
-        if (_stack_data()) {
-            _stack_data(false);
-            _size(cursize);
-        }
-        else {
-            alloc_traits::deallocate(_alloc(), data(), capacity()+1);
-        }
-
-        _capacity(cnt);
-        _data(newdata);
-    }
-
-    constexpr std::size_t _size() const
-    {
-        if (_stack_data())
-            return m_data.first().in.stackdata.m_size.n;
-        else
-            return m_data.first().in.heapdata.m_size;
-    }
-
-    constexpr std::size_t _size(std::size_t val)
-    {
-        if (_stack_data())
-            return m_data.first().in.stackdata.m_size.n = (Char)val;
-        else
-            return m_data.first().in.heapdata.m_size = val;
-    }
-
-    constexpr std::size_t _capacity() const
-    {
-        if (_stack_data())
-            return STATIC_COUNT;
-        else
-            return m_data.first().in.heapdata.m_capacity;
-    }
-
-    constexpr std::size_t _capacity(std::size_t val)
-    {
-        if (_stack_data())
-            return STATIC_COUNT;
-        else
-            return m_data.first().in.heapdata.m_capacity = val;
-    }
-
-    constexpr const Char* _data() const
-    {
-        if (_stack_data())
-            return m_data.first().in.stackdata.str;
-        else
-            return m_data.first().in.heapdata.m_ptr;
-    }
-
-    constexpr Char* _data()
-    {
-        if (_stack_data())
-            return m_data.first().in.stackdata.str;
-        else
-            return m_data.first().in.heapdata.m_ptr;
-    }
-
-    constexpr Char* _data(Char* val)
-    {
-        if (_stack_data())
-            return m_data.first().in.stackdata.str;
-        else
-            return m_data.first().in.heapdata.m_ptr = val;
-    }
-
-public:
-    constexpr basic_string() noexcept(noexcept(Allocator()))
-        : basic_string{Allocator{}} { }
-
-    constexpr explicit basic_string(const Allocator& alloc) noexcept
-        : m_data{{}, alloc} { }
-
-    constexpr basic_string(const basic_string& other, const Allocator& alloc)
-        : basic_string{alloc}
-    {
-        append(other.c_str(), other.size());
-    }
-
-    constexpr basic_string(const basic_string& other)
-        : basic_string{other, alloc_traits::
-            select_on_container_copy_construction(other._alloc())} { }
-
-    constexpr basic_string(basic_string&& other) noexcept
-        : m_data{other.m_data.first(), std::move(other._alloc())}
-    {
-        other._stack_data(true);
-        other._size(0);
-        other._data()[0] = 0;
-    }
-
-    constexpr basic_string(basic_string&& other, const Allocator& alloc)
-        : basic_string{alloc}
-    {
-        if (alloc == other._alloc()) {
-            m_data.first() = other.m_data.first();
-            other._stack_data(true);
-            other._size(0);
-            other._data()[0] = 0;
-        }
-        else {
-            append(other.c_str(), other.size());
-        }
-    }
-
-    constexpr basic_string(const basic_string& other, size_type pos,
-            const Allocator& alloc = Allocator{})
-        : basic_string{other.c_str() + pos, alloc} { }
-
-    // constexpr basic_string(std::initializer_list<Char> ilist,
-    //         const Allocator& alloc = Allocator{})
-    //     : basic_string {alloc}
-    // {
-    //     assign(ilist.begin(), ilist.end());
-    // }
-
-    constexpr basic_string(const Char* str, size_type count,
-            const Allocator& alloc = Allocator{})
-        : basic_string{alloc}
-    {
-        assign(str, count);
-    }
-
-    constexpr basic_string(const Char* str, const Allocator& alloc = Allocator{})
-        : basic_string{str, traits_type::length(str), alloc} { }
-
-    constexpr ~basic_string()
-    {
-        _release();
-    }
-
-    constexpr basic_string& operator=(const Char* str)
-    {
-        return assign(str);
-    }
-
-    constexpr basic_string& operator=(const basic_string& other)
-    {
-        return assign(other.c_str(), other.size());
-    }
-
-    constexpr basic_string& operator=(basic_string&& other)
-    {
-        if constexpr (alloc_traits::
-                propagate_on_container_move_assignment::value) {
-            _release();
-            _alloc() = std::move(other._alloc());
-        }
-        else {
-            if (_alloc() != other._alloc()) {
-                assign(other.c_str(), other.size());
-                return *this;
-            }
-            _release();
-        }
-
-        m_data.first() = other.m_data.first();
-        other._stack_data(true);
-        other._size(0);
-        other._data()[0] = 0;
-
-        return *this;
-    }
-
-    constexpr basic_string& operator=(Char ch)
-    {
-        return assign(1, ch);
-    }
-
-    // constexpr basic_string& operator=(std::initializer_list<Char> init)
-    // {
-    //     assign(init.begin(), init.end());
-    //     return *this;
-    // }
-
-    constexpr basic_string& append(std::size_t len, Char ch)
-    {
-        std::size_t cursize = size();
-        std::size_t newsize = cursize + len;
-
-        if (newsize > capacity())
-            _reserve(std::max(capacity() * 2, newsize));
-
-        auto* pdata = data();
-        for (std::size_t i = cursize; i < newsize; ++i)
-            pdata[i] = ch;
-        pdata[newsize] = 0;
-
-        _size(newsize);
-
-        return *this;
-    }
-
-    constexpr basic_string& append(const Char* str, std::size_t count)
-    {
-        std::size_t cursize = size();
-        std::size_t newsize = cursize + count;
-
-        if (newsize > capacity())
-            _reserve(std::max(capacity() * 2, newsize));
-
-        memcpy(data() + cursize, str, count);
-        data()[newsize] = 0;
-
-        _size(newsize);
-
-        return *this;
-    }
-
-    constexpr basic_string& append(const Char* str)
-    {
-        return append(str, traits_type::length(str));
-    }
-
-    constexpr basic_string& assign(size_type n, Char ch)
-    {
-        clear();
-        return append(n, ch);
-    }
-
-    constexpr basic_string& assign(const Char* str, size_type count)
-    {
-        clear();
-        return append(str, count);
-    }
-
-    constexpr basic_string& assign(const Char* str)
-    {
-        return assign(str, traits_type::length(str));
-    }
-
-    // TODO: check whether InputIter satisfies LegacyInputIterator
-    // template <typename InputIter>
-    // constexpr basic_string& assign(InputIter first, InputIter last)
-    // {
-    //     clear();
-    //     insert(cbegin(), first, last);
-    //     return *this;
-    // }
-    // constexpr basic_string& assign(std::initializer_list<T> init)
-    // {
-    //     clear();
-    //     insert(cbegin(), init.begin(), init.end());
-    //     return *this;
-    // }
-
-    constexpr basic_string& operator+=(Char ch)
-    {
-        return append(1, ch);
-    }
-
-    constexpr basic_string& operator+=(const Char* str)
-    {
-        return append(str);
-    }
-
-    constexpr basic_string& operator+=(const basic_string& str)
-    {
-        return append(str.c_str(), str.size());
-    }
-
-    constexpr bool empty() const noexcept
-    { return size() == 0; }
-    constexpr size_type size() const noexcept
-    { return _size(); }
-    constexpr size_type capacity() const noexcept
-    { return _capacity(); }
-
-    constexpr Char* data() noexcept { return _data(); }
-    constexpr const Char* data() const noexcept { return _data(); }
-    constexpr const Char* c_str() const noexcept { return data(); }
-
-    constexpr reference operator[](size_type pos)
-    { return data()[pos]; }
-    constexpr const_reference operator[](size_type pos) const
-    { return data()[pos]; }
-
-    // constexpr reference at(size_type pos)
-    // {
-    //     // TODO: exceptions
-    //     // if (pos >= size())
-    //     //     throw std::out_of_range("basic_string::at");
-    //     return operator[](pos);
-    // }
-    // constexpr const_reference at(size_type pos) const
-    // {
-    //     // TODO: exceptions
-    //     // if (pos >= size())
-    //     //     throw std::out_of_range("basic_string::at");
-    //     return operator[](pos);
-    // }
-
-    constexpr reference front() noexcept
-    { return operator[](0); }
-    constexpr const_reference front() const noexcept
-    { return operator[](0); }
-    constexpr reference back() noexcept
-    { return operator[](size() - 1); }
-    constexpr const_reference back() const noexcept
-    { return operator[](size() - 1); }
-
-    // TODO: std::reverse_iterator
-    constexpr iterator begin() noexcept
-    { return iterator { data() }; }
-    constexpr const_iterator begin() const noexcept
-    { return const_iterator { data() }; }
-    constexpr const_iterator cbegin() const noexcept
-    { return const_iterator { data() }; }
-    constexpr iterator end() noexcept
-    { return iterator { data() + size() }; }
-    constexpr const_iterator end() const noexcept
-    { return const_iterator { data() + size() }; }
-    constexpr const_iterator cend() const noexcept
-    { return const_iterator { data() + size() }; }
-
-    constexpr void clear() noexcept{ _size(0); }
-
-    constexpr void push_back(Char ch) { append(1, ch); }
-    constexpr void pop_back() { erase(cend()-1); }
-
-    constexpr void swap(basic_string& other) noexcept(
-        alloc_traits::propagate_on_container_swap::value
-        || alloc_traits::is_always_equal::value)
-    {
-        if (alloc_traits::propagate_on_container_swap::value)
-            std::swap(_alloc(), other._alloc());
-        std::swap(m_data.first(), other.m_data.first());
-    }
-
-    constexpr int compare(const basic_string& str) const noexcept
-    {
-        return traits_type::compare(c_str(), str.c_str(), size()+1);
-    }
-
-    constexpr int compare(const Char* str) const
-    {
-        return traits_type::compare(c_str(), str, size()+1);
-    }
-};
-
-template <typename Char, typename Traits, typename Allocator>
-constexpr bool operator==(
-    const std::basic_string<Char, Traits, Allocator>& lhs,
-    const std::basic_string<Char, Traits, Allocator>& rhs) noexcept
-{
-    return lhs.compare(rhs) == 0;
-}
-
-template <typename Char, typename Traits, typename Allocator>
-constexpr bool operator==(
-    const std::basic_string<Char, Traits, Allocator>& lhs, const Char* rhs)
-{
-    return lhs.compare(rhs) == 0;
-}
-
-template <typename Char, typename Traits, typename Allocator>
-constexpr bool operator<(
-    const std::basic_string<Char, Traits, Allocator>& lhs,
-    const std::basic_string<Char, Traits, Allocator>& rhs) noexcept
-{
-    return lhs.compare(rhs) < 0;
-}
-
-template <typename Char, typename Traits, typename Allocator>
-constexpr void swap(
-    std::basic_string<Char, Traits, Allocator>& lhs,
-    std::basic_string<Char, Traits, Allocator>& rhs) noexcept(noexcept(lhs.swap(rhs)))
-{
-    lhs.swap(rhs);
-}
-
-using string = basic_string<char>;
-
-} // namespace std
-
-#endif

+ 0 - 483
gblibstdc++/include/tuple

@@ -1,483 +0,0 @@
-#ifndef __GBLIBCPP_TUPLE__
-#define __GBLIBCPP_TUPLE__
-
-#include <cstddef>
-#include <type_traits>
-#include <utility>
-
-#include <functional>
-
-#include <bits/tuple_tools>
-#include <bits/sequence>
-
-namespace std {
-
-template <std::size_t I, typename T>
-struct tuple_element<I, const T> {
-    using type = std::add_const_t<tuple_element_t<I, T>>;
-};
-template <std::size_t I, typename T>
-struct tuple_element<I, volatile T> {
-    using type = std::add_volatile_t<tuple_element_t<I, T>>;
-};
-template <std::size_t I, typename T>
-struct tuple_element<I, const volatile T> {
-    using type = std::add_cv_t<tuple_element_t<I, T>>;
-};
-
-namespace __helpers {
-
-template <typename T, typename = void>
-struct __const_tuple_size {};
-
-template <typename T>
-struct __const_tuple_size<T, void_t<decltype(std::tuple_size<T>::value)>>
-    : std::integral_constant<std::size_t, std::tuple_size<T>::value> {};
-
-} // namespace __helpers
-
-template <typename T>
-struct tuple_size<const T> : __helpers::__const_tuple_size<T> {};
-
-template <typename... Types>
-class tuple;
-
-template <std::size_t I, typename Type, typename... Types>
-struct tuple_element<I, std::tuple<Type, Types...>>
-    : tuple_element<I-1, std::tuple<Types...>> {};
-
-template <typename Type, typename... Types>
-struct tuple_element<0, std::tuple<Type, Types...>> { using type = Type; };
-
-template <typename... Types>
-struct tuple_size<std::tuple<Types...>>
-    : std::integral_constant<std::size_t, sizeof...(Types)> {};
-
-namespace __helpers {
-
-template <std::size_t I, typename... Types>
-class tuple_impl;
-
-template <>
-class tuple_impl<0> {
-    template <std::size_t, typename...>
-    friend class tuple_impl;
-
-    template <std::size_t J, typename... UTypes>
-    friend constexpr auto std::get(std::tuple<UTypes...>& tpl) noexcept
-        -> tuple_element_t<J, std::tuple<UTypes...>>&;
-    template <std::size_t J, typename... UTypes>
-    friend constexpr auto std::get(std::tuple<UTypes...>&& tpl) noexcept
-        -> tuple_element_t<J, std::tuple<UTypes...>>&&;
-    template <std::size_t J, typename... UTypes>
-    friend constexpr auto std::get(const std::tuple<UTypes...>& tpl) noexcept
-        -> tuple_element_t<J, std::tuple<UTypes...>> const&;
-    template <std::size_t J, typename... UTypes>
-    friend constexpr auto std::get(const std::tuple<UTypes...>&& tpl) noexcept
-        -> tuple_element_t<J, std::tuple<UTypes...>> const&&;
-
-    template <std::size_t> constexpr void _getl(void) const = delete;
-    template <std::size_t> constexpr void _getr(void) const = delete;
-public:
-    constexpr tuple_impl() noexcept = default;
-
-    constexpr tuple_impl(const tuple_impl& arg) noexcept = default;
-    constexpr tuple_impl(tuple_impl&& arg) noexcept = default;
-
-    template <typename... UTypes>
-    constexpr tuple_impl(const std::tuple<UTypes...>& other) = delete;
-    template <typename... UTypes>
-    constexpr tuple_impl(std::tuple<UTypes...>&& other) = delete;
-
-    constexpr tuple_impl& operator=(const tuple_impl& other) noexcept = default;
-    constexpr tuple_impl& operator=(tuple_impl&& other) noexcept = default;
-};
-
-template <std::size_t I, typename Type, typename... Types>
-class tuple_impl<I, Type, Types...> {
-    template <std::size_t, typename...>
-    friend class tuple_impl;
-
-    template <std::size_t J, typename... UTypes>
-    friend constexpr auto std::get(std::tuple<UTypes...>& tpl) noexcept
-        -> tuple_element_t<J, std::tuple<UTypes...>>&;
-    template <std::size_t J, typename... UTypes>
-    friend constexpr auto std::get(std::tuple<UTypes...>&& tpl) noexcept
-        -> tuple_element_t<J, std::tuple<UTypes...>>&&;
-    template <std::size_t J, typename... UTypes>
-    friend constexpr auto std::get(const std::tuple<UTypes...>& tpl) noexcept
-        -> tuple_element_t<J, std::tuple<UTypes...>> const&;
-    template <std::size_t J, typename... UTypes>
-    friend constexpr auto std::get(const std::tuple<UTypes...>&& tpl) noexcept
-        -> tuple_element_t<J, std::tuple<UTypes...>> const&&;
-
-    Type val;
-    tuple_impl<I+1, Types...> next;
-
-    template <std::size_t J>
-    constexpr auto& _getl(void)
-    {
-        if constexpr (I == J)
-            return val;
-        else
-            return next.template _getl<J>();
-    }
-
-    template <std::size_t J>
-    constexpr const auto& _getl(void) const
-    {
-        if constexpr (I == J)
-            return val;
-        else
-            return next.template _getl<J>();
-    }
-
-    template <std::size_t J>
-    constexpr auto&& _getr(void)
-    {
-        if constexpr (I == J)
-            return std::forward<Type>(val);
-        else
-            return std::forward<
-                decltype(next.template _getr<J>())>(
-                    next.template _getr<J>());
-    }
-
-    template <std::size_t J>
-    constexpr const auto&& _getr(void) const
-    {
-        if constexpr (I == J)
-            return std::forward<Type>(val);
-        else
-            return std::forward<
-                decltype(next.template _getr<J>())>(
-                    next.template _getr<J>());
-    }
-
-public:
-    constexpr tuple_impl()
-        : val(), next() {}
-
-    constexpr tuple_impl(const tuple_impl& arg) = default;
-    constexpr tuple_impl(tuple_impl&& arg) = default;
-
-    constexpr tuple_impl(const Type& val, const Types&... vals)
-        : val(val), next(vals...) {}
-
-    template <typename UType, typename... UTypes>
-    constexpr tuple_impl(UType&& val, UTypes&&... vals)
-        : val(std::forward<UType>(val)), next(std::forward<UTypes>(vals)...) {}
-
-    template <typename... UTypes>
-    constexpr tuple_impl(const std::tuple<UTypes...>& other)
-        : val(std::get<I>(other)), next(other) {}
-    template <typename... UTypes>
-    constexpr tuple_impl(std::tuple<UTypes...>&& other)
-        : val(std::get<I>(other)), next(std::move(other)) {}
-
-    constexpr tuple_impl& operator=(const tuple_impl& other) = default;
-    constexpr tuple_impl& operator=(tuple_impl&& other) = default;
-};
-
-template <std::size_t I, typename Type>
-class tuple_impl<I, Type> {
-    template <std::size_t, typename...>
-    friend class tuple_impl;
-
-    template <std::size_t J, typename... UTypes>
-    friend constexpr auto std::get(std::tuple<UTypes...>& tpl) noexcept
-        -> tuple_element_t<J, std::tuple<UTypes...>>&;
-    template <std::size_t J, typename... UTypes>
-    friend constexpr auto std::get(std::tuple<UTypes...>&& tpl) noexcept
-        -> tuple_element_t<J, std::tuple<UTypes...>>&&;
-    template <std::size_t J, typename... UTypes>
-    friend constexpr auto std::get(const std::tuple<UTypes...>& tpl) noexcept
-        -> tuple_element_t<J, std::tuple<UTypes...>> const&;
-    template <std::size_t J, typename... UTypes>
-    friend constexpr auto std::get(const std::tuple<UTypes...>&& tpl) noexcept
-        -> tuple_element_t<J, std::tuple<UTypes...>> const&&;
-
-    Type val;
-
-    template <std::size_t J>
-    constexpr Type& _getl(void)
-    {
-        static_assert(J == I);
-        return val;
-    }
-    template <std::size_t J>
-    constexpr Type const& _getl(void) const
-    {
-        static_assert(J == I);
-        return val;
-    }
-    template <std::size_t J>
-    constexpr Type&& _getr(void)
-    {
-        static_assert(J == I);
-        return std::forward<Type>(val);
-    }
-    template <std::size_t J>
-    constexpr Type const&& _getr(void) const
-    {
-        static_assert(J == I);
-        return std::forward<Type>(val);
-    }
-
-public:
-    constexpr tuple_impl()
-        : val() {}
-
-    constexpr tuple_impl(const tuple_impl& arg) = default;
-    constexpr tuple_impl(tuple_impl&& arg) = default;
-
-    constexpr tuple_impl(const Type& val) : val(val) {}
-
-    template <typename UType>
-    constexpr tuple_impl(UType&& val) : val(std::forward<UType>(val)) {}
-
-    template <typename... UTypes>
-    constexpr tuple_impl(const std::tuple<UTypes...>& other)
-        : val(std::get<I>(other)) {}
-    template <typename... UTypes>
-    constexpr tuple_impl(std::tuple<UTypes...>&& other)
-        : val(std::get<I>(other)) {}
-
-    constexpr tuple_impl& operator=(const tuple_impl& other) = default;
-    constexpr tuple_impl& operator=(tuple_impl&& other) = default;
-};
-
-template <typename... Types>
-struct tuple_constraints {
-    static constexpr std::size_t Tsize = sizeof...(Types);
-
-    template <std::size_t... I>
-    static constexpr auto idx_seq(std::index_sequence<I...> seq)
-    { return seq; }
-
-    template <typename UTuple, typename Seq, typename... UTypes>
-    struct tuple_copy_move_constructible_impl;
-
-    template <typename UTuple, typename... UTypes, std::size_t... I>
-    struct tuple_copy_move_constructible_impl<UTuple,
-        std::index_sequence<I...>, UTypes...> : std::bool_constant<
-        Tsize == sizeof...(UTypes)
-        && (... && std::is_constructible_v<Types, decltype(
-            std::get<I>(std::declval<UTuple>()))>)
-        && ((Tsize != 1) || (!(... && std::is_convertible_v<UTuple, Types>)
-            && !(... && std::is_constructible_v<Types, UTuple>)
-            && !(... && std::is_same_v<Types, UTypes>)))
-    > {};
-
-    template <typename UTuple, typename... UTypes>
-    struct tuple_copy_move_constructible : tuple_copy_move_constructible_impl<
-        UTuple, decltype(idx_seq(std::index_sequence_for<UTypes...>{})), UTypes...> {};
-
-    template <typename Pair, typename = std::index_sequence<0, 1>>
-    struct tuple_pair_constructible;
-
-    template <typename Pair, std::size_t... I>
-    struct tuple_pair_constructible<Pair, std::index_sequence<I...>>
-        : std::bool_constant<sizeof...(Types) == 2
-            && (... && std::is_constructible_v<Types,
-                decltype(std::get<I>(std::declval<Pair>()))>)
-    > {};
-
-    template <typename... Us>
-    struct tuple_pair_copy_assignable : std::bool_constant<
-        sizeof...(Types) == 2
-        && (... && std::is_assignable_v<Types&, const Us&>)
-    > {};
-
-    template <typename... Us>
-    struct tuple_pair_move_assignable : std::bool_constant<
-        sizeof...(Types) == 2
-        && (... && std::is_assignable_v<Types&, Us>)
-    > {};
-};
-
-} // namespace __helpers
-
-template <typename... Types>
-class tuple : public __helpers::tuple_impl<0, Types...> {
-private:
-    using base = __helpers::tuple_impl<0, Types...>;
-
-    template <typename... UTypes, std::size_t... I>
-    constexpr void __copy_assignment(
-        const tuple<UTypes...>& other, std::index_sequence<I...>)
-    { ((std::get<I>(*this) = std::get<I>(other)), ...); }
-
-    template <typename... UTypes, std::size_t... I>
-    constexpr void __move_assignment(
-        tuple<UTypes...>&& other, std::index_sequence<I...>)
-    {
-        ((std::get<I>(*this) = std::forward<UTypes>(std::get<I>(other))), ...);
-    }
-
-public:
-    template <typename _ = void, std::enable_if_t<
-        (... && std::is_default_constructible_v<Types>)
-        && __helpers::template_true_type<_>::value
-    , bool> = true>
-    constexpr tuple() : base() {}
-
-    template <typename _ = void, std::enable_if_t<
-        sizeof...(Types) >= 1
-        && (... && std::is_copy_constructible_v<Types>)
-        && __helpers::template_true_type<_>::value
-    , bool> = true>
-    constexpr tuple(const Types&... args)
-        : base(args...) {}
-
-    template <typename... UTypes, std::enable_if_t<
-        sizeof...(UTypes) == sizeof...(Types)
-        && sizeof...(Types) >= 1
-        && (... && std::is_constructible_v<Types, UTypes>)
-        && !(sizeof...(Types) == 1
-            && (... && std::is_same_v<tuple, std::remove_cvref_t<UTypes>>))
-    , bool> = true>
-    constexpr tuple(UTypes&&... args)
-        : base(std::forward<UTypes>(args)...) {}
-
-    template <typename... UTypes, std::enable_if_t<
-        __helpers::tuple_constraints<Types...>::template
-            tuple_copy_move_constructible<const tuple<UTypes...>&, UTypes...>::value
-    , bool> = true>
-    constexpr tuple(const tuple<UTypes...>& other)
-        : base(other) {}
-
-    template <typename... UTypes, std::enable_if_t<
-        __helpers::tuple_constraints<Types...>::template
-            tuple_copy_move_constructible<tuple<UTypes...>&&, UTypes...>::value
-    , bool> = true>
-    constexpr tuple(tuple<UTypes...>&& other)
-        : base(std::move(other)) {}
-
-    template <typename U1, typename U2, std::enable_if_t<
-        __helpers::tuple_constraints<Types...>::template
-            tuple_pair_constructible<const std::pair<U1, U2>&>::value
-    , bool> = true>
-    constexpr tuple(const std::pair<U1, U2>& p)
-        : base(std::get<0>(p), std::get<1>(p)) {}
-
-    template <typename U1, typename U2, std::enable_if_t<
-        __helpers::tuple_constraints<Types...>::template
-            tuple_pair_constructible<std::pair<U1, U2>&&>::value
-    , bool> = true>
-    constexpr tuple(std::pair<U1, U2>&& p)
-        : base(std::get<0>(std::move(p)), std::get<1>(std::move(p))) {}
-
-    constexpr tuple(const tuple&) = default;
-    constexpr tuple(tuple&&) = default;
-
-    constexpr tuple& operator=(const tuple& other) = default;
-    constexpr tuple& operator=(tuple&& other) = default;
-
-    template <typename... UTypes, std::enable_if_t<
-        sizeof...(Types) == sizeof...(UTypes)
-        && (... && std::is_assignable_v<Types&, const UTypes&>)
-        , bool> = true>
-    constexpr tuple& operator=(const tuple<UTypes...>& other)
-    {
-        __copy_assignment(other, index_sequence_for<Types...> {});
-        return *this;
-    }
-
-    template <typename... UTypes, std::enable_if_t<
-        sizeof...(Types) == sizeof...(UTypes)
-        && (... && std::is_assignable_v<Types&, UTypes>)
-        , bool> = true>
-    constexpr tuple& operator=(tuple<UTypes...>&& other)
-    {
-        __move_assignment(std::move(other), index_sequence_for<Types...> {});
-        return *this;
-    }
-
-    template <typename U1, typename U2, std::enable_if_t<
-        __helpers::tuple_constraints<Types...>::template
-            tuple_pair_copy_assignable<U1, U2>::value
-    , bool> = true>
-    constexpr tuple& operator=(const std::pair<U1, U2>& p)
-    {
-        std::get<0>(*this) = p.first;
-        std::get<1>(*this) = p.second;
-        return *this;
-    }
-
-    template <typename U1, typename U2, std::enable_if_t<
-        __helpers::tuple_constraints<Types...>::template
-            tuple_pair_move_assignable<U1, U2>::value
-    , bool> = true>
-    constexpr tuple& operator=(std::pair<U1, U2>&& p)
-    {
-        std::get<0>(*this) = std::forward<U1>(p.first);
-        std::get<1>(*this) = std::forward<U2>(p.second);
-        return *this;
-    }
-
-    constexpr void swap(tuple& other) { std::swap(*this, other); }
-};
-
-template <typename... Types>
-tuple(Types...) -> tuple<Types...>;
-
-namespace __helpers {
-
-struct ignore_t {
-    template <typename T>
-    constexpr void operator=(T&&) const noexcept {}
-};
-
-template <typename Func, typename Tuple, std::size_t... I>
-constexpr auto apply_impl(Func&& func, Tuple&& tpl, std::index_sequence<I...>)
-{
-    return std::invoke(
-        std::forward<Func>(func),
-        std::get<I>(std::forward<Tuple>(tpl))...);
-}
-
-} // namespace __helpers
-
-inline constexpr __helpers::ignore_t ignore;
-
-template <typename... Types>
-constexpr void swap(std::tuple<Types...>& lhs, std::tuple<Types...>& rhs)
-    noexcept(noexcept(lhs.swap(rhs)))
-{
-    lhs.swap(rhs);
-}
-
-template <typename... Types>
-constexpr auto make_tuple(Types&&... args)
-    -> std::tuple<__helpers::to_tuple_type_t<Types>...>
-{
-    return std::tuple<__helpers::to_tuple_type_t<Types>...>
-        { std::forward<Types>(args)... };
-}
-
-template <typename... Types>
-constexpr std::tuple<Types&...> tie(Types&... args) noexcept
-{
-    return { args... };
-}
-
-template <typename... Types>
-constexpr std::tuple<Types&&...> forward_as_tuple(Types&&... args) noexcept
-{
-    return { std::forward<Types>(args)... };
-}
-
-template <typename Func, typename Tuple>
-constexpr decltype(auto) apply(Func&& func, Tuple&& tpl)
-{
-    return __helpers::apply_impl(
-        std::forward<Func>(func), std::forward<Tuple>(tpl),
-        std::make_index_sequence<
-            std::tuple_size_v<std::remove_cvref_t<Tuple>>> {}
-    );
-}
-
-} // namespace std
-
-#endif

+ 0 - 356
gblibstdc++/include/type_traits

@@ -1,356 +0,0 @@
-#ifndef __GBLIBCPP_TYPE_TRAITS__
-#define __GBLIBCPP_TYPE_TRAITS__
-
-#include <bits/fwd_functional>
-#include <bits/forward>
-
-#include <bits/type_traits/base>
-#include <bits/type_traits/is_es>
-#include <bits/type_traits/remove_add>
-
-namespace std {
-
-template <typename T>
-struct add_const { using type = T const; };
-template <typename T>
-struct add_volatile { using type = T volatile; };
-template <typename T>
-struct add_cv { using type = T const volatile; };
-
-template <typename T>
-using add_const_t = typename add_const<T>::type;
-template <typename T>
-using add_volatile_t = typename add_volatile<T>::type;
-template <typename T>
-using add_cv_t = typename add_cv<T>::type;
-
-template <typename T, typename U>
-struct is_same : public false_type {};
-template <typename T>
-struct is_same<T, T> : public true_type {};
-
-template <typename T, typename U>
-inline constexpr bool is_same_v = is_same<T, U>::value;
-
-template <typename T>
-struct is_void : public is_same<remove_cv_t<T>, void> {};
-
-template <typename T>
-inline constexpr bool is_void_v = is_void<T>::value;
-
-template <typename T>
-struct is_pointer : public false_type {};
-template <typename T>
-struct is_pointer<T*> : public true_type {};
-template <typename T>
-struct is_pointer<T* const> : public true_type {};
-template <typename T>
-struct is_pointer<T* volatile> : public true_type {};
-template <typename T>
-struct is_pointer<T* const volatile> : public true_type {};
-
-template <typename T>
-inline constexpr bool is_pointer_v = is_pointer<T>::value;
-
-template <bool B, typename T = void>
-struct enable_if {};
-template <typename T>
-struct enable_if<true, T> { using type = T; };
-
-template <bool B, typename T = void>
-using enable_if_t = typename enable_if<B, T>::type;
-
-namespace __helpers {
-
-template <typename From, typename To, typename = void>
-struct is_convertible : public false_type {};
-template <typename From, typename To>
-struct is_convertible<From, To,
-    decltype(declval<void(*)(To)>()(declval<From>()))
-> : public true_type {};
-template <typename Void1, typename Void2>
-struct is_convertible<Void1, Void2,
-    enable_if_t<is_void_v<Void1> && is_void_v<Void2> >
-> : public true_type {};
-
-template <typename From, typename To, typename = void>
-struct is_nothrow_convertible : public false_type {};
-template <typename From, typename To>
-struct is_nothrow_convertible<From, To,
-    decltype(declval<void(*)(To)>()(declval<From>()))
-> : public true_type {};
-template <typename Void1, typename Void2>
-struct is_nothrow_convertible<Void1, Void2,
-    enable_if_t<is_void_v<Void1> && is_void_v<Void2> >
-> : public true_type {};
-
-// TODO: check T is union
-template <typename T>
-true_type __test_is_class(int T::*);
-template <typename T>
-false_type __test_is_class(...);
-
-template <typename Base, typename Derived>
-auto _try_is_base_of(...) -> true_type;
-
-template <typename Base, typename Derived>
-auto _try_is_base_of() ->
-    decltype(void());
-
-template <typename Base>
-true_type __conv_base_pointer(const volatile Base*);
-template <typename>
-false_type __conv_base_pointer(const volatile void*);
-
-template <typename Base, typename Derived>
-decltype(__conv_base_pointer<Base>(declval<Derived*>()))
-try_is_base_of(int);
-
-template <typename, typename>
-true_type try_is_base_of(...);
-
-} // namespace __helpers
-
-template <typename From, typename To>
-struct is_convertible : public __helpers::is_convertible<From, To> {};
-template <typename From, typename To>
-struct is_nothrow_convertible : public __helpers::is_nothrow_convertible<From, To> {};
-
-template <typename From, typename To>
-inline constexpr bool is_convertible_v = is_convertible<From, To>::value;
-template <typename From, typename To>
-inline constexpr bool is_nothrow_convertible_v = is_nothrow_convertible<From, To>::value;
-
-template <typename T>
-struct is_class : public decltype(__helpers::__test_is_class<T>(nullptr)) {};
-
-template <typename T>
-inline constexpr bool is_class_v = is_class<T>::value;
-
-template <typename Base, typename Derived>
-struct is_base_of : public bool_constant<
-    is_class_v<Base> && is_class_v<Derived>
-    && decltype(__helpers::try_is_base_of<Base, Derived>(0))::value
-> {};
-
-template <typename Base, typename Derived>
-inline constexpr bool is_base_of_v = is_base_of<Base, Derived>::value;
-
-namespace __helpers {
-
-template <typename>
-struct is_reference_wrapper : public false_type {};
-template <typename T>
-struct is_reference_wrapper<reference_wrapper<T>> : public true_type {};
-
-template <typename FuncType>
-struct __invoke_impl {
-    template <typename Func, typename... Args>
-    static auto __invoke(Func&& func, Args&&... args)
-        noexcept(noexcept(forward<Func>(func)(forward<Args>(args)...)))
-        -> decltype(forward<Func>(func)(forward<Args>(args)...)) {
-        return forward<Func>(func)(forward<Args>(args)...);
-    }
-};
-
-template <typename T, typename Ret>
-struct __invoke_impl<Ret T::*> {
-    template <typename _T1, typename T1 = decay_t<_T1>, typename = enable_if_t<
-        is_same_v<T, T1> || is_base_of_v<T, T1>
-        >>
-    static auto get(_T1&& val) -> _T1&& {
-        return forward<_T1>(val);
-    }
-
-    template <typename _T1, typename T1 = decay_t<_T1>, typename = enable_if_t<
-        is_reference_wrapper<T1>::value
-        >>
-    static auto get(_T1&& val) -> decltype(val.get()) {
-        return val.get();
-    }
-
-    template <typename _T1, typename T1 = decay_t<_T1>, typename = enable_if_t<
-        !is_same_v<T, T1> && !is_base_of_v<T, T1>
-        && !is_reference_wrapper<T1>::value
-        >>
-    static auto get(_T1&& val) -> decltype(*forward<_T1>(val)) {
-        return *forward<_T1>(val);
-    }
-
-    template <typename T1, typename... Args>
-    static auto __invoke(Ret T::*pmf, T1&& t1, Args&&... args)
-        noexcept(noexcept((forward<T1>(t1).*pmf)(forward<Args>(args)...)))
-        -> decltype((get(forward<T1>(t1)).*pmf)(forward<Args>(args)...)) {
-        return (get(forward<T1>(t1)).*pmf)(forward<Args>(args)...);
-    }
-
-    template <typename T1>
-    static auto __invoke(Ret T::*pdm, T1&& t1) noexcept
-        -> decltype(get(forward<T1>(t1)).*pdm) {
-        return get(forward<T1>(t1)).*pdm;
-    }
-};
-
-template <typename Func, typename... Args, typename FuncBase = decay_t<Func>>
-auto INVOKE(Func&& func, Args&&... args)
-    noexcept(noexcept(__invoke_impl<FuncBase>::__invoke(
-        forward<Func>(func), forward<Args>(args)...)))
-    -> decltype(__invoke_impl<FuncBase>::__invoke(
-        forward<Func>(func), forward<Args>(args)...))
-{
-    return __invoke_impl<FuncBase>::__invoke(
-    forward<Func>(func), forward<Args>(args)...);
-}
-
-template <typename Func, typename = void, typename... Args>
-struct __is_invocable : public false_type {};
-
-template <typename Func, typename... Args>
-struct __is_invocable<Func, void_t<
-    decltype(INVOKE(declval<Func>(), declval<Args>()...))>,
-    Args...> : public true_type {};
-
-template <typename Func, typename = void, typename... Args>
-struct __invoke_result {};
-
-template <typename Func, typename... Args>
-struct __invoke_result<Func, enable_if_t<
-    __is_invocable<Func, void, Args...>::value
->, Args...> {
-    using type = decltype(INVOKE(declval<Func>(), declval<Args>()...));
-};
-
-template <typename R, typename Func, typename... Args>
-enable_if_t<
-    is_convertible_v<typename __invoke_result<Func, void, Args...>::type, R>, R>
-INVOKE_R(Func&& func, Args&&... args)
-    noexcept(
-        noexcept(INVOKE(forward<Func>(func), forward<Args>(args)...))
-        && noexcept(is_nothrow_convertible_v<
-            typename __invoke_result<Func, void, Args...>::type, R>)
-    )
-{
-    return INVOKE(forward<Func>(func), forward<Args>(args)...);
-}
-
-template <typename R, typename Func, typename = void, typename... Args>
-struct __is_invocable_r : public false_type {};
-
-template <typename R, typename Func, typename... Args>
-struct __is_invocable_r<R, Func, void_t<
-    decltype(INVOKE_R<R>(declval<Func>(), declval<Args>()...))>,
-    Args...> : public true_type {};
-
-} // namespace __helpers
-
-template <typename Func, typename... Args>
-struct is_invocable : __helpers::__is_invocable<Func, void, Args...> {};
-template <typename R, typename Func, typename... Args>
-struct is_invocable_r : __helpers::__is_invocable_r<R, Func, void, Args...> {};
-
-template <typename Func, typename... Args>
-struct is_nothrow_invocable : bool_constant<
-    is_invocable<Func, Args...>::value
-    && noexcept(__helpers::INVOKE(declval<Func>(), declval<Args>()...))
-> {};
-template <typename R, typename Func, typename... Args>
-struct is_nothrow_invocable_r : bool_constant<
-    is_invocable_r<R, Func, Args...>::value
-    && noexcept(__helpers::INVOKE_R<R>(declval<Func>(), declval<Args>()...))
-> {};
-
-template <typename Func, typename... Args>
-inline constexpr bool is_invocable_v = is_invocable<Func, Args...>::value;
-template <typename R, typename Func, typename... Args>
-inline constexpr bool is_invocable_r_v = is_invocable_r<R, Func, Args...>::value;
-template <typename Func, typename... Args>
-inline constexpr bool is_nothrow_invocable_v = is_nothrow_invocable<Func, Args...>::value;
-template <typename R, typename Func, typename... Args>
-inline constexpr bool is_nothrow_invocable_r_v = is_nothrow_invocable_r<R, Func, Args...>::value;
-
-template <typename Func, typename... Args>
-struct invoke_result : __helpers::__invoke_result<Func, void, Args...> {};
-
-template <class Func, class... Args>
-using invoke_result_t = typename invoke_result<Func, Args...>::type;
-
-template <typename T, typename U, typename = void>
-struct is_assignable : public false_type {};
-
-template <typename T, typename U>
-struct is_assignable<T, U, void_t<
-    decltype(std::declval<T>() = std::declval<U>())>> : public true_type {};
-
-template <typename T, typename U>
-inline constexpr bool is_assignable_v = is_assignable<T, U>::value;
-
-#if defined(__GNUC__) or defined(__clang__)
-
-template <typename T, typename... Args>
-struct is_constructible
-    : public bool_constant<__is_constructible(T, Args...)> {};
-
-#else
-
-namespace __helpers {
-
-template <typename T, typename = void, typename... Args>
-struct is_constructible_impl : public false_type {};
-
-template <typename T, typename... Args>
-struct is_constructible_impl<T, void_t<
-    decltype(
-        T { declval<Args>()... }
-    )>, Args...> : public true_type {};
-
-} // namespace __helpers
-
-template <typename T, typename... Args>
-struct is_constructible
-    : public __helpers::is_constructible_impl<T, void, Args...> {};
-
-#endif
-
-template <typename T>
-struct is_default_constructible : public is_constructible<T> {};
-
-template <typename T>
-struct is_copy_constructible
-    : public is_constructible<T, add_lvalue_reference_t<add_const_t<T>>> {};
-
-template <typename T>
-struct is_move_constructible
-    : public is_constructible<T, add_rvalue_reference_t<T>> {};
-
-template <typename T, typename... Args>
-inline constexpr bool is_constructible_v = is_constructible<T, Args...>::value;
-template <typename T>
-inline constexpr bool is_default_constructible_v = is_default_constructible<T>::value;
-template <typename T>
-inline constexpr bool is_copy_constructible_v = is_copy_constructible<T>::value;
-template <typename T>
-inline constexpr bool is_move_constructible_v = is_move_constructible<T>::value;
-
-#define __CPP_GREATBRIDF
-#ifdef __CPP_GREATBRIDF
-
-template <typename U, template <typename...> class T, typename...>
-struct is_template_instance : public false_type {
-};
-template <template <typename...> class T, typename... Ts>
-struct is_template_instance<T<Ts...>, T, Ts...> : public true_type {
-};
-
-template <typename U, template <typename...> class T, typename... Ts>
-inline constexpr bool is_template_instance_v = is_template_instance<U, T, Ts...>::value;
-
-template <typename T>
-using template_false_type = __helpers::template_false_type<T>;
-template <typename T>
-using template_true_type = __helpers::template_true_type<T>;
-
-#endif
-
-} // namespace std
-
-#endif

+ 0 - 185
gblibstdc++/include/utility

@@ -1,185 +0,0 @@
-#ifndef __GBLIBCPP_UTILITY__
-#define __GBLIBCPP_UTILITY__
-
-#include <cstddef>
-#include <bits/forward>
-#include <bits/sequence>
-#include <bits/tuple_tools>
-
-#include <type_traits>
-
-namespace std {
-
-template <typename T, typename U = T>
-constexpr T exchange(T& dst, U&& val)
-{
-    T tmp = move(dst);
-    dst = forward<U>(val);
-    return tmp;
-}
-
-template <typename T>
-constexpr void swap(T& a, T& b)
-{
-    T tmp(std::move(a));
-    a = std::move(b);
-    b = std::move(tmp);
-}
-
-struct piecewise_construct_t { explicit piecewise_construct_t() = default; };
-
-inline constexpr piecewise_construct_t piecewise_construct {};
-
-template <typename... Types>
-class tuple;
-
-template <typename T1, typename T2>
-struct pair;
-
-template <typename T1, typename T2>
-struct tuple_size<std::pair<T1, T2>>
-    : public std::integral_constant<std::size_t, 2> {};
-
-template <typename T1, typename T2>
-struct tuple_element<0, std::pair<T1, T2>> { using type = T1; };
-template <typename T1, typename T2>
-struct tuple_element<1, std::pair<T1, T2>> { using type = T2; };
-template <std::size_t I, typename T1, typename T2>
-struct tuple_element<I, std::pair<T1, T2>> {
-    static_assert(I < 2, "std::pair has only 2 elements");
-};
-
-template <typename T1, typename T2>
-struct pair {
-    using first_type = T1;
-    using second_type = T2;
-
-    T1 first;
-    T2 second;
-
-    template <typename U1 = T1, typename U2 = T2, std::enable_if_t<
-        std::is_default_constructible_v<U1>
-        && std::is_default_constructible_v<U2>
-    , bool> = true>
-    constexpr pair() : first(), second() {}
-
-    template <typename U1 = T1, typename U2 = T2, std::enable_if_t<
-        std::is_copy_constructible_v<U1>
-        && std::is_copy_constructible_v<U2>
-    , bool> = true>
-    constexpr pair(const T1& t1, const T2& t2)
-        : first(t1), second(t2) {}
-
-    template <typename U1, typename U2, std::enable_if_t<
-        std::is_constructible_v<T1, U1> && std::is_constructible_v<T2, U2>
-    , bool> = true>
-    constexpr pair(U1&& t1, U2&& t2)
-        : first(std::forward<U1>(t1))
-        , second(std::forward<U2>(t2)) {}
-
-    template <typename U1, typename U2, std::enable_if_t<
-        std::is_constructible_v<T1, const U1&>
-        && std::is_constructible_v<T2, const U2&>
-    , bool> = true>
-    constexpr pair(const pair<U1, U2>& p)
-        : first(p.first) , second(p.second) {}
-
-    template <typename U1, typename U2, std::enable_if_t<
-        std::is_constructible_v<T1, U1>
-        && std::is_constructible_v<T2, U2>
-    , bool> = true>
-    constexpr pair(pair<U1, U2>&& p)
-        : first(std::forward<U1>(p.first))
-        , second(std::forward<U2>(p.second)) {}
-
-    template <typename... Args1, typename... Args2>
-    constexpr pair(std::piecewise_construct_t,
-        std::tuple<Args1...> first_args,
-        std::tuple<Args2...> second_args)
-        : first(std::make_from_tuple<T1>(std::move(first_args)))
-        , second(std::make_from_tuple<T2>(std::move(second_args))) {}
-
-    constexpr pair(const pair&) = default;
-    constexpr pair(pair&&) = default;
-
-    constexpr pair& operator=(const pair& other) = default;
-    constexpr pair& operator=(pair&& other) = default;
-
-    template <typename U1, typename U2, std::enable_if_t<
-        std::is_assignable_v<T1&, const U1&>
-        && std::is_assignable_v<T2&, const U2&>
-    , bool> = true>
-    constexpr pair& operator=(const pair<U1, U2>& other)
-    {
-        first = other.first;
-        second = other.second;
-        return *this;
-    }
-
-    template <typename U1, typename U2, std::enable_if_t<
-        std::is_assignable_v<T1&, U1>
-        && std::is_assignable_v<T2&, U2>
-    , bool> = true>
-    constexpr pair& operator=(pair<U1, U2>&& other)
-    {
-        first = std::forward<U1>(other.first);
-        second = std::forward<U2>(other.second);
-        return *this;
-    }
-
-    constexpr void swap(pair& other)
-    {
-        std::swap(first, other.first);
-        std::swap(second, other.second);
-    }
-};
-
-template <typename T1, typename T2>
-pair(T1, T2) -> pair<T1, T2>;
-
-template <typename T1, typename T2>
-constexpr auto make_pair(T1&& t1, T2&& t2)
-    -> std::pair<__helpers::to_tuple_type_t<T1>, __helpers::to_tuple_type_t<T2>>
-{
-    return { std::forward<T1>(t1), std::forward<T2>(t2) };
-}
-
-template <std::size_t I, typename T1, typename T2>
-constexpr auto get(std::pair<T1, T2>& p) noexcept
-    -> std::tuple_element_t<I, std::pair<T1, T2>>&
-{
-    if constexpr (I == 0) return p.first;
-    else return p.second;
-}
-template <std::size_t I, typename T1, typename T2>
-constexpr auto get(std::pair<T1, T2>&& p) noexcept
-    -> std::tuple_element_t<I, std::pair<T1, T2>>&&
-{
-    if constexpr (I == 0) return std::forward<T1>(p.first);
-    else return std::forward<T2>(p.second);
-}
-template <std::size_t I, typename T1, typename T2>
-constexpr auto get(const std::pair<T1, T2>& p) noexcept
-    -> std::tuple_element_t<I, std::pair<T1, T2>> const&
-{
-    if constexpr (I == 0) return p.first;
-    else return p.second;
-}
-template <std::size_t I, typename T1, typename T2>
-constexpr auto get(const std::pair<T1, T2>&& p) noexcept
-    -> std::tuple_element_t<I, std::pair<T1, T2>> const&&
-{
-    if constexpr (I == 0) return std::forward<T1>(p.first);
-    else return std::forward<T2>(p.second);
-}
-
-template <typename T1, typename T2>
-constexpr void swap(std::pair<T1, T2>& lhs, std::pair<T1, T2>& rhs)
-    noexcept(noexcept(lhs.swap(rhs)))
-{
-    lhs.swap(rhs);
-}
-
-} // namespace std
-
-#endif

+ 0 - 502
gblibstdc++/include/vector

@@ -1,502 +0,0 @@
-#ifndef __GBLIBCPP_VECTOR__
-#define __GBLIBCPP_VECTOR__
-
-#include <bits/iter_ops>
-#include <bits/compressed_pair>
-
-#include <functional>
-#include <memory>
-#include <initializer_list>
-#include <cstddef>
-
-namespace std {
-
-template <typename T, typename Allocator = std::allocator<T>>
-class vector {
-public:
-    using value_type = T;
-    using allocator_type = Allocator;
-    using size_type = std::size_t;
-    using difference_type = std::ptrdiff_t;
-    using reference = T&;
-    using const_reference = const T&;
-
-    template <bool Const>
-    class _iterator {
-    public:
-        // TODO:
-        // using iterator_category = std::random_access_iterator_tag;
-        using value_type = std::conditional_t<Const, const T, T>;
-        using difference_type = std::ptrdiff_t;
-        using pointer = std::add_pointer_t<value_type>;
-        using reference = std::add_lvalue_reference_t<value_type>;
-
-    private:
-        T* m_ptr;
-
-    public:
-        constexpr _iterator(void) noexcept : m_ptr() {}
-        constexpr explicit _iterator(const T* ptr) noexcept
-            : m_ptr(const_cast<T*>(ptr)) {}
-        constexpr _iterator(const _iterator& other) noexcept = default;
-        constexpr _iterator(_iterator&& other) noexcept = default;
-        constexpr _iterator& operator=(const _iterator& other) noexcept = default;
-        constexpr _iterator& operator=(_iterator&& other) noexcept = default;
-        constexpr bool operator==(const _iterator& other) const noexcept = default;
-
-        constexpr reference operator*() const noexcept { return *m_ptr; }
-        constexpr pointer operator&() const noexcept
-        { return std::addressof(this->operator*()); }
-        constexpr pointer operator->() const noexcept
-        { return this->operator&(); }
-        constexpr _iterator& operator++() noexcept
-        { ++m_ptr; return *this; }
-        constexpr _iterator operator++(int) noexcept
-        { _iterator ret(m_ptr); (void)this->operator++(); return ret; }
-        constexpr _iterator& operator--(void) noexcept
-        { --m_ptr; return *this; }
-        constexpr _iterator operator--(int) noexcept
-        { _iterator ret(m_ptr); (void)this->operator--(); return ret; }
-        constexpr _iterator& operator+=(difference_type n) noexcept
-        { m_ptr += n; return *this; }
-        constexpr _iterator& operator-=(difference_type n) noexcept
-        { m_ptr -= n; return *this; }
-        constexpr _iterator operator+(difference_type n) const noexcept
-        { return _iterator { m_ptr + n }; }
-        constexpr _iterator operator-(difference_type n) const noexcept
-        { return _iterator { m_ptr - n }; }
-        constexpr difference_type operator-(const _iterator& other) const noexcept
-        { return m_ptr - other.m_ptr; }
-        constexpr reference operator[](difference_type n) const noexcept
-        { return m_ptr[n]; }
-        constexpr operator bool() { return m_ptr; }
-        constexpr operator _iterator<true>() { return _iterator<true> { m_ptr }; }
-        constexpr operator _iterator<false>() { return _iterator<false> { m_ptr }; }
-        constexpr operator const T*() { return m_ptr; }
-    };
-
-private:
-    using alloc_traits = std::allocator_traits<Allocator>;
-
-public:
-    using pointer = typename alloc_traits::pointer;
-    using const_pointer = typename alloc_traits::const_pointer;
-    using iterator = _iterator<false>;
-    using const_iterator = _iterator<true>;
-
-private:
-    impl::compressed_pair<T*, allocator_type> m_data;
-    size_type m_size;
-    size_type m_capacity;
-
-private:
-    constexpr allocator_type& _alloc() noexcept { return m_data.second(); }
-    constexpr const allocator_type& _alloc() const noexcept { return m_data.second(); }
-    constexpr T*& _data() noexcept { return m_data.first(); }
-    constexpr T* const& _data() const noexcept { return m_data.first(); }
-
-    // assert(n >= m_size)
-    constexpr void _reallocate_safe(size_type n)
-    {
-        T* newptr = nullptr;
-        if (n)
-            newptr = alloc_traits::allocate(_alloc(), n);
-
-        for (size_t i = 0; i < m_size; ++i) {
-            if (n)
-                alloc_traits::construct(_alloc(), newptr + i, std::move(_data()[i]));
-            alloc_traits::destroy(_alloc(), _data() + i);
-        }
-
-        alloc_traits::deallocate(_alloc(), _data(), m_capacity);
-        _data() = newptr;
-        m_capacity = n;
-    }
-
-    // make m_capacity >= n >= m_size
-    constexpr void _pre_resize(size_type n)
-    {
-        while (n < m_size)
-            pop_back();
-
-        reserve(n);
-    }
-
-public:
-    constexpr vector(void)
-        noexcept(noexcept(Allocator()))
-        : m_data{impl::default_construct_t{}}, m_size(), m_capacity() {}
-
-    constexpr explicit vector(const Allocator& alloc) noexcept
-        : m_data{nullptr, alloc}, m_size(), m_capacity() {}
-
-    constexpr vector(size_type n, const T& val,
-        const Allocator& alloc = Allocator())
-        : vector(alloc) { resize(n, val); }
-
-    constexpr explicit vector(size_type n,
-        const Allocator& alloc = Allocator())
-        : vector(alloc) { resize(n); }
-
-    // TODO: check whether InputIter satisfies LegacyInputIterator
-    template <typename InputIter>
-    constexpr vector(InputIter first, InputIter last,
-        const Allocator& alloc = Allocator())
-        : vector(alloc) { insert(cbegin(), first, last); }
-
-    constexpr vector(const vector& other)
-        : vector(std::allocator_traits<allocator_type>::
-            select_on_container_copy_construction(other._alloc()))
-    { insert(cbegin(), other.begin(), other.end()); }
-
-    constexpr vector(const vector& other, const Allocator& alloc)
-        : vector(alloc) { insert(cbegin(), other.begin(), other.end()); }
-
-    constexpr vector(vector&& other) noexcept
-        : m_data{std::exchange(other._data(), nullptr), std::move(other._alloc())}
-        , m_size(std::exchange(other.m_size, 0))
-        , m_capacity(std::exchange(other.m_capacity, 0)) { }
-
-    constexpr vector(vector&& other, const Allocator& alloc)
-        : vector(alloc)
-    {
-        if (alloc == other._alloc()) {
-            _data() = std::exchange(other._data(), nullptr);
-            m_size = std::exchange(other.m_size, 0);
-            m_capacity = std::exchange(other.m_capacity, 0);
-        } else {
-            // TODO: std::move_iterator
-            // insert(cbegin(), std::make_move_iterator(other.begin()),
-            //     std::make_move_iterator(other.end()));
-            for (auto& item : other)
-                emplace_back(std::move(item));
-        }
-    }
-
-    constexpr vector(std::initializer_list<T> init,
-        const Allocator& alloc = Allocator())
-        : vector(alloc) { insert(cbegin(), init.begin(), init.end()); }
-
-    constexpr ~vector()
-    {
-        resize(0);
-        shrink_to_fit();
-    }
-
-    constexpr vector& operator=(const vector& other)
-    {
-        clear();
-
-        if constexpr (alloc_traits::
-            propagate_on_container_copy_assignment::value) {
-            if (_alloc() != other._alloc())
-                shrink_to_fit();
-            _alloc() = other._alloc();
-        }
-
-        insert(cbegin(), other.begin(), other.end());
-        return *this;
-    }
-
-    constexpr vector& operator=(vector&& other)
-    {
-        clear();
-
-        if constexpr (alloc_traits::
-            propagate_on_container_move_assignment::value) {
-            shrink_to_fit();
-            _alloc() = std::move(other._alloc());
-        }
-        else {
-            if (_alloc() != other._alloc()) {
-                // TODO: std::move_iterator
-                for (auto& item : other)
-                    emplace_back(std::move(item));
-                return *this;
-            }
-            shrink_to_fit();
-        }
-
-        _data() = std::exchange(other._data(), nullptr);
-        m_size = std::exchange(other.m_size, 0);
-        m_capacity = std::exchange(other.m_capacity, 0);
-        return *this;
-    }
-
-    constexpr vector& operator=(std::initializer_list<T> init)
-    {
-        assign(init.begin(), init.end());
-        return *this;
-    }
-
-    constexpr void assign(size_type n, const T& val)
-    {
-        clear();
-        resize(n, val);
-    }
-
-    // TODO: check whether InputIter satisfies LegacyInputIterator
-    template <typename InputIter>
-    constexpr void assign(InputIter first, InputIter last)
-    {
-        clear();
-        insert(cbegin(), first, last);
-    }
-    constexpr void assign(std::initializer_list<T> init)
-    {
-        clear();
-        insert(cbegin(), init.begin(), init.end());
-    }
-
-    constexpr allocator_type get_allocator(void) const noexcept
-    { return _alloc(); }
-
-    constexpr reference at(size_type pos)
-    {
-        // TODO: exceptions
-        // if (pos >= sz)
-        //     throw std::out_of_range("vector::at");
-        return _data()[pos];
-    }
-    constexpr const_reference at(size_type pos) const
-    {
-        // TODO: exceptions
-        // if (pos >= sz)
-        //     throw std::out_of_range("vector::at");
-        return _data()[pos];
-    }
-
-    constexpr reference operator[](size_type pos) noexcept
-    { return _data()[pos]; }
-    constexpr const_reference operator[](size_type pos) const noexcept
-    { return _data()[pos]; }
-
-    constexpr reference front() noexcept
-    { return _data()[0]; }
-    constexpr const_reference front() const noexcept
-    { return _data()[0]; }
-    constexpr reference back() noexcept
-    { return _data()[m_size - 1]; }
-    constexpr const_reference back() const noexcept
-    { return _data()[m_size - 1]; }
-
-    constexpr T* data(void) noexcept
-    { return _data(); }
-    constexpr const T* data(void) const noexcept
-    { return _data(); }
-
-    // TODO: std::reverse_iterator
-    constexpr iterator begin() noexcept
-    { return iterator { _data() }; }
-    constexpr const_iterator begin() const noexcept
-    { return const_iterator { _data() }; }
-    constexpr const_iterator cbegin() const noexcept
-    { return const_iterator { _data() }; }
-    constexpr iterator end() noexcept
-    { return iterator { _data() + m_size }; }
-    constexpr const_iterator end() const noexcept
-    { return const_iterator { _data() + m_size }; }
-    constexpr const_iterator cend() const noexcept
-    { return const_iterator { _data() + m_size }; }
-
-    [[nodiscard]] constexpr bool empty() const noexcept
-    { return m_size == 0; }
-    constexpr size_type size() const noexcept
-    { return m_size; }
-    constexpr size_type capacity() const noexcept
-    { return m_capacity; }
-
-    constexpr void reserve(size_type new_cap)
-    {
-        if (new_cap > m_capacity)
-            _reallocate_safe(new_cap);
-    }
-
-    constexpr void resize(size_type n)
-    {
-        _pre_resize(n);
-        while (n > m_size)
-            emplace_back();
-    }
-    constexpr void resize(size_type n, const value_type& value)
-    {
-        _pre_resize(n);
-        while (n > m_size)
-            emplace_back(value);
-    }
-
-    constexpr void shrink_to_fit()
-    {
-        if (m_size < m_capacity)
-            _reallocate_safe(m_size);
-    }
-    constexpr void clear() noexcept
-    { resize(0); }
-
-    template <typename... Args>
-    constexpr iterator emplace(const_iterator pos, Args&&... args)
-    {
-        size_type idx = pos - _data();
-
-        if (!_data())
-            reserve(1);
-
-        if (m_size == m_capacity)
-            reserve(m_capacity * 2);
-
-        for (size_type i = m_size; i > idx; --i)
-            alloc_traits::construct(_alloc(), _data() + i, std::move(_data()[i-1]));
-
-        alloc_traits::construct(_alloc(), _data() + idx,
-            std::forward<Args>(args)...);
-
-        ++m_size;
-        return iterator { _data() + idx };
-    }
-
-    constexpr iterator insert(const_iterator pos, T&& val)
-    { return emplace(pos, std::move(val)); }
-    constexpr iterator insert(const_iterator pos, const T& val)
-    { return emplace(pos, val); }
-
-    constexpr iterator insert(const_iterator pos, size_type n, const T& val)
-    {
-        if (!n)
-            return pos;
-
-        size_type idx = pos - _data();
-        if (!pos)
-            reserve(n);
-
-        if (m_size + n > m_capacity)
-            reserve(m_size + n);
-        for (size_type i = m_size + n - 1; i >= idx + n; --i)
-            alloc_traits::construct(_alloc(), _data() + i, std::move(_data()[i-n]));
-        for (size_type i = idx; i < idx + n; ++i)
-            alloc_traits::construct(_alloc(), _data() + i, val);
-        m_size += n;
-        return iterator { _data() + idx };
-    }
-
-    // TODO: LegacyInputIterator version of this
-    template <typename ForwardIter>
-    constexpr iterator insert(const_iterator pos,
-        ForwardIter first, ForwardIter last)
-    {
-        size_type idx = pos - _data();
-        size_type n = 0;
-
-        ForwardIter tmp = first;
-        while (tmp != last)
-            ++n, ++tmp;
-
-        if (!n)
-            return pos;
-
-        if (!pos)
-            reserve(n);
-
-        if (m_size + n > m_capacity)
-            reserve(m_size + n);
-        for (size_type i = m_size + n - 1; i >= idx + n; --i)
-            alloc_traits::construct(_alloc(), _data() + i, std::move(_data()[i-n]));
-        for (size_type i = idx; i < idx + n; ++i)
-            alloc_traits::construct(_alloc(), _data() + i, *first++);
-        m_size += n;
-        return iterator { _data() + idx };
-    }
-
-    constexpr iterator insert(const_iterator pos, std::initializer_list<T> init)
-    { return insert(pos, init.begin(), init.end()); }
-
-    constexpr iterator erase(const_iterator pos)
-    {
-        size_type idx = pos - _data();
-        alloc_traits::destroy(_alloc(), _data() + idx);
-        for (size_type i = idx; i < m_size - 1; ++i)
-            alloc_traits::construct(_alloc(), _data() + i, std::move(_data()[i+1]));
-        --m_size;
-        return iterator { _data() + idx };
-    }
-
-    constexpr iterator erase(const_iterator first, const_iterator last)
-    {
-        size_type n = last - first;
-        if (!n)
-            return last;
-
-        size_type idx = first - _data();
-        for (size_type i = idx; i < idx + n; ++i)
-            alloc_traits::destroy(_alloc(), _data() + i);
-
-        for (size_type i = idx; i < m_size - n; ++i)
-            _alloc().construct(_data() + i, std::move(_data()[i+n]));
-
-        m_size -= n;
-        return iterator { _data() + idx };
-    }
-
-    constexpr void push_back(const T& val) { insert(cend(), val); }
-    constexpr void push_back(T&& val) { insert(cend(), std::move(val)); }
-
-    template <typename... Args>
-    constexpr reference emplace_back(Args&&... args)
-    { return *emplace(cend(), std::forward<Args>(args)...); }
-
-    constexpr void pop_back() { erase(--cend()); }
-
-    constexpr void swap(vector& other) noexcept(
-        alloc_traits::propagate_on_container_swap::value
-        || alloc_traits::is_always_equal::value)
-    {
-        if (alloc_traits::propagate_on_container_swap::value)
-            std::swap(_alloc(), other.m_alloc);
-        std::swap(_data(), other.m_data);
-        std::swap(m_size, other.m_size);
-        std::swap(m_capacity, other.m_capacity);
-    }
-};
-
-template <typename T, typename Allocator>
-constexpr void swap(
-    std::vector<T, Allocator>& lhs,
-    std::vector<T, Allocator>& rhs) noexcept(noexcept(lhs.swap(rhs)))
-{ lhs.swap(rhs); }
-
-template <typename T, typename Allocator, typename U>
-constexpr typename std::vector<T, Allocator>::size_type
-erase(std::vector<T, Allocator>& vec, const U& value)
-{
-    typename std::vector<T, Allocator>::size_type n = 0;
-
-    for (auto iter = vec.begin(); iter != vec.end(); ) {
-        if (*iter == value) {
-            iter = vec.erase(iter);
-            ++n;
-        } else {
-            ++iter;
-        }
-    }
-    return n;
-}
-
-template <typename T, typename Allocator, typename Pred>
-constexpr typename std::vector<T, Allocator>::size_type
-erase_if(std::vector<T, Allocator>& vec, Pred pred)
-{
-    typename std::vector<T, Allocator>::size_type n = 0;
-
-    for (auto iter = vec.begin(); iter != vec.end(); ) {
-        if (pred(*iter)) {
-            iter = vec.erase(iter);
-            ++n;
-        } else {
-            ++iter;
-        }
-    }
-    return n;
-}
-
-} // namespace std
-
-#endif

+ 0 - 0
gblibstdc++/src/stdc++.cpp


+ 0 - 47
include/kernel/async/lock.hpp

@@ -1,47 +0,0 @@
-#pragma once
-
-#include <cstddef>
-
-#include <stdint.h>
-
-namespace kernel::async {
-
-using spinlock_t = unsigned long volatile;
-using lock_context_t = unsigned long;
-
-void init_spinlock(spinlock_t& lock);
-
-void spin_lock(spinlock_t& lock);
-void spin_unlock(spinlock_t& lock);
-
-lock_context_t spin_lock_irqsave(spinlock_t& lock);
-void spin_unlock_irqrestore(spinlock_t& lock, lock_context_t context);
-
-class mutex {
-   private:
-    spinlock_t m_lock;
-
-   public:
-    constexpr mutex() : m_lock{0} {}
-    mutex(const mutex&) = delete;
-    ~mutex();
-
-    lock_context_t lock_irq();
-    void unlock_irq(lock_context_t state);
-};
-
-class lock_guard_irq {
-   private:
-    mutex& m_mtx;
-    lock_context_t state;
-
-   public:
-    explicit inline lock_guard_irq(mutex& mtx) : m_mtx{mtx} {
-        state = m_mtx.lock_irq();
-    }
-    lock_guard_irq(const lock_guard_irq&) = delete;
-
-    inline ~lock_guard_irq() { m_mtx.unlock_irq(state); }
-};
-
-} // namespace kernel::async

+ 0 - 102
include/kernel/mem/paging.hpp

@@ -1,102 +0,0 @@
-#pragma once
-
-#include <cstddef>
-#include <tuple>
-
-#include <stdint.h>
-
-#include <kernel/mem/paging_asm.h>
-#include <kernel/mem/phys.hpp>
-
-namespace kernel::mem::paging {
-
-constexpr int idx_p5(uintptr_t vaddr) noexcept {
-    return (vaddr >> 48) & 0x1ff;
-}
-constexpr int idx_p4(uintptr_t vaddr) noexcept {
-    return (vaddr >> 39) & 0x1ff;
-}
-constexpr int idx_p3(uintptr_t vaddr) noexcept {
-    return (vaddr >> 30) & 0x1ff;
-}
-constexpr int idx_p2(uintptr_t vaddr) noexcept {
-    return (vaddr >> 21) & 0x1ff;
-}
-constexpr int idx_p1(uintptr_t vaddr) noexcept {
-    return (vaddr >> 12) & 0x1ff;
-}
-
-constexpr std::tuple<int, int, int, int, int> idx_all(uintptr_t vaddr) noexcept {
-    return {idx_p5(vaddr), idx_p4(vaddr), idx_p3(vaddr), idx_p2(vaddr), idx_p1(vaddr)};
-}
-
-// page frame number
-// since we have large pages now, pfns are not shifted right
-using pfn_t = uintptr_t;
-
-// paging structure attributes
-using psattr_t = uintptr_t;
-
-constexpr psattr_t PA_DATA = PA_P | PA_RW | PA_NXE;
-constexpr psattr_t PA_KERNEL_DATA = PA_DATA | PA_G;
-constexpr psattr_t PA_USER_DATA = PA_DATA | PA_G | PA_US;
-
-constexpr psattr_t PA_PAGE_TABLE = PA_P | PA_RW;
-constexpr psattr_t PA_KERNEL_PAGE_TABLE = PA_PAGE_TABLE | PA_G;
-
-constexpr psattr_t PA_DATA_HUGE = PA_DATA | PA_PS;
-constexpr psattr_t PA_KERNEL_DATA_HUGE = PA_DATA_HUGE | PA_G;
-constexpr psattr_t PA_USER_DATA_HUGE = PA_DATA_HUGE | PA_US;
-
-namespace __inner {
-    using pse_t = uint64_t;
-
-} // namespace __inner
-
-class PSE {
-    physaddr<__inner::pse_t> m_ptrbase;
-
-   public:
-    explicit constexpr PSE(uintptr_t pptr) noexcept : m_ptrbase{pptr} {}
-
-    constexpr void clear() noexcept { *m_ptrbase = 0; }
-
-    constexpr void set(psattr_t attributes, pfn_t pfn) {
-        *m_ptrbase = (attributes & PA_MASK) | (pfn & ~PA_MASK);
-    }
-
-    constexpr pfn_t pfn() const noexcept { return *m_ptrbase & ~PA_MASK; }
-
-    constexpr psattr_t attributes() const noexcept { return *m_ptrbase & PA_MASK; }
-
-    constexpr PSE operator[](std::size_t nth) const noexcept {
-        return PSE{m_ptrbase.phys() + 8 * nth};
-    }
-
-    constexpr PSE parse() const noexcept { return PSE{*m_ptrbase & ~PA_MASK}; }
-};
-
-constexpr physaddr<void> KERNEL_PAGE_TABLE_PHYS_ADDR{KERNEL_PML4};
-constexpr PSE KERNEL_PAGE_TABLE{KERNEL_PML4};
-
-constexpr unsigned long PAGE_PRESENT = 0x00010000;
-constexpr unsigned long PAGE_BUDDY = 0x00020000;
-constexpr unsigned long PAGE_SLAB = 0x00040000;
-
-constexpr unsigned long PAGE_FAULT_P = 0x00000001;
-constexpr unsigned long PAGE_FAULT_W = 0x00000002;
-constexpr unsigned long PAGE_FAULT_U = 0x00000004;
-constexpr unsigned long PAGE_FAULT_R = 0x00000008;
-constexpr unsigned long PAGE_FAULT_I = 0x00000010;
-constexpr unsigned long PAGE_FAULT_PK = 0x00000020;
-constexpr unsigned long PAGE_FAULT_SS = 0x00000040;
-constexpr unsigned long PAGE_FAULT_SGX = 0x00008000;
-
-} // namespace kernel::mem::paging
-
-struct Page;
-
-extern "C" Page* c_alloc_page();
-extern "C" Page* c_alloc_pages(uint32_t order);
-extern "C" uintptr_t c_alloc_page_table();
-extern "C" uintptr_t page_to_pfn(Page* page);

+ 0 - 25
include/kernel/mem/paging_asm.h

@@ -1,25 +0,0 @@
-#define KERNEL_IMAGE_PADDR 0x400000
-#define KERNEL_PML4 0x001000
-#define KERNEL_PDPT_PHYS_MAPPING 0x002000
-#define KERNEL_PDPT_KERNEL_SPACE 0x003000
-#define KERNEL_PD_KIMAGE 0x004000
-#define KERNEL_PT_KIMAGE 0x005000
-#define KERNEL_PD_STRUCT_PAGE_ARR 0x006000
-#define KERNEL_STAGE1_PADDR 0x007000
-
-#define KERNEL_BSS_HUGE_PAGE 0x200000
-
-#define PA_P 0x0000000000000001
-#define PA_RW 0x0000000000000002
-#define PA_US 0x0000000000000004
-#define PA_PWT 0x0000000000000008
-#define PA_PCD 0x0000000000000010
-#define PA_A 0x0000000000000020
-#define PA_D 0x0000000000000040
-#define PA_PS 0x0000000000000080
-#define PA_G 0x0000000000000100
-#define PA_COW 0x0000000000000200
-#define PA_MMAP 0x0000000000000400
-#define PA_ANON 0x0000000000000800
-#define PA_NXE 0x8000000000000000
-#define PA_MASK 0xfff0000000000fff

+ 0 - 34
include/kernel/mem/phys.hpp

@@ -1,34 +0,0 @@
-#pragma once
-
-#include <bit>
-#include <cstddef>
-#include <type_traits>
-
-#include <stdint.h>
-
-#include <types/types.h>
-
-namespace kernel::mem {
-
-template <typename T, bool Cached = true>
-class physaddr {
-    static constexpr uintptr_t PHYS_OFFSET = Cached ? 0xffffff0000000000ULL : 0xffffff4000000000ULL;
-
-    uintptr_t m_ptr;
-
-   public:
-    explicit constexpr physaddr(uintptr_t ptr) : m_ptr{ptr} {}
-    explicit constexpr physaddr(std::nullptr_t) : m_ptr{} {}
-
-    // cast to non-pointer types is prohibited
-    template <typename U, typename = std::enable_if_t<std::is_pointer_v<U>>>
-    constexpr U cast_to() const noexcept {
-        return std::bit_cast<U>(m_ptr + PHYS_OFFSET);
-    }
-
-    constexpr operator T*() const noexcept { return cast_to<T*>(); }
-    constexpr T* operator->() const noexcept { return *this; }
-    constexpr uintptr_t phys() const noexcept { return m_ptr; }
-};
-
-} // namespace kernel::mem

+ 0 - 37
include/kernel/mem/slab.hpp

@@ -1,37 +0,0 @@
-#pragma once
-
-#include <cstddef>
-#include <type_traits>
-
-#include <stdint.h>
-
-namespace kernel::mem {
-
-struct slab_cache;
-
-struct slab_head {
-    slab_cache* cache;
-
-    slab_head* next;
-    slab_head* prev;
-
-    void* free;
-
-    unsigned int free_count;
-    unsigned int obj_size;
-};
-
-struct slab_cache {
-    slab_head* slabs_empty;
-    slab_head* slabs_partial;
-    slab_head* slabs_full;
-
-    std::size_t obj_size;
-};
-
-void init_slab_cache(slab_cache* cache, std::size_t obj_size);
-
-void* slab_alloc(slab_cache* cache);
-void slab_free(void* ptr);
-
-} // namespace kernel::mem

+ 0 - 37
include/types/allocator.hpp

@@ -1,37 +0,0 @@
-#pragma once
-#include <cstddef>
-
-#include <types/types.h>
-
-#include <kernel/async/lock.hpp>
-
-namespace types::memory {
-
-class brk_memory_allocator {
-   public:
-    using byte = std::byte;
-    using size_type = std::size_t;
-
-   private:
-    byte* p_start;
-    byte* p_limit;
-    byte* p_break;
-    byte* p_allocated;
-    kernel::async::mutex mtx;
-
-    byte* brk(byte* addr);
-    byte* sbrk(size_type increment);
-
-    constexpr byte* sbrk() const noexcept { return p_break; }
-
-   public:
-    explicit brk_memory_allocator(byte* start, size_type size);
-    brk_memory_allocator(const brk_memory_allocator&) = delete;
-
-    void* allocate(size_type size);
-    void deallocate(void* ptr);
-
-    bool allocated(void* ptr) const noexcept;
-};
-
-} // namespace types::memory

+ 0 - 46
include/types/list.hpp

@@ -1,46 +0,0 @@
-#pragma once
-
-namespace types::list {
-
-template <typename ListNode>
-void list_insert(ListNode** head, ListNode* node) {
-    node->prev = nullptr;
-    node->next = *head;
-    if (*head)
-        (*head)->prev = node;
-    *head = node;
-}
-
-template <typename ListNode>
-ListNode* list_get(ListNode** head) {
-    ListNode* node = *head;
-    if (node) {
-        *head = node->next;
-        if (*head)
-            (*head)->prev = nullptr;
-
-        node->next = nullptr;
-        node->prev = nullptr;
-    }
-    return node;
-}
-
-template <typename ListNode>
-void list_remove(ListNode** head, ListNode* node) {
-    if (node == *head) {
-        assert(!node->prev);
-        *head = node->next;
-    }
-    else {
-        assert(node->prev);
-        node->prev->next = node->next;
-    }
-
-    if (node->next)
-        node->next->prev = node->prev;
-
-    node->next = nullptr;
-    node->prev = nullptr;
-}
-
-} // namespace types::list

+ 0 - 31
include/types/types.h

@@ -1,31 +0,0 @@
-#pragma once
-
-#include "stdint.h"
-
-#define __user
-
-#ifdef __GNUC__
-#define NORETURN __attribute__((noreturn))
-#else
-#error "no definition for ((NORETURN))"
-#endif
-
-#ifdef __GNUC__
-#define SECTION(x) __attribute__((section(x)))
-#else
-#error "no definition for ((SECTION))"
-#endif
-
-#ifdef __GNUC__
-#define PACKED __attribute__((__packed__))
-#else
-#error "no definition for ((PACKED))"
-#endif
-
-#ifdef __GNUC__
-#define likely(expr) (__builtin_expect(!!(expr), 1))
-#define unlikely(expr) (__builtin_expect(!!(expr), 0))
-#else
-#define likely(expr) (!!(expr))
-#define unlikely(expr) (!!(expr))
-#endif

+ 0 - 1
rust-headers.hpp

@@ -1,4 +1,3 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <sys/stat.h>
-#include <kernel/mem/paging_asm.h>

+ 0 - 339
src/boot.s

@@ -1,339 +0,0 @@
-.section .stage1
-
-#include <kernel/mem/paging_asm.h>
-
-.code16
-
-.Lhalt:
-    hlt
-    jmp .
-
-# scratch %eax
-# return address should be of 2 bytes, and will be zero extended to 4 bytes
-go_32bit:
-    cli
-    # borrow the null entry from the early gdt
-    lidt EARLY_GDT
-
-    # set PE bit
-    mov %cr0, %eax
-    or $1, %eax
-    mov %eax, %cr0
-
-    ljmp $0x18, $.Lgo_32bit0
-
-.Lgo_16bit0:
-    mov $0x30, %ax
-    mov %ax, %ds
-    mov %ax, %es
-    mov %ax, %ss
-
-    lidt BIOS_IDT_DESCRIPTOR
-
-    mov %cr0, %eax
-    and $0xfffffffe, %eax
-    mov %eax, %cr0
-
-    ljmp $0x00, $2f
-
-2:
-    xor %ax, %ax
-    mov %ax, %ds
-    mov %ax, %ss
-    mov %ax, %es
-
-    sti
-
-    pop %eax
-    push %ax
-    ret
-
-.code32
-# scratch %eax
-# return address should be of 4 bytes, and extra 2 bytes will be popped from the stack
-go_16bit:
-    cli
-    ljmp $0x28, $.Lgo_16bit0
-
-.Lgo_32bit0:
-    mov $0x20, %ax
-    mov %ax, %ds
-    mov %ax, %es
-    mov %ax, %ss
-
-    pop %ax
-    movzw %ax, %eax
-    push %eax
-    ret
-
-# build read disk packet on the stack and perform read operation
-#
-# read 16k to 0x8000 and then copy to destination
-#
-# %edi: lba start
-# %esi: destination
-.code32
-read_disk:
-    push %ebp
-    mov %esp, %ebp
-
-    lea -24(%esp), %esp
-
-    mov $0x00200010, %eax # packet size 0, sector count 64
-    mov %eax, (%esp)
-
-    mov $0x08000000, %eax # destination address 0x0800:0x0000
-    mov %eax, 4(%esp)
-
-    mov %edi, 8(%esp)  # lba low 4bytes
-
-    xor %eax, %eax
-    mov %eax, 12(%esp) # lba high 2bytes
-
-    mov %esi, %edi
-    mov %esp, %esi # packet address
-
-    call go_16bit
-.code16
-    mov $0x42, %ah
-    mov $0x80, %dl
-    int $0x13
-    jc .Lhalt
-
-    call go_32bit
-.code32
-    # move data to destination
-    mov $0x8000, %esi
-    mov $4096, %ecx
-    rep movsl
-
-    mov %ebp, %esp
-    pop %ebp
-    ret
-
-.align 8
-.Lgdt_data:
-    .8byte 0x00209a0000000000 # 64bit code selector
-    .8byte 0x0000920000000000 # 64bit data selector
-    .8byte 0x00cf9a000000ffff # 32bit code selector
-    .8byte 0x00cf92000000ffff # 32bit data selector
-    .8byte 0x000f9a000000ffff # 16bit code selector
-    .8byte 0x000f92000000ffff # 16bit data selector
-
-.globl start_32bit
-start_32bit:
-    mov $0x10, %ax
-    mov %ax, %ds
-    mov %ax, %es
-    mov %ax, %ss
-
-    mov $EARLY_GDT_DESCRIPTOR, %edi
-    mov $0x37, %ax
-    mov %ax, (%edi)
-
-    mov $EARLY_GDT, %eax
-    mov %eax, 2(%edi)
-
-    # fill in early kernel GDT
-    xchg %eax, %edi
-    xor %eax, %eax
-    mov $2, %ecx
-
-    # null segment
-    rep stosl
-
-    # other data
-    mov $.Lgdt_data, %esi
-    mov $12, %ecx
-
-    rep movsl
-
-    lgdt EARLY_GDT_DESCRIPTOR
-    ljmp $0x18, $2f
-
-2:
-    mov $0x20, %ax
-    mov %ax, %ds
-    mov %ax, %es
-    mov %ax, %ss
-
-    # temporary kernel stack
-    mov $0x1000, %esp
-
-    # read kimage into memory
-	lea -16(%esp), %esp
-    mov $KIMAGE_32K_COUNT, %ecx
-    shl $1, %ecx
-    movl $KERNEL_IMAGE_PADDR, 4(%esp) # destination address
-	movl $9, (%esp) # LBA
-
-2:
-	mov (%esp), %edi
-	mov 4(%esp), %esi
-
-	mov %ecx, %ebx
-    call read_disk
-	mov %ebx, %ecx
-
-    addl $0x4000, 4(%esp)
-	addl $32, (%esp)
-
-    loop 2b
-
-	lea 16(%esp), %esp
-
-    cld
-    xor %eax, %eax
-
-    # clear paging structures
-    mov $0x1000, %edi
-    mov $0x6000, %ecx
-    shr $2, %ecx # %ecx /= 4
-    rep stosl
-
-    # set P, RW, G
-    mov $(PA_P | PA_RW | PA_G), %ebx
-    xor %edx, %edx
-    mov $KERNEL_PDPT_PHYS_MAPPING, %esi
-
-    # PML4E 0x000
-    # we need the first 1GB identically mapped
-    # so that we won't trigger a triple fault after
-    # enabling paging
-    mov $KERNEL_PML4, %edi
-    call fill_pxe
-
-    # PML4E 0xff0
-    mov $(PA_NXE >> 32), %edx
-    lea 0xff0(%edi), %edi
-    call fill_pxe
-    xor %edx, %edx
-
-    # setup PDPT for physical memory mapping
-    mov $KERNEL_PDPT_PHYS_MAPPING, %edi
-
-    # set PS
-    or $PA_PS, %ebx
-    mov $256, %ecx
-    xor %esi, %esi
-2:
-    call fill_pxe
-    lea 8(%edi), %edi
-    add $0x40000000, %esi # 1GB
-    adc $0, %edx
-    loop 2b
-
-    mov $(PA_NXE >> 32), %edx
-
-    # set PCD, PWT
-    or $(PA_PCD | PA_PWT), %ebx
-    mov $256, %ecx
-    xor %esi, %esi
-2:
-    call fill_pxe
-    lea 8(%edi), %edi
-    add $0x40000000, %esi # 1GB
-    adc $0, %edx
-    loop 2b
-
-    xor %edx, %edx
-
-    # PML4E 0xff8
-    mov $KERNEL_PDPT_KERNEL_SPACE, %esi
-    mov $KERNEL_PML4, %edi
-    lea 0xff8(%edi), %edi
-    # clear PCD, PWT, PS
-    and $(~(PA_PCD | PA_PWT | PA_PS)), %ebx
-    call fill_pxe
-
-    # PDPTE 0x008
-    mov $KERNEL_PDPT_KERNEL_SPACE, %edi
-    lea 0x8(%edi), %edi
-    mov $KERNEL_PD_STRUCT_PAGE_ARR, %esi
-    call fill_pxe
-
-    # PDPTE 0xff8
-    lea 0xff0(%edi), %edi
-    mov $KERNEL_PD_KIMAGE, %esi
-    call fill_pxe
-
-    # PDE 0xff0
-    mov $KERNEL_PD_KIMAGE, %edi
-    lea 0xff0(%edi), %edi
-    mov $KERNEL_PT_KIMAGE, %esi # 0x104000
-    call fill_pxe
-
-    # fill PT (kernel image)
-    mov $KERNEL_PT_KIMAGE, %edi
-    mov $KERNEL_IMAGE_PADDR, %esi
-
-    mov $KIMAGE_PAGES, %ecx
-
-2:
-    call fill_pxe
-    lea 8(%edi), %edi
-    lea 0x1000(%esi), %esi
-    loop 2b
-
-    # set msr
-    mov $0xc0000080, %ecx
-    rdmsr
-    or $0x901, %eax # set LME, NXE, SCE
-    wrmsr
-
-    # set cr4
-    mov %cr4, %eax
-    or $0xa0, %eax # set PAE, PGE
-    mov %eax, %cr4
-
-    # load new page table
-    mov $KERNEL_PML4, %eax
-    mov %eax, %cr3
-
-    mov %cr0, %eax
-    // SET PE, WP, PG
-    or $0x80010001, %eax
-    mov %eax, %cr0
-
-    ljmp $0x08, $2f
-
-# %ebx: attribute low
-# %edx: attribute high
-# %esi: page physical address
-# %edi: page x entry address
-fill_pxe:
-    lea (%ebx, %esi, 1), %eax
-    mov %eax, (%edi)
-    mov %edx, 4(%edi)
-
-    ret
-
-.code64
-2:
-    jmp 2f
-
-.section .text
-2:
-    mov $0x10, %ax
-    mov %ax, %ds
-    mov %ax, %es
-    mov %ax, %ss
-
-    # load kernel identically mapped base address
-    mov $0xffffff, %rax
-    shl $40, %rax
-
-    # place the stack at physical address 0x80000
-    mov $0x80000, %rsp
-    add %rax, %rsp
-
-    # clear the previous stack frame base, setting the return address to 0
-    xor %rbp, %rbp
-    push %rbp
-
-    # argument 1: the pointer to the bootloader data (paddr 0x0 + kernel space offset)
-    mov $E820_MEM_MAP_DATA, %rdi
-    add %rax, %rdi
-
-    # we use jmp instead of call since we've set the return address above
-    jmp _kernel_init