C++ 标准库头文件
2021-07-19 本文已影响0人
奇点创客
/*****************************************************************************
* FileName : stdc++.h
* Author : QiDianMaker
* Email : 1440657175@qq.com
* Description : C++ standard library header
* Create Date : 2020-04-14
*****************************************************************************/
#if defined(__clang__) || defined(__GNUC__)
#define CPP_STANDARD __cplusplus
#elif defined(_MSC_VER)
#define CPP_STANDARD _MSVC_LANG
#pragma warning(disable: 4996) // // 针对 VS, 使用 cstring 库函数不发出警告
#endif
#if CPP_STANDARD >= 199711L
#define HAS_CPP_03 1
#endif
#if CPP_STANDARD >= 201103L
#define HAS_CPP_11 1
#endif
#if CPP_STANDARD >= 201402L
#define HAS_CPP_14 1
#endif
#if CPP_STANDARD >= 201703L
#define HAS_CPP_17 1
#endif
#if CPP_STANDARD >= 202002L
#define HAS_CPP_20 1
#endif
/********************************* C++ 标准库 **********************************/
#if HAS_CPP_20
/* 概念库 **********************************************************************/
#include <concepts> /* 基础概念库 (C++20) */
/* 协程库 **********************************************************************/
#include <coroutine> /* 协程支持库 (C++20) */
#endif // HAS_CPP_20
/* 工具库 **********************************************************************/
#include <cstdlib> /* 通用工具:程序控制、动态内存分配、随机数、排序与搜索 */
#include <csignal> /* 信号管理的函数与宏常量 */
#include <csetjmp> /* 保存执行语境的宏,及跳转到某个执行语境的函数 */
#include <cstdarg> /* 变长实参列表的处理 */
#include <typeinfo> /* 运行时类型信息工具 */
#if HAS_CPP_11
#include <typeindex> /* std::type_index (C++11) */
#include <type_traits> /* 编译时类型信息 (C++11) */
#endif // HAS_CPP_11
#include <bitset> /* std::bitset 类模板 */
#include <functional> /* 函数对象、函数调用、绑定操作、引用包装 */
#include <utility> /* 多种工具组件 */
#include <ctime> /* C 风格的时间/日期工具 */
#if HAS_CPP_11
#include <chrono> /* C++ 时间工具 (C++11) */
#endif // HAS_CPP_11
#include <cstddef> /* 标准宏和 typedef */
#if HAS_CPP_11
#include <initializer_list> /* std::initializer_list 类模板 (C++11) */
#include <tuple> /* std::tuple 类模板 (C++11)*/
#endif // HAS_CPP_11
#if HAS_CPP_17
#include <any> /* std::any 类 (C++17) */
#include <optional> /* std::optional 类模板 (C++17) */
#include <variant> /* std::variant 类模板 (C++17) */
#endif // HAS_CPP_17
#if HAS_CPP_20
#include <compare> /* 三路比较运算符支持 (C++20) */
#include <version> /* 提供依赖于实现的库信息 (C++20) */
#include <source_location> /* 提供获得源码位置的手段 (C++20) */
#endif // HAS_CPP_20
//#include <stacktrace> /* 栈追踪 C++23 */
/* 工具库 **********************************************************************/
// 动态内存管理
#include <new> /* 低层内存管理工具 */
#include <memory> /* 高层内存管理工具 */
#if HAS_CPP_11
#include <scoped_allocator> /* 嵌套分配器类 (C++11) */
#endif // HAS_CPP_11
#if HAS_CPP_17
#include <memory_resource> /* 多态分配器及内存资源 (C++17) */
#endif // HAS_CPP_17
/* 数值界限 ********************************************************************/
#include <climits> /* 整型类型的界限 */
#include <cfloat> /* 浮点类型的界限 */
#if HAS_CPP_11
#include <cstdint> /* 定长整数及其他类型的界限 (C++11) */
#include <cinttypes> /* 格式化宏、[u]intmax_t 数学工具及转换 (C++11) */
#endif // HAS_CPP_11
#include <limits> /* 查询算术类型属性的标准化方式 */
/* 错误处理 ********************************************************************/
#include <exception> /* 异常处理工具 */
#include <stdexcept> /* 标准异常对象 */
#include <cassert> /* 将其实参与零比较的条件性编译宏 */
#if HAS_CPP_11
#include <system_error> /* 定义 std::error_code,依赖于平台的错误码 (C++11) */
#endif // HAS_CPP_11
#include <cerrno> /* 含有最近一次错误号的宏 */
/* 字符串库 ********************************************************************/
#include <cctype> /* 确定字符数据中所含类型的函数 */
#include <cwctype> /* 确定宽字符数据中所含类型的函数 */
#include <cstring> /* 多种窄字符串处理函数 */
#include <cwchar> /* 多种宽及多字节字符串处理函数 */
#if HAS_CPP_11
#include <cuchar> /* C 风格 Unicode 字符转换函数 (C++11) */
#endif // HAS_CPP_11
#include <string> /* std::basic_string 类模板 */
#if HAS_CPP_17
#include <string_view> /* std::basic_string_view 类模板 (C++17) */
#include <charconv> /* std::to_chars 与 std::from_chars (C++17)*/
#endif // HAS_CPP_17
#if HAS_CPP_20
#include <format> /* 格式化库,包括 std::format (C++20) */
#endif // HAS_CPP_20
/* 容器库 **********************************************************************/
#if HAS_CPP_11
#include <array> /* std::array 容器 (C++11) */
#endif // HAS_CPP_11
#include <vector> /* std::vector 容器 */
#include <deque> /* std::deque 容器 */
#include <list> /* std::list 容器 */
#if HAS_CPP_11
#include <forward_list> /* std::forward_list 容器 (C++11) */
#include <unordered_set> /* std::unordered_[multi]set 无序关联容器 (C++11) */
#include <unordered_map> /* std::unordered_[multi]map 无序关联容器 (C++11) */
#endif // HAS_CPP_11
#include <set> /* std::[multi]set 关联容器 */
#include <map> /* std::[multi]map 关联容器 */
#include <stack> /* std::stack 容器适配器 */
#include <queue> /* std::[priority_]queue 容器适配器 */
#if HAS_CPP_20
#include <span> /* std::span 视图 (C++20) */
#endif // HAS_CPP_20
/* 迭代器库*********************************************************************/
#include <iterator> /* 范围迭代器 */
/* 范围库 **********************************************************************/
#if HAS_CPP_20
#include <ranges> /* 范围访问、原语、要求、工具及适配器 (C++20) */
#endif // HAS_CPP_20
/* 算法库 **********************************************************************/
#include <algorithm> /* 对范围操作的算法 */
#if HAS_CPP_17
#include <execution> /* 针对算法的并行版本的预定义执行策略 (C++17) */
#endif // HAS_CPP_17
/* 数值库 **********************************************************************/
#include <cmath> /* 常用数学函数 */
#include <complex> /* 复数类型 */
#include <valarray> /* 表示和操作值的数组的类 */
#if HAS_CPP_11
#include <random> /* 随机数生成器及分布 (C++11) */
#include <ratio> /* 编译时有理数算术 (C++11) */
#include <cfenv> /* 浮点环境访问函数 (C++11) */
#endif // HAS_CPP_11
#include <numeric> /* 容器中值的数值运算 */
#if HAS_CPP_20
#include <bit> /* 位操纵函数 (C++20) */
#include <numbers> /* 数学常数 (C++20) */
#endif // HAS_CPP_20
/* 本地化库 ********************************************************************/
#include <locale> /* 本地化工具 */
#include <clocale> /* C 本地化工具 */
#if HAS_CPP_11
#include <codecvt> /* Unicode 转换设施 (C++11) (C++17) 中弃用 */
#endif // HAS_CPP_11
/* 输入/输出库 *****************************************************************/
#include <iosfwd> /* 所有输入/输出库中的类的前置声明 */
#include <ios> /* std::ios_base 类、std::basic_ios 类模板及数个 typedef */
#include <istream> /* std::basic_istream 类模板及数个 typedef */
#include <ostream> /* std::basic_[i]ostream 类模板及数个 typedef */
#include <iostream> /* 数个标准流对象 */
#include <fstream> /* std::basic_[i,o]fstream 类模板及数个 typedef */
#include <sstream> /* std::basic_[i,o]stringstream类模板及数个 typedef */
#if HAS_CPP_20
#include <syncstream> /* std::basic_osyncstream、std::basic_syncbuf 及 typedef (C++20) */
#endif // HAS_CPP_20
//#include <strstream> /* std::[i, o]strstream (C++98) 中弃用 */
#include <iomanip> /* 控制输入输出格式的辅助函数 */
#include <streambuf> /* std::basic_streambuf 类模板 */
#include <cstdio> /* C 风格输入输出函数 */
/* 文件系统库*******************************************************************/
#if HAS_CPP_17
#include <filesystem> /* std::path 类及支持函数 (C++17) */
#endif // HAS_CPP_17
#if HAS_CPP_11
/* 正则表达式库 ****************************************************************/
#include <regex> /* 支持正则表达式处理的类、算法及迭代器 (C++11) */
/* 原子操作库 ******************************************************************/
#include <atomic> /* 原子操作库 (C++11) */
#endif // HAS_CPP_11
/* 线程支持库 ******************************************************************/
#if HAS_CPP_11
#include <thread> /* std::thread 类及支持函数 (C++11) */
#include <mutex> /* 互斥元件 (C++11) */
#include <future> /* 异步计算的元件 (C++11) */
#include <condition_variable> /* 线程等待条件 (C++11) */
#endif // HAS_CPP_11
#if HAS_CPP_14
#include <shared_mutex> /* 共享的互斥元件 (C++14) */
#endif // HAS_CPP_14
#if HAS_CPP_20
#include <semaphore> /* 信号量 (C++20) */
#include <latch> /* 闩 (C++20) */
#include <barrier> /* 屏障 (C++20) */
#include <stop_token> /* std::jthread 的停止记号 (C++20) */
#endif // HAS_CPP_20
/********************************** 第三方库 **********************************/
// Boost -- C++ 准标准库
//#include <boost/asio.hpp>
//#include <boost/type_index.hpp>
// OpenCV -- 开源计算机视觉库
#ifdef _WIN64
//#include <opencv2/opencv.hpp>
#endif
/******************************** 有用的自造组件 ******************************/
#include "output_container.hpp" // 输出容器
#if HAS_CPP_20
// 通用打印函数
template<typename... U>
void print(U&&... u)
{
using std::cout, std::endl, std::forward;
size_t i{0};
auto printer = [&i](auto&& arg) {
sizeof...(U) != ++i ? cout << forward<decltype(arg)>(arg) << " "
: cout << forward<decltype(arg)>(arg) << endl;
};
(printer(u), ...);
}
// split 函数
template<typename Container = std::vector<std::string_view>>
Container split(const std::string_view sv, const std::string_view delim = " ")
{
using std::views::split, std::views::transform, std::ranges::distance;
using std::string_view, std::addressof, std::inserter;
Container ret;
auto view = sv | split(delim) | transform([](auto&& rng) {
return string_view(addressof(*rng.begin()), distance(rng));
});
auto ins = inserter(ret, ret.end());
for (auto&& e : view)
ins = { e.begin(), e.end() };
return ret;
}
#endif // HAS_CPP_20
/********************************** 常用组件 **********************************/
using std::cout;
using std::cin;
using std::endl;
#if HAS_CPP_20
using std::span;
using std::format;
#endif // HAS_CPP_20
#if HAS_CPP_11
using std::array;
#endif // HAS_CPP_11
using std::vector;
using std::string;
#if HAS_CPP_11
using namespace std::chrono;
#endif // HAS_CPP_11
#if HAS_CPP_14
using namespace std::string_literals;
using namespace std::chrono_literals;
#endif // HAS_CPP_14
#if HAS_CPP_17
using namespace std::string_view_literals;
namespace fs = std::filesystem;
#endif // HAS_CPP_17
#if HAS_CPP_20
namespace rg = std::ranges;
#endif // HAS_CPP_20