diff --git a/stl/CMakeLists.txt b/stl/CMakeLists.txt index a42c7200a12..08b261b3733 100644 --- a/stl/CMakeLists.txt +++ b/stl/CMakeLists.txt @@ -123,6 +123,7 @@ set(HEADERS ${CMAKE_CURRENT_LIST_DIR}/inc/deque ${CMAKE_CURRENT_LIST_DIR}/inc/exception ${CMAKE_CURRENT_LIST_DIR}/inc/execution + ${CMAKE_CURRENT_LIST_DIR}/inc/experimental/algorithm ${CMAKE_CURRENT_LIST_DIR}/inc/experimental/coroutine ${CMAKE_CURRENT_LIST_DIR}/inc/experimental/deque ${CMAKE_CURRENT_LIST_DIR}/inc/experimental/filesystem @@ -130,6 +131,7 @@ set(HEADERS ${CMAKE_CURRENT_LIST_DIR}/inc/experimental/generator ${CMAKE_CURRENT_LIST_DIR}/inc/experimental/list ${CMAKE_CURRENT_LIST_DIR}/inc/experimental/map + ${CMAKE_CURRENT_LIST_DIR}/inc/experimental/random ${CMAKE_CURRENT_LIST_DIR}/inc/experimental/resumable ${CMAKE_CURRENT_LIST_DIR}/inc/experimental/set ${CMAKE_CURRENT_LIST_DIR}/inc/experimental/string diff --git a/stl/inc/__msvc_all_public_headers.hpp b/stl/inc/__msvc_all_public_headers.hpp index 17767871349..c7d2c07436f 100644 --- a/stl/inc/__msvc_all_public_headers.hpp +++ b/stl/inc/__msvc_all_public_headers.hpp @@ -140,11 +140,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include diff --git a/stl/inc/experimental/algorithm b/stl/inc/experimental/algorithm new file mode 100644 index 00000000000..3ece148087e --- /dev/null +++ b/stl/inc/experimental/algorithm @@ -0,0 +1,46 @@ +// algorithm experimental header + +// Copyright (c) Microsoft Corporation. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#pragma once +#ifndef _EXPERIMENTAL_ALGORITHM_ +#define _EXPERIMENTAL_ALGORITHM_ +#include +#if _STL_COMPILER_PREPROCESSOR + +#include +#include + +#pragma pack(push, _CRT_PACKING) +#pragma warning(push, _STL_WARNING_LEVEL) +#pragma warning(disable : _STL_DISABLED_WARNINGS) +_STL_DISABLE_CLANG_WARNINGS +#pragma push_macro("new") +#undef new + +_STD_BEGIN +namespace experimental { + inline namespace fundamentals_v3 { + + template + _SampleIt sample(_PopIt _First, _PopIt _Last, _SampleIt _Dest, _Diff _Count) { + return _STD sample(_First, _Last, _Dest, _Count, _Engine()); + } + + template + void shuffle(_RanIt _First, _RanIt _Last) { + _STD shuffle(_First, _Last, _Engine()); + } + + } // namespace fundamentals_v3 +} // namespace experimental +_STD_END + +#pragma pop_macro("new") +_STL_RESTORE_CLANG_WARNINGS +#pragma warning(pop) +#pragma pack(pop) + +#endif // _STL_COMPILER_PREPROCESSOR +#endif // _EXPERIMENTAL_ALGORITHM_ diff --git a/stl/inc/experimental/random b/stl/inc/experimental/random new file mode 100644 index 00000000000..1fde1dd565c --- /dev/null +++ b/stl/inc/experimental/random @@ -0,0 +1,68 @@ +// random experimental header + +// Copyright (c) Microsoft Corporation. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#pragma once +#ifndef _EXPERIMENTAL_RANDOM_ +#define _EXPERIMENTAL_RANDOM_ +#include +#if _STL_COMPILER_PREPROCESSOR + +#include + +#pragma pack(push, _CRT_PACKING) +#pragma warning(push, _STL_WARNING_LEVEL) +#pragma warning(disable : _STL_DISABLED_WARNINGS) +_STL_DISABLE_CLANG_WARNINGS +#pragma push_macro("new") +#undef new + +_STD_BEGIN +namespace experimental { + inline namespace fundamentals_v3 { + + const seed_seq _Seed_engine() { + static_assert( + is_same_v, "This code assumes that default_random_engine is mt19937"); + constexpr size_t _Nx = mt19937::state_size; + constexpr size_t _Wx = mt19937::word_size; + static_assert(_Wx % 32 == 0, "mt19937::word_size is not a multiple of 32"); + constexpr size_t _Kx = _Wx / 32; + + uint32_t _Values[_Nx * _Kx]; + random_device _Rd; + _STD generate(_STD begin(_Values), _STD end(_Values), _STD ref(_Rd)); + return seed_seq(_STD cbegin(_Values), _STD cend(_Values)); + } + + _NODISCARD inline default_random_engine& _Engine() { + thread_local default_random_engine _Eng(_Seed_engine()); + return _Eng; + } + + template + _NODISCARD _IntType randint(const _IntType _Min, const _IntType _Max) { + _RNG_REQUIRE_INTTYPE(randint(), _IntType); + _STL_ASSERT(_Min <= _Max, "invalid min and max arguments for randint()"); + return uniform_int_distribution<_IntType>{_Min, _Max}(_Engine()); + } + + inline void reseed() { + _Engine().seed(_Seed_engine()); + } + + inline void reseed(const default_random_engine::result_type _Value) { + _Engine().seed(_Value); + } + } // namespace fundamentals_v3 +} // namespace experimental +_STD_END + +#pragma pop_macro("new") +_STL_RESTORE_CLANG_WARNINGS +#pragma warning(pop) +#pragma pack(pop) + +#endif // _STL_COMPILER_PREPROCESSOR +#endif // _EXPERIMENTAL_RANDOM_ diff --git a/stl/inc/yvals_core.h b/stl/inc/yvals_core.h index d0ca6c339da..85f98d0ae4f 100644 --- a/stl/inc/yvals_core.h +++ b/stl/inc/yvals_core.h @@ -998,6 +998,8 @@ // EXPERIMENTAL #define __cpp_lib_experimental_erase_if 201411L #define __cpp_lib_experimental_filesystem 201406L +#define __cpp_lib_experimental_randint 201511L +#define __cpp_lib_experimental_sample 201402L #ifdef _RTC_CONVERSION_CHECKS_ENABLED