Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move numerous components from <xstddef> to other headers and reduce inclusion #3623

Merged
merged 16 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions stl/inc/bit
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
_EMIT_STL_WARNING(STL4038, "The contents of <bit> are available only with C++20 or later.");
#else // ^^^ !_HAS_CXX20 / _HAS_CXX20 vvv

#include <cstdlib>
#include <isa_availability.h>
#include <limits>
#include <type_traits>
Expand Down
1 change: 1 addition & 0 deletions stl/inc/exception
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <yvals.h>
#if _STL_COMPILER_PREPROCESSOR

#include <cstdlib>
#include <type_traits>

#pragma pack(push, _CRT_PACKING)
Expand Down
25 changes: 19 additions & 6 deletions stl/inc/functional
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <tuple>
#include <typeinfo>
#include <xmemory>
#include <xstddef>
#if _HAS_CXX17
#ifdef _LEGACY_CODE_ASSUMES_FUNCTIONAL_INCLUDES_MEMORY
#include <memory>
Expand All @@ -31,7 +30,7 @@ _STL_DISABLE_CLANG_WARNINGS
#undef new

_STD_BEGIN
// plus, minus, and multiplies are defined in <xstddef>
// plus, minus, and multiplies are defined in <xutility>

_EXPORT_STD template <class _Ty = void>
struct divides {
Expand Down Expand Up @@ -65,7 +64,8 @@ struct negate {
}
};

// equal_to, not_equal_to, greater, less, greater_equal, and less_equal are defined in <xstddef>
// less is defined in <type_traits>
// equal_to, not_equal_to, greater, greater_equal, and less_equal are defined in <xutility>

_EXPORT_STD template <class _Ty = void>
struct logical_and {
Expand Down Expand Up @@ -142,7 +142,7 @@ struct bit_not {
}
};

// void specializations of plus, minus, and multiplies are defined in <xstddef>
// void specializations of plus, minus, and multiplies are defined in <xutility>

template <>
struct divides<void> {
Expand Down Expand Up @@ -175,8 +175,8 @@ struct negate<void> {

using is_transparent = int;
};

// void specializations of equal_to, not_equal_to, greater, less, greater_equal, and less_equal are defined in <xstddef>
// void specializations of less is defined in <type_traits>
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
// void specializations of equal_to, not_equal_to, greater, greater_equal, and less_equal are defined in <xutility>

template <>
struct logical_and<void> {
Expand Down Expand Up @@ -302,6 +302,19 @@ _STL_RESTORE_DEPRECATED_WARNING

#if _HAS_AUTO_PTR_ETC
_STL_DISABLE_DEPRECATED_WARNING
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
_EXPORT_STD template <class _Arg, class _Result>
struct unary_function { // base class for unary functions
using argument_type = _Arg;
using result_type = _Result;
};

_EXPORT_STD template <class _Arg1, class _Arg2, class _Result>
struct binary_function { // base class for binary functions
using first_argument_type = _Arg1;
using second_argument_type = _Arg2;
using result_type = _Result;
};

_EXPORT_STD template <class _Fn>
class binder1st : public unary_function<typename _Fn::second_argument_type,
typename _Fn::result_type> { // functor adapter _Func(stored, right)
Expand Down
2 changes: 1 addition & 1 deletion stl/inc/iosfwd
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <cstdio>
#include <cstring>
#include <cwchar>
#include <xstddef>
#include <xtr1common>

#pragma pack(push, _CRT_PACKING)
#pragma warning(push, _STL_WARNING_LEVEL)
Expand Down
2 changes: 1 addition & 1 deletion stl/inc/limits
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <climits>
#include <cwchar>
#include <isa_availability.h>
#include <xstddef>
#include <xtr1common>

#include _STL_INTRIN_HEADER

Expand Down
181 changes: 181 additions & 0 deletions stl/inc/type_traits
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,133 @@ struct is_compound : bool_constant<!is_fundamental_v<_Ty>> {}; // determine whet
_EXPORT_STD template <class _Ty>
_INLINE_VAR constexpr bool is_compound_v = !is_fundamental_v<_Ty>;

#define _EMIT_CDECL(FUNC, OPT1, OPT2, OPT3) FUNC(__cdecl, OPT1, OPT2, OPT3)

#ifdef _M_CEE
#define _EMIT_CLRCALL(FUNC, OPT1, OPT2, OPT3) FUNC(__clrcall, OPT1, OPT2, OPT3)

#else // _M_CEE
#define _EMIT_CLRCALL(FUNC, OPT1, OPT2, OPT3)
#endif // _M_CEE

#if defined(_M_IX86) && !defined(_M_CEE)
#define _EMIT_FASTCALL(FUNC, OPT1, OPT2, OPT3) FUNC(__fastcall, OPT1, OPT2, OPT3)

#else // defined(_M_IX86) && !defined(_M_CEE)
#define _EMIT_FASTCALL(FUNC, OPT1, OPT2, OPT3)
#endif // defined(_M_IX86) && !defined(_M_CEE)

#ifdef _M_IX86
#define _EMIT_STDCALL(FUNC, OPT1, OPT2, OPT3) FUNC(__stdcall, OPT1, OPT2, OPT3)
#define _EMIT_THISCALL(FUNC, OPT1, OPT2, OPT3) FUNC(__thiscall, OPT1, OPT2, OPT3)

#else // _M_IX86
#define _EMIT_STDCALL(FUNC, OPT1, OPT2, OPT3)
#define _EMIT_THISCALL(FUNC, OPT1, OPT2, OPT3)
#endif // _M_IX86

#if ((defined(_M_IX86) && _M_IX86_FP >= 2) || defined(_M_X64)) && !defined(_M_CEE)
#define _EMIT_VECTORCALL(FUNC, OPT1, OPT2, OPT3) FUNC(__vectorcall, OPT1, OPT2, OPT3)

#else // defined(_M_IX86) && _M_IX86_FP >= 2 etc.
#define _EMIT_VECTORCALL(FUNC, OPT1, OPT2, OPT3)
#endif // defined(_M_IX86) && _M_IX86_FP >= 2 etc.

#define _NON_MEMBER_CALL(FUNC, CV_OPT, REF_OPT, NOEXCEPT_OPT) \
_EMIT_CDECL(FUNC, CV_OPT, REF_OPT, NOEXCEPT_OPT) \
_EMIT_CLRCALL(FUNC, CV_OPT, REF_OPT, NOEXCEPT_OPT) \
_EMIT_FASTCALL(FUNC, CV_OPT, REF_OPT, NOEXCEPT_OPT) \
_EMIT_STDCALL(FUNC, CV_OPT, REF_OPT, NOEXCEPT_OPT) \
_EMIT_VECTORCALL(FUNC, CV_OPT, REF_OPT, NOEXCEPT_OPT)

#define _NON_MEMBER_CALL_CV(FUNC, REF_OPT, NOEXCEPT_OPT) \
_NON_MEMBER_CALL(FUNC, , REF_OPT, NOEXCEPT_OPT) \
_NON_MEMBER_CALL(FUNC, const, REF_OPT, NOEXCEPT_OPT) \
_NON_MEMBER_CALL(FUNC, volatile, REF_OPT, NOEXCEPT_OPT) \
_NON_MEMBER_CALL(FUNC, const volatile, REF_OPT, NOEXCEPT_OPT)

#define _NON_MEMBER_CALL_CV_REF(FUNC, NOEXCEPT_OPT) \
_NON_MEMBER_CALL_CV(FUNC, , NOEXCEPT_OPT) \
_NON_MEMBER_CALL_CV(FUNC, &, NOEXCEPT_OPT) \
_NON_MEMBER_CALL_CV(FUNC, &&, NOEXCEPT_OPT)

#ifdef __cpp_noexcept_function_type
#define _NON_MEMBER_CALL_CV_REF_NOEXCEPT(FUNC) \
_NON_MEMBER_CALL_CV_REF(FUNC, ) \
_NON_MEMBER_CALL_CV_REF(FUNC, noexcept)
#else // __cpp_noexcept_function_type
#define _NON_MEMBER_CALL_CV_REF_NOEXCEPT(FUNC) _NON_MEMBER_CALL_CV_REF(FUNC, )
#endif // __cpp_noexcept_function_type

#define _MEMBER_CALL(FUNC, CV_OPT, REF_OPT, NOEXCEPT_OPT) \
_EMIT_CDECL(FUNC, CV_OPT, REF_OPT, NOEXCEPT_OPT) \
_EMIT_CLRCALL(FUNC, CV_OPT, REF_OPT, NOEXCEPT_OPT) \
_EMIT_FASTCALL(FUNC, CV_OPT, REF_OPT, NOEXCEPT_OPT) \
_EMIT_STDCALL(FUNC, CV_OPT, REF_OPT, NOEXCEPT_OPT) \
_EMIT_THISCALL(FUNC, CV_OPT, REF_OPT, NOEXCEPT_OPT) \
_EMIT_VECTORCALL(FUNC, CV_OPT, REF_OPT, NOEXCEPT_OPT)

#define _MEMBER_CALL_CV(FUNC, REF_OPT, NOEXCEPT_OPT) \
_MEMBER_CALL(FUNC, , REF_OPT, NOEXCEPT_OPT) \
_MEMBER_CALL(FUNC, const, REF_OPT, NOEXCEPT_OPT) \
_MEMBER_CALL(FUNC, volatile, REF_OPT, NOEXCEPT_OPT) \
_MEMBER_CALL(FUNC, const volatile, REF_OPT, NOEXCEPT_OPT)

#define _MEMBER_CALL_CV_REF(FUNC, NOEXCEPT_OPT) \
_MEMBER_CALL_CV(FUNC, , NOEXCEPT_OPT) \
_MEMBER_CALL_CV(FUNC, &, NOEXCEPT_OPT) \
_MEMBER_CALL_CV(FUNC, &&, NOEXCEPT_OPT)

#ifdef __cpp_noexcept_function_type
#define _MEMBER_CALL_CV_REF_NOEXCEPT(FUNC) \
_MEMBER_CALL_CV_REF(FUNC, ) \
_MEMBER_CALL_CV_REF(FUNC, noexcept)
#else // __cpp_noexcept_function_type
#define _MEMBER_CALL_CV_REF_NOEXCEPT(FUNC) _MEMBER_CALL_CV_REF(FUNC, )
#endif // __cpp_noexcept_function_type

#ifdef __cpp_noexcept_function_type
#define _CLASS_DEFINE_CV_REF_NOEXCEPT(CLASS) \
CLASS(_EMPTY_ARGUMENT) \
CLASS(const) \
CLASS(volatile) \
CLASS(const volatile) \
CLASS(&) \
CLASS(const&) \
CLASS(volatile&) \
CLASS(const volatile&) \
CLASS(&&) \
CLASS(const&&) \
CLASS(volatile&&) \
CLASS(const volatile&&) \
CLASS(noexcept) \
CLASS(const noexcept) \
CLASS(volatile noexcept) \
CLASS(const volatile noexcept) \
CLASS(&noexcept) \
CLASS(const& noexcept) \
CLASS(volatile& noexcept) \
CLASS(const volatile& noexcept) \
CLASS(&&noexcept) \
CLASS(const&& noexcept) \
CLASS(volatile&& noexcept) \
CLASS(const volatile&& noexcept)
#else // __cpp_noexcept_function_type
#define _CLASS_DEFINE_CV_REF_NOEXCEPT(CLASS) \
CLASS(_EMPTY_ARGUMENT) \
CLASS(const) \
CLASS(volatile) \
CLASS(const volatile) \
CLASS(&) \
CLASS(const&) \
CLASS(volatile&) \
CLASS(const volatile&) \
CLASS(&&) \
CLASS(const&&) \
CLASS(volatile&&) \
CLASS(const volatile&&)
#endif // __cpp_noexcept_function_type

template <class... _Types>
struct _Arg_types {}; // provide argument_type, etc. when sizeof...(_Types) is 1 or 2

Expand Down Expand Up @@ -1471,6 +1598,36 @@ _NODISCARD _MSVC_INTRINSIC constexpr //
return _STD move(_Arg);
}

_EXPORT_STD template <class _Ty>
_NODISCARD constexpr _Ty* addressof(_Ty& _Val) noexcept {
return __builtin_addressof(_Val);
}

_EXPORT_STD template <class _Ty>
const _Ty* addressof(const _Ty&&) = delete;

#pragma warning(push)
#pragma warning(disable : 5215) // '%s' a function parameter with a volatile qualified type is deprecated in C++20
#pragma warning(disable : 5216) // '%s' a volatile qualified return type is deprecated in C++20

#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-volatile"
#endif // __clang__

template <class _Ty>
_NODISCARD _Ty _Fake_copy_init(_Ty) noexcept;
// _Fake_copy_init<T>(E):
// (1) has type T [decay_t<decltype((E))> if T is deduced],
// (2) is well-formed if and only if E is implicitly convertible to T and T is destructible, and
// (3) is non-throwing if and only if both conversion from decltype((E)) to T and destruction of T are non-throwing.

#ifdef __clang__
#pragma clang diagnostic pop
#endif // __clang__

#pragma warning(pop)

_EXPORT_STD template <class _Ty>
class reference_wrapper;

Expand Down Expand Up @@ -2294,6 +2451,30 @@ template <class _Kty>
struct _Is_nothrow_hashable<_Kty, void_t<decltype(hash<_Kty>{}(_STD declval<const _Kty&>()))>>
: bool_constant<noexcept(hash<_Kty>{}(_STD declval<const _Kty&>()))> {};

_EXPORT_STD template <class _Ty = void>
struct less {
using _FIRST_ARGUMENT_TYPE_NAME _CXX17_DEPRECATE_ADAPTOR_TYPEDEFS = _Ty;
using _SECOND_ARGUMENT_TYPE_NAME _CXX17_DEPRECATE_ADAPTOR_TYPEDEFS = _Ty;
using _RESULT_TYPE_NAME _CXX17_DEPRECATE_ADAPTOR_TYPEDEFS = bool;

_NODISCARD constexpr bool operator()(const _Ty& _Left, const _Ty& _Right) const
noexcept(noexcept(_Fake_copy_init<bool>(_Left < _Right))) /* strengthened */ {
return _Left < _Right;
}
};

template <>
struct less<void> {
template <class _Ty1, class _Ty2>
_NODISCARD constexpr auto operator()(_Ty1&& _Left, _Ty2&& _Right) const
noexcept(noexcept(static_cast<_Ty1&&>(_Left) < static_cast<_Ty2&&>(_Right))) // strengthened
-> decltype(static_cast<_Ty1&&>(_Left) < static_cast<_Ty2&&>(_Right)) {
return static_cast<_Ty1&&>(_Left) < static_cast<_Ty2&&>(_Right);
}

using is_transparent = int;
};

// vvvvvvvvvv DERIVED FROM corecrt_internal_fltintrn.h vvvvvvvvvv

template <class _FloatingType>
Expand Down
6 changes: 5 additions & 1 deletion stl/inc/utility
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#define _UTILITY_
#include <yvals_core.h>
#if _STL_COMPILER_PREPROCESSOR
#include <initializer_list>
#include <type_traits>
#include <xstddef>

#ifdef __cpp_lib_concepts
#include <concepts>
Expand All @@ -19,6 +19,10 @@
#include <compare>
#endif // _HAS_CXX20

#if _HAS_CXX23
#include <cstdlib>
#endif // _HAS_CXX23

#pragma pack(push, _CRT_PACKING)
#pragma warning(push, _STL_WARNING_LEVEL)
#pragma warning(disable : _STL_DISABLED_WARNINGS)
Expand Down
1 change: 0 additions & 1 deletion stl/inc/xlocinfo
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <cstdio> // TRANSITION, VSO-661721
#include <cstdlib>
#include <cwchar>
#include <xstddef>
#include <xstring>

#pragma pack(push, _CRT_PACKING)
Expand Down
10 changes: 10 additions & 0 deletions stl/inc/xmemory
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ _STL_DISABLE_CLANG_WARNINGS
#undef new

_STD_BEGIN
template <class _Ptrty>
_NODISCARD constexpr auto _Unfancy(_Ptrty _Ptr) noexcept { // converts from a fancy pointer to a plain pointer
return _STD addressof(*_Ptr);
}

template <class _Ty>
_NODISCARD constexpr _Ty* _Unfancy(_Ty* _Ptr) noexcept { // do nothing for plain pointers
return _Ptr;
}

template <class _Ty>
struct _NODISCARD _Tidy_guard { // class with destructor that calls _Tidy
_Ty* _Target;
Expand Down
Loading