vs2022 cpp <yvals_core.h> 文件注释

比较重要的一点是STL内部很多函数已经使用了并行算法
可以考虑参考STL内部的并行算法实现方式来改进代码


//#include   注释
// yvals_core.h internal header (core) 内部头文件(核心)
#ifndef _STL_COMPILER_PREPROCESSOR //STL编译器预处理器
// All STL headers avoid exposing their contents when included by various
// non-C++-compiler tools to avoid breaking builds when we use newer language
// features in the headers than such tools understand.
//所有STL标头在被各种非C++编译器工具包含时都避免暴露其内容,
//以避免在标头中使用比这些工具所理解的更新的语言功能时破坏构建。
#if defined(RC_INVOKED) || defined(Q_MOC_RUN) || defined(__midl)
#define _STL_COMPILER_PREPROCESSOR 0
#else
#define _STL_COMPILER_PREPROCESSOR 1
#endif
#endif // _STL_COMPILER_PREPROCESSOR

#if _STL_COMPILER_PREPROCESSOR
//如果未定义__cplusplus就编译期报错
#ifndef __cplusplus
#define _STL_STRINGIZE_(S) #S
#define _STL_STRINGIZE(S)  _STL_STRINGIZE_(S)
#pragma message(__FILE__ "(" _STL_STRINGIZE(__LINE__) "): STL1003: Unexpected compiler, expected C++ compiler.")
#error Error in C++ Standard Library usage //C++ 标准库使用错误
#endif // __cplusplus

// Implemented unconditionally: 无条件实施
// N3911 void_t
// ...
// P2549R1 unexpected::error()

// Parallel Algorithms Notes 并行算法笔记
// C++ allows an implementation to implement parallel algorithms as calls to the serial algorithms.
// C++ 允许实现将并行算法实现为对串行算法的调用。
// This implementation parallelizes several common algorithm calls, but not all.
// 此实现并行化了几个常见的算法调用,但不是全部。
//
// std::execution::unseq has no direct analogue for any optimizer we target as of 2020-07-29,
// though we will map it to #pragma loop(ivdep) for the for_each algorithms only as these are the only algorithms where
// the library does not need to introduce inter-loop-body dependencies to accomplish the algorithm's goals.
// std::execution::unseq 与我们从 2020 年 7 月 29 日起针对的任何优化器都没有直接类似物,
// 尽管我们将它映射到 for_each 算法的#pragma loop(ivdep),
// 因为这些是库中唯一的算法 不需要引入循环体间的依赖关系来实现算法的目标。
// **The following algorithms are parallelized. 以下算法是并行化的。**
// * adjacent_difference adjacent_find
// * all_of any_of count count_if equal exclusive_scan
// * sort stable_sort find find_end find_first_of find_if find_if_not
// * search search_n set_difference set_intersection
// * for_each for_each_n inclusive_scan is_heap is_heap_until
// * is_partitioned is_sorted is_sorted_until
// * mismatch none_of partition reduce
// * remove remove_if replace replace_if
// * transform transform_exclusive_scan transform_inclusive_scan transform_reduce
//
// The following are not presently parallelized: 以下内容目前未并行化:
// No apparent parallelism performance improvement on target hardware; all algorithms which
// merely copy or permute elements with no branches are typically memory bandwidth limited.
// 目标硬件上没有明显的并行性能改进; 所有算法仅复制或置换没有分支的元素通常会限制内存带宽。
// * copy copy_n fill fill_n
// * move reverse reverse_copy rotate rotate_copy
// * shift_left shift_right swap_ranges
// Confusion over user parallelism requirements exists; likely in the above category anyway.
// 存在对用户并行性要求的混淆; 无论如何都可能属于上述类别。
// * generate generate_n
//
// Effective parallelism suspected to be infeasible.有效并行被怀疑是不可行的。
// * partial_sort partial_sort_copy
//
// Not yet evaluated; parallelism may be implemented in a future release and is suspected to be beneficial.
// 尚未评估; 并行性可能会在未来的版本中实现,并且被认为是有益的。
// * copy_if includes inplace_merge lexicographical_compare
// * max_element merge min_element minmax_element nth_element
// * partition_copy remove_copy remove_copy_if replace_copy replace_copy_if
// * set_symmetric_difference set_union stable_partition unique unique_copy

#include 
#include  // The _HAS_CXX tags must be defined before including this.

// Note that _STL_PRAGMA is load-bearing; it still needs to exist even once CUDA and ICC support _Pragma.
// 注意_STL_PRAGMA是承重的; 即使 CUDA 和 ICC 支持 _Pragma,它仍然需要存在。(应该是用于编译告警)
#if defined(__CUDACC__) || defined(__INTEL_COMPILER)
#define _STL_PRAGMA(PRAGMA) __pragma(PRAGMA)
#else
#define _STL_PRAGMA(PRAGMA) _Pragma(#PRAGMA)
#endif
#define _STL_PRAGMA_MESSAGE(MESSAGE) _STL_PRAGMA(message(MESSAGE))
#define _EMIT_STL_MESSAGE(MESSAGE)   _STL_PRAGMA_MESSAGE(__FILE__ "(" _CRT_STRINGIZE(__LINE__) "): " MESSAGE)
#define _EMIT_STL_WARNING(NUMBER, MESSAGE) _EMIT_STL_MESSAGE("warning " #NUMBER ": " MESSAGE) static_assert(true, "") //级别低,继续编译
#define _EMIT_STL_ERROR(NUMBER, MESSAGE) _EMIT_STL_MESSAGE("error " #NUMBER ": " MESSAGE) static_assert(false, "Error in C++ Standard Library usage.")

#ifndef _STL_WARNING_LEVEL //告警等级,限制为3、4
#if defined(_MSVC_WARNING_LEVEL) && _MSVC_WARNING_LEVEL >= 4
#define _STL_WARNING_LEVEL 4
#else // defined(_MSVC_WARNING_LEVEL) && _MSVC_WARNING_LEVEL >= 4
#define _STL_WARNING_LEVEL 3
#endif // defined(_MSVC_WARNING_LEVEL) && _MSVC_WARNING_LEVEL >= 4
#endif // _STL_WARNING_LEVEL
#if _STL_WARNING_LEVEL < 3
#error _STL_WARNING_LEVEL cannot be less than 3.
#endif // _STL_WARNING_LEVEL < 3
#if _STL_WARNING_LEVEL > 4
#error _STL_WARNING_LEVEL cannot be greater than 4.
#endif // _STL_WARNING_LEVEL > 4

#ifndef __has_cpp_attribute //判断编译器是否有某种功能特性,后面省略类似代码
#define _FALLTHROUGH //switch case分支,指示从前一标号直落是有意的,而在发生直落时给出警告的编译器不应诊断它。
#elif __has_cpp_attribute(fallthrough) >= 201603L
#define _FALLTHROUGH [[fallthrough]] //展开成该属性被添加到工作草案中时的年份和月份
#else
#define _FALLTHROUGH
#endif

#ifndef _STL_DISABLED_WARNINGS  //各种编译告警控制,后面省略类似代码
#define _STL_DISABLED_WARNINGS  4180 ... _STL_EXTRA_DISABLED_WARNINGS
#endif // _STL_DISABLED_WARNINGS

#define _CPPLIB_VER       650
#define _MSVC_STL_VERSION 143
#define _MSVC_STL_UPDATE  202210L  //STL 版本信息

#ifndef _HAS_STATIC_RTTI
#define _HAS_STATIC_RTTI 1
#endif // _HAS_STATIC_RTTI

#if defined(_CPPRTTI) && !_HAS_STATIC_RTTI
#error /GR implies _HAS_STATIC_RTTI.
#endif // defined(_CPPRTTI) && !_HAS_STATIC_RTTI

// N4842 [dcl.constexpr]/1: "A function or static data member declared with the constexpr or consteval specifier is implicitly an inline function or variable"
// N4842 [dcl.constexpr]/1:“使用 constexpr 或 consteval 说明符声明的函数或静态数据成员隐式为内联函数或变量”
// Functions that became constexpr in C++17 在 C++17 中成为 constexpr 的函数
#if _HAS_CXX17 //_HAS_CXX20  _HAS_CXX23 类似
#define _CONSTEXPR17 constexpr  //_INLINE_VAR 类似
#else // ^^^ constexpr in C++17 and later / inline (not constexpr) in C++14 vvv
#define _CONSTEXPR17 inline
#endif // ^^^ inline (not constexpr) in C++14 ^^^

#ifdef __cpp_consteval //consteval constexpr 含义接近
#define _CONSTEVAL consteval
#else // ^^^ supports consteval / no consteval vvv
#define _CONSTEVAL constexpr
#endif // ^^^ no consteval ^^^

// P2465R3 Standard Library Modules std And std.compat 标准库模块 std 和 std.compat
#if _HAS_CXX23 && defined(_BUILD_STD_MODULE)
#define _EXPORT_STD export
#else // _HAS_CXX23 && defined(_BUILD_STD_MODULE)
#define _EXPORT_STD
#endif // _HAS_CXX23 && defined(_BUILD_STD_MODULE)

// N4190 Removing auto_ptr, random_shuffle(), And Old  Stuff 删除auto_ptr, random_shuffle()等
#ifndef _HAS_AUTO_PTR_ETC
#define _HAS_AUTO_PTR_ETC (!_HAS_CXX17)
#endif // _HAS_AUTO_PTR_ETC
// P0003R5 Removing Dynamic Exception Specifications 删除动态异常规范
#ifndef _HAS_UNEXPECTED
#define _HAS_UNEXPECTED (!_HAS_CXX17)
#endif // _HAS_UNEXPECTED
// ... 省略部分告警
// STL4000 is "_STATIC_CPPLIB is deprecated", currently in yvals.h
// STL4001 is "/clr:pure is deprecated", currently in yvals.h

#if _HAS_TR1_NAMESPACE //弃用告警
#ifdef _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING
#define _DEPRECATE_TR1_NAMESPACE
#else // _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING
//启用告警
#define _DEPRECATE_TR1_NAMESPACE [[deprecated("warning STL4002: " \
        "The non-Standard std::tr1 namespace and TR1-only machinery are deprecated and will be REMOVED. You can " \
        "define _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING to suppress this warning.")]]
#endif // _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING
#endif // _HAS_TR1_NAMESPACE

// STL4003 was "The non-Standard std::identity struct is deprecated and will be REMOVED."
// STL4003 非标准 std::identity 结构已弃用并将被移除

// Enforcement of matching allocator value_types 执行匹配分配器 value_types
#ifndef _ENFORCE_MATCHING_ALLOCATORS
#define _ENFORCE_MATCHING_ALLOCATORS _HAS_CXX17
#endif // _ENFORCE_MATCHING_ALLOCATORS


// Controls whether the STL will force /fp:fast to enable vectorization of algorithms defined
// in the standard as special cases; such as reduce, transform_reduce, inclusive_scan, exclusive_scan
//控制 STL 是否会强制 /fp:fast 启用标准中定义为特殊情况的算法的矢量化; 比如reduce, transform_reduce, inclusive_scan, exclusive_scan
#ifndef _STD_VECTORIZE_WITH_FLOAT_CONTROL
#ifdef _M_FP_EXCEPT
#define _STD_VECTORIZE_WITH_FLOAT_CONTROL 0
#else // ^^^ floating-point exceptions enabled / floating-point exceptions disabled (default) vvv
#define _STD_VECTORIZE_WITH_FLOAT_CONTROL 1
#endif // _M_FP_EXCEPT
#endif // _STD_VECTORIZE_WITH_FLOAT_CONTROL

// P0174R2 Deprecating Vestigial Library Parts 弃用残留的库部分
// P0521R0 Deprecating shared_ptr::unique()
// Other C++17 deprecation warnings  各种弃用的告警,后面省略
// 废弃头文件 , , , and  are deprecated in C++17. ... 

// P2186R2 Removing Garbage Collection Support 删除垃圾收集支持
#ifndef _HAS_GARBAGE_COLLECTION_SUPPORT_DELETED_IN_CXX23
#define _HAS_GARBAGE_COLLECTION_SUPPORT_DELETED_IN_CXX23 (_HAS_FEATURES_REMOVED_IN_CXX23)
#endif // _HAS_GARBAGE_COLLECTION_SUPPORT_DELETED_IN_CXX23

// C++14 C++17 C++20 C++23常量定义,特性加入的时间,只留几个示例
#define __cpp_lib_chrono_udls                 201304L
...
#define __cpp_lib_void_t                           201411L
#define __cpp_lib_to_chars              201611L
#define __cpp_lib_atomic_value_initialization 201911L
#define __cpp_lib_constexpr_bitset                  202207L

#ifdef _RTC_CONVERSION_CHECKS_ENABLED
#ifndef _ALLOW_RTCc_IN_STL
#error /RTCc rejects conformant code, so it is not supported by the C++ Standard Library. Either remove this \
compiler option, or define _ALLOW_RTCc_IN_STL to suppress this error.
///RTCc 拒绝符合标准的代码,因此 C++ 标准库不支持它。 要么删除这个编译器选项,或定义 _ALLOW_RTCc_IN_STL 以抑制此错误。
#endif // _ALLOW_RTCc_IN_STL
#endif // _RTC_CONVERSION_CHECKS_ENABLED

#define _STRINGIZEX(x)  #x
#define _STRINGIZE(x)   _STRINGIZEX(x) //转字符串
#define _EMPTY_ARGUMENT // for empty macro argument 空宏参数

#define _STD_BEGIN namespace std {
#define _STD_END   }
#define _STD       ::std::
#define _CHRONO    ::std::chrono::
#define _RANGES    ::std::ranges::

// We use the stdext (standard extension) namespace to contain extensions that are not part of the current standard
#define _STDEXT_BEGIN namespace stdext {
#define _STDEXT_END   }
#define _STDEXT       ::stdext::

#define _CSTD ::

#define _EXTERN_C     extern "C" {
#define _END_EXTERN_C }

#ifdef _M_CEE_PURE
#define _EXTERN_C_UNLESS_PURE
#define _END_EXTERN_C_UNLESS_PURE
#else // ^^^ _M_CEE_PURE / !_M_CEE_PURE vvv
#define _EXTERN_C_UNLESS_PURE     _EXTERN_C
#define _END_EXTERN_C_UNLESS_PURE _END_EXTERN_C
#endif // _M_CEE_PURE

#if defined(MRTDLL) && !defined(_CRTBLD)
#error In yvals_core.h, defined(MRTDLL) implies defined(_CRTBLD); !defined(_CRTBLD) implies !defined(MRTDLL)
#endif // defined(MRTDLL) && !defined(_CRTBLD)

#if defined(MRTDLL) && !defined(_M_CEE_PURE)
#error In yvals_core.h, defined(MRTDLL) implies defined(_M_CEE_PURE); !defined(_M_CEE_PURE) implies !defined(MRTDLL)
#endif // defined(MRTDLL) && !defined(_M_CEE_PURE)

#define _STL_WIN32_WINNT_VISTA   0x0600 // _WIN32_WINNT_VISTA from sdkddkver.h
#define _STL_WIN32_WINNT_WIN7    0x0601 // _WIN32_WINNT_WIN7 from sdkddkver.h
#define _STL_WIN32_WINNT_WIN8    0x0602 // _WIN32_WINNT_WIN8 from sdkddkver.h
#define _STL_WIN32_WINNT_WINBLUE 0x0603 // _WIN32_WINNT_WINBLUE from sdkddkver.h
#define _STL_WIN32_WINNT_WIN10   0x0A00 // _WIN32_WINNT_WIN10 from sdkddkver.h

// Note that the STL DLL builds will set this to XP for ABI compatibility with VS2015 which supported XP.
#ifndef _STL_WIN32_WINNT
#if defined(_M_ARM64)
// The first ARM64 Windows was Windows 10
#define _STL_WIN32_WINNT _STL_WIN32_WINNT_WIN10
#elif defined(_M_ARM) || defined(_ONECORE) || defined(_CRT_APP)
// The first ARM or OneCore or App Windows was Windows 8
#define _STL_WIN32_WINNT _STL_WIN32_WINNT_WIN8
#else // ^^^ default to Win8 // default to Win7 vvv
// The earliest Windows supported by this implementation is Windows 7
#define _STL_WIN32_WINNT _STL_WIN32_WINNT_WIN7
#endif // ^^^ !defined(_M_ARM) && !defined(_M_ARM64) && !defined(_ONECORE) && !defined(_CRT_APP) ^^^
#endif // _STL_WIN32_WINNT

#ifdef __cpp_noexcept_function_type
#define _NOEXCEPT_FNPTR noexcept
#else
#define _NOEXCEPT_FNPTR
#endif // __cpp_noexcept_function_type

#ifdef __clang__
#define _STL_UNREACHABLE __builtin_unreachable()
#else // ^^^ clang ^^^ / vvv other vvv
#define _STL_UNREACHABLE __assume(false)
#endif // __clang__

#ifdef _ENABLE_STL_INTERNAL_CHECK //变参宏示例,静态判断
#define _STL_INTERNAL_STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
#else // ^^^ _ENABLE_STL_INTERNAL_CHECK ^^^ // vvv !_ENABLE_STL_INTERNAL_CHECK vvv
#define _STL_INTERNAL_STATIC_ASSERT(...)
#endif // _ENABLE_STL_INTERNAL_CHECK

#endif // _STL_COMPILER_PREPROCESSOR
#endif // _YVALS_CORE_H_


你可能感兴趣的:(cpp,c++)