From e30b01eaeac28d72cf0e2c8dba0e184935d4a71f Mon Sep 17 00:00:00 2001 From: Mingxin Wang Date: Mon, 31 Mar 2025 10:58:11 +0800 Subject: [PATCH 1/8] Fix typo (#275) --- docs/weak_proxy.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/weak_proxy.md b/docs/weak_proxy.md index d37662ef..c663f161 100644 --- a/docs/weak_proxy.md +++ b/docs/weak_proxy.md @@ -10,14 +10,14 @@ using weak_proxy = proxy>; // since 3.3.0 Class template `weak_facade` is a [facade](facade.md) type for weak pointers (e.g., [`std::weak_ptr`](https://en.cppreference.com/w/cpp/memory/weak_ptr)) potentially converted from a `proxy` object. -## Member Types of `observer_facade` +## Member Types of `weak_facade` | Name | Description | | ------------------ | ------------------------------------------------------------ | | `convention_types` | A [tuple-like](https://en.cppreference.com/w/cpp/utility/tuple/tuple-like) type that contains one convention type `C`, where`C::is_direct` is `false`, `C::dispatch_type` is of member function `lock` with accessibility, and `C::overload_types` is a [tuple-like](https://en.cppreference.com/w/cpp/utility/tuple/tuple-like) type that contains type `proxy() const noexcept`. | | `reflection_types` | A [tuple-like](https://en.cppreference.com/w/cpp/utility/tuple/tuple-like) type that contains no types. | -## Member Constants of `observer_facade` +## Member Constants of `weak_facade` | Name | Description | | ---------------------------------- | ------------------------------ | From 680ca2c2334fcbba2aed29346695135cba82de41 Mon Sep 17 00:00:00 2001 From: iKoznov Date: Wed, 9 Apr 2025 08:47:42 +0200 Subject: [PATCH 2/8] fix compilation error with clang 20: (#281) --- proxy.h | 1 + 1 file changed, 1 insertion(+) diff --git a/proxy.h b/proxy.h index 9ba1c9e2..02fde832 100644 --- a/proxy.h +++ b/proxy.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include From 435e18eaf616bd094983d9245bbb35bd01d1e08b Mon Sep 17 00:00:00 2001 From: Mingxin Wang Date: Thu, 10 Apr 2025 13:01:15 +0800 Subject: [PATCH 3/8] Upgrade Clang to version 20 (#282) --- .github/workflows/bvt-clang.yml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/bvt-clang.yml b/.github/workflows/bvt-clang.yml index bbfe25e0..f690aeb6 100644 --- a/.github/workflows/bvt-clang.yml +++ b/.github/workflows/bvt-clang.yml @@ -15,20 +15,23 @@ jobs: - name: install clang run: | - sudo apt install -y clang-19 libc++-19-dev + wget https://apt.llvm.org/llvm.sh + chmod +x llvm.sh + sudo ./llvm.sh 20 + sudo apt install libc++-20-dev - name: check compiler version run: | - clang++-19 --version + clang++-20 --version - - name: build and run test with clang 19 + - name: build and run test with clang 20 run: | - cmake -B build -DCMAKE_C_COMPILER=clang-19 -DCMAKE_CXX_COMPILER=clang++-19 -DCMAKE_CXX_FLAGS="-stdlib=libc++" -DCMAKE_CXX_STANDARD=23 -DCMAKE_BUILD_TYPE=Release + cmake -B build -DCMAKE_C_COMPILER=clang-20 -DCMAKE_CXX_COMPILER=clang++-20 -DCMAKE_CXX_FLAGS="-stdlib=libc++" -DCMAKE_CXX_STANDARD=23 -DCMAKE_BUILD_TYPE=Release cmake --build build -j ctest --test-dir build -j mkdir build/drop chmod +x tools/dump_build_env.sh - ./tools/dump_build_env.sh clang++-19 build/drop/env-info.json + ./tools/dump_build_env.sh clang++-20 build/drop/env-info.json - name: run benchmarks run: | From 006b69425538747aaad6edc49049a1d60761d233 Mon Sep 17 00:00:00 2001 From: Mingxin Wang Date: Wed, 7 May 2025 14:29:08 +0800 Subject: [PATCH 4/8] Extract example code from docs (#291) --- CMakeLists.txt | 2 +- docs/CMakeLists.txt | 28 +++++++++ samples/CMakeLists.txt | 20 ------- samples/PRO_DEF_FREE_AS_MEM_DISPATCH.cpp | 19 ------ samples/PRO_DEF_FREE_DISPATCH.cpp | 19 ------ samples/PRO_DEF_MEM_DISPATCH.cpp | 21 ------- samples/access_proxy.cpp | 31 ---------- samples/allocate_proxy.cpp | 18 ------ samples/allocate_proxy_shared.cpp | 22 ------- samples/basic_facade_builder.cpp | 39 ------------- .../basic_facade_builder/add_convention.cpp | 31 ---------- samples/basic_facade_builder/add_facade.cpp | 52 ----------------- .../basic_facade_builder/add_reflection.cpp | 58 ------------------- samples/basic_facade_builder/build.cpp | 35 ----------- .../basic_facade_builder/restrict_layout.cpp | 28 --------- samples/basic_facade_builder/support_copy.cpp | 21 ------- .../support_destruction.cpp | 19 ------ .../basic_facade_builder/support_format.cpp | 18 ------ .../support_relocation.cpp | 22 ------- samples/basic_facade_builder/support_rtti.cpp | 21 ------- .../support_rtti/proxy_cast.cpp | 35 ----------- .../support_rtti/proxy_typeid.cpp | 18 ------ samples/basic_facade_builder/support_view.cpp | 20 ------- samples/basic_facade_builder/support_weak.cpp | 25 -------- samples/explicit_conversion_dispatch.cpp | 16 ----- samples/facade_aware_overload_t.cpp | 28 --------- samples/implicit_conversion_dispatch.cpp | 30 ---------- samples/inplace_proxiable_target.cpp | 20 ------- samples/make_proxy.cpp | 26 --------- samples/make_proxy_inplace.cpp | 20 ------- samples/make_proxy_shared.cpp | 26 --------- samples/make_proxy_view.cpp | 26 --------- samples/msft_lib_proxy.cpp | 15 ----- samples/operator_dispatch.cpp | 24 -------- samples/proxiable.cpp | 20 ------- samples/proxiable_target.cpp | 15 ----- samples/proxy.cpp | 31 ---------- samples/proxy/constructor.cpp | 48 --------------- samples/proxy/destructor.cpp | 17 ------ samples/proxy/emplace.cpp | 30 ---------- samples/proxy/friend_operator_equality.cpp | 18 ------ samples/proxy/friend_swap.cpp | 25 -------- samples/proxy/indirection.cpp | 31 ---------- samples/proxy/operator_bool.cpp | 18 ------ samples/proxy/reset.cpp | 16 ----- samples/proxy_invoke.cpp | 21 ------- samples/proxy_reflect.cpp | 39 ------------- samples/proxy_view.cpp | 19 ------ samples/weak_dispatch.cpp | 27 --------- samples/weak_proxy.cpp | 24 -------- tools/extract_example_code_from_docs.py | 42 ++++++++++++++ 51 files changed, 71 insertions(+), 1223 deletions(-) create mode 100644 docs/CMakeLists.txt delete mode 100644 samples/CMakeLists.txt delete mode 100644 samples/PRO_DEF_FREE_AS_MEM_DISPATCH.cpp delete mode 100644 samples/PRO_DEF_FREE_DISPATCH.cpp delete mode 100644 samples/PRO_DEF_MEM_DISPATCH.cpp delete mode 100644 samples/access_proxy.cpp delete mode 100644 samples/allocate_proxy.cpp delete mode 100644 samples/allocate_proxy_shared.cpp delete mode 100644 samples/basic_facade_builder.cpp delete mode 100644 samples/basic_facade_builder/add_convention.cpp delete mode 100644 samples/basic_facade_builder/add_facade.cpp delete mode 100644 samples/basic_facade_builder/add_reflection.cpp delete mode 100644 samples/basic_facade_builder/build.cpp delete mode 100644 samples/basic_facade_builder/restrict_layout.cpp delete mode 100644 samples/basic_facade_builder/support_copy.cpp delete mode 100644 samples/basic_facade_builder/support_destruction.cpp delete mode 100644 samples/basic_facade_builder/support_format.cpp delete mode 100644 samples/basic_facade_builder/support_relocation.cpp delete mode 100644 samples/basic_facade_builder/support_rtti.cpp delete mode 100644 samples/basic_facade_builder/support_rtti/proxy_cast.cpp delete mode 100644 samples/basic_facade_builder/support_rtti/proxy_typeid.cpp delete mode 100644 samples/basic_facade_builder/support_view.cpp delete mode 100644 samples/basic_facade_builder/support_weak.cpp delete mode 100644 samples/explicit_conversion_dispatch.cpp delete mode 100644 samples/facade_aware_overload_t.cpp delete mode 100644 samples/implicit_conversion_dispatch.cpp delete mode 100644 samples/inplace_proxiable_target.cpp delete mode 100644 samples/make_proxy.cpp delete mode 100644 samples/make_proxy_inplace.cpp delete mode 100644 samples/make_proxy_shared.cpp delete mode 100644 samples/make_proxy_view.cpp delete mode 100644 samples/msft_lib_proxy.cpp delete mode 100644 samples/operator_dispatch.cpp delete mode 100644 samples/proxiable.cpp delete mode 100644 samples/proxiable_target.cpp delete mode 100644 samples/proxy.cpp delete mode 100644 samples/proxy/constructor.cpp delete mode 100644 samples/proxy/destructor.cpp delete mode 100644 samples/proxy/emplace.cpp delete mode 100644 samples/proxy/friend_operator_equality.cpp delete mode 100644 samples/proxy/friend_swap.cpp delete mode 100644 samples/proxy/indirection.cpp delete mode 100644 samples/proxy/operator_bool.cpp delete mode 100644 samples/proxy/reset.cpp delete mode 100644 samples/proxy_invoke.cpp delete mode 100644 samples/proxy_reflect.cpp delete mode 100644 samples/proxy_view.cpp delete mode 100644 samples/weak_dispatch.cpp delete mode 100644 samples/weak_proxy.cpp create mode 100644 tools/extract_example_code_from_docs.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 77dd586b..d3da5a3d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,5 +26,5 @@ include(CTest) if (BUILD_TESTING) add_subdirectory(tests) add_subdirectory(benchmarks) - add_subdirectory(samples) + add_subdirectory(docs) endif() diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt new file mode 100644 index 00000000..875f42c3 --- /dev/null +++ b/docs/CMakeLists.txt @@ -0,0 +1,28 @@ +project(msft_proxy_docs) + +find_package(Python3 REQUIRED COMPONENTS Interpreter) + +file(GLOB_RECURSE DOC_FILES "*.md") +set(EXTRACTION_SCRIPT ${CMAKE_SOURCE_DIR}/tools/extract_example_code_from_docs.py) +set(EXAMPLES_DIR ${CMAKE_BINARY_DIR}/examples_from_docs) +file(MAKE_DIRECTORY "${EXAMPLES_DIR}") +execute_process( + COMMAND ${Python3_EXECUTABLE} ${EXTRACTION_SCRIPT} ${CMAKE_CURRENT_SOURCE_DIR} ${EXAMPLES_DIR} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND_ERROR_IS_FATAL ANY +) + +file(GLOB EXAMPLE_SOURCES "${EXAMPLES_DIR}/*.cpp") +set_source_files_properties(${EXAMPLE_SOURCES} PROPERTIES GENERATED TRUE) +foreach(SOURCE ${EXAMPLE_SOURCES}) + get_filename_component(EXECUTABLE_NAME ${SOURCE} NAME_WE) + add_executable(${EXECUTABLE_NAME} ${SOURCE}) + target_link_libraries(${EXECUTABLE_NAME} PRIVATE msft_proxy) + if (MSVC) + target_compile_options(${EXECUTABLE_NAME} PRIVATE /W4) + elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + target_compile_options(${EXECUTABLE_NAME} PRIVATE -Wall -Wextra -Wpedantic -Wno-c++2b-extensions) + else() + target_compile_options(${EXECUTABLE_NAME} PRIVATE -Wall -Wextra -Wpedantic) + endif() +endforeach() diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt deleted file mode 100644 index 29deb3ea..00000000 --- a/samples/CMakeLists.txt +++ /dev/null @@ -1,20 +0,0 @@ -project(msft_proxy_samples) - -file(GLOB_RECURSE SOURCES "*.cpp") - -foreach(SOURCE ${SOURCES}) - file(RELATIVE_PATH REL_PATH ${CMAKE_SOURCE_DIR} ${SOURCE}) - get_filename_component(DIR ${REL_PATH} DIRECTORY) - string(REPLACE "/" "_" DIR_UNDERSCORE ${DIR}) - get_filename_component(EXECUTABLE_NAME ${SOURCE} NAME_WE) - set(FULL_EXECUTABLE_NAME "${DIR_UNDERSCORE}_${EXECUTABLE_NAME}") - add_executable(${FULL_EXECUTABLE_NAME} ${SOURCE}) - target_link_libraries(${FULL_EXECUTABLE_NAME} PRIVATE msft_proxy) - if (MSVC) - target_compile_options(${FULL_EXECUTABLE_NAME} PRIVATE /W4) - elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - target_compile_options(${FULL_EXECUTABLE_NAME} PRIVATE -Wall -Wextra -Wpedantic -Wno-c++2b-extensions) - else() - target_compile_options(${FULL_EXECUTABLE_NAME} PRIVATE -Wall -Wextra -Wpedantic) - endif() -endforeach() diff --git a/samples/PRO_DEF_FREE_AS_MEM_DISPATCH.cpp b/samples/PRO_DEF_FREE_AS_MEM_DISPATCH.cpp deleted file mode 100644 index eb807dca..00000000 --- a/samples/PRO_DEF_FREE_AS_MEM_DISPATCH.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from PRO_DEF_FREE_AS_MEM_DISPATCH.md. - -#include -#include - -#include "proxy.h" - -PRO_DEF_FREE_AS_MEM_DISPATCH(FreeToString, std::to_string, ToString); - -struct Stringable : pro::facade_builder - ::add_convention - ::build {}; - -int main() { - pro::proxy p = pro::make_proxy(123); - std::cout << p->ToString() << "\n"; // Prints "123" -} diff --git a/samples/PRO_DEF_FREE_DISPATCH.cpp b/samples/PRO_DEF_FREE_DISPATCH.cpp deleted file mode 100644 index 1648c5b2..00000000 --- a/samples/PRO_DEF_FREE_DISPATCH.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from PRO_DEF_FREE_DISPATCH.md. - -#include -#include - -#include "proxy.h" - -PRO_DEF_FREE_DISPATCH(FreeToString, std::to_string, ToString); - -struct Stringable : pro::facade_builder - ::add_convention - ::build {}; - -int main() { - pro::proxy p = pro::make_proxy(123); - std::cout << ToString(*p) << "\n"; // Prints "123" -} diff --git a/samples/PRO_DEF_MEM_DISPATCH.cpp b/samples/PRO_DEF_MEM_DISPATCH.cpp deleted file mode 100644 index 53af4bd1..00000000 --- a/samples/PRO_DEF_MEM_DISPATCH.cpp +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from PRO_DEF_MEM_DISPATCH.md. - -#include -#include -#include - -#include "proxy.h" - -PRO_DEF_MEM_DISPATCH(MemAt, at); - -struct Dictionary : pro::facade_builder - ::add_convention - ::build {}; - -int main() { - std::vector v{"hello", "world"}; - pro::proxy p = &v; - std::cout << p->at(1) << "\n"; // Prints "world" -} diff --git a/samples/access_proxy.cpp b/samples/access_proxy.cpp deleted file mode 100644 index 14e180f2..00000000 --- a/samples/access_proxy.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from access_proxy.md. - -#include -#include - -#include "proxy.h" - -PRO_DEF_FREE_DISPATCH(FreeToString, std::to_string, ToString); - -struct Stringable : pro::facade_builder - ::add_convention - ::build {}; - -int main() { - pro::proxy p = pro::make_proxy(123); - - // Invokes with accessibility API - std::cout << ToString(*p) << "\n"; // Prints "123" - - // How it works behind the scenes - using Accessor = FreeToString::accessor; - static_assert(std::is_base_of_v>); - Accessor& a = static_cast(*p); - pro::proxy& p2 = pro::access_proxy(a); - std::cout << std::boolalpha << (&p == &p2) << "\n"; // Prints "true" because access_proxy converts - // an accessor back to the original proxy - auto result = pro::proxy_invoke(p2); - std::cout << result << "\n"; // Prints "123" -} diff --git a/samples/allocate_proxy.cpp b/samples/allocate_proxy.cpp deleted file mode 100644 index 22878af6..00000000 --- a/samples/allocate_proxy.cpp +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from allocate_proxy.md. - -#include - -#include "proxy.h" - -// By default, the maximum pointer size defined by pro::facade_builder -// is 2 * sizeof(void*). This value can be overridden by `restrict_layout`. -struct Any : pro::facade_builder::build {}; - -int main() { - // sizeof(std::array) is usually greater than 2 * sizeof(void*), - // calling allocate_proxy has no limitation to the size and alignment of the target - using Target = std::array; - pro::proxy p1 = pro::allocate_proxy(std::allocator{}); -} diff --git a/samples/allocate_proxy_shared.cpp b/samples/allocate_proxy_shared.cpp deleted file mode 100644 index 41032aa8..00000000 --- a/samples/allocate_proxy_shared.cpp +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from allocate_proxy_shared.md. - -#include -#include - -#include "proxy.h" - -struct RttiAware : pro::facade_builder - ::support_copy - ::support_rtti - ::build {}; - -int main() { - std::pmr::unsynchronized_pool_resource pool; - std::pmr::polymorphic_allocator<> alloc{&pool}; - pro::proxy p1 = pro::allocate_proxy_shared(alloc, 1); - pro::proxy p2 = p1; - proxy_cast(*p1) += 2; - std::cout << proxy_cast(*p2) << "\n"; // Prints "3" -} diff --git a/samples/basic_facade_builder.cpp b/samples/basic_facade_builder.cpp deleted file mode 100644 index 2e82cbab..00000000 --- a/samples/basic_facade_builder.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from basic_facade_builder.md. - -#include - -#include "proxy.h" - -template -struct MovableCallable : pro::facade_builder - ::add_convention, Overloads...> - ::build {}; - -template -struct CopyableCallable : pro::facade_builder - ::support_copy - ::add_facade> - ::build {}; - -// MyFunction has similar functionality as std::function but supports multiple overloads -// MyMoveOnlyFunction has similar functionality as std::move_only_function but supports multiple overloads -template -using MyFunction = pro::proxy>; -template -using MyMoveOnlyFunction = pro::proxy>; - -int main() { - auto f = [](auto&&... v) { - std::cout << "f() called. Args: "; - ((std::cout << v << ":" << typeid(decltype(v)).name() << ", "), ...); - std::cout << "\n"; - }; - MyFunction p0{&f}; - (*p0)(123); // Prints "f() called. Args: 123:i," (assuming GCC) - MyMoveOnlyFunction p1{&f}; - (*p1)(); // Prints "f() called. Args:" - (*p1)(456); // Prints "f() called. Args: 456:i," - (*p1)(1.2); // Prints "f() called. Args: 1.2:d," -} diff --git a/samples/basic_facade_builder/add_convention.cpp b/samples/basic_facade_builder/add_convention.cpp deleted file mode 100644 index 7f0ed4f2..00000000 --- a/samples/basic_facade_builder/add_convention.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from add_convention.md. - -#include -#include -#include - -#include "proxy.h" - -PRO_DEF_FREE_DISPATCH(FreeToString, std::to_string, ToString); - -struct BasicStringable : pro::facade_builder - ::add_convention - ::build {}; - -struct Stringable : pro::facade_builder - ::add_facade - ::support_copy - ::add_direct_convention() &&> - ::build {}; - -int main() { - pro::proxy p1 = std::make_shared(123); - pro::proxy p2 = p1; - pro::proxy p3 = static_cast>(std::move(p2)); - pro::proxy p4 = std::move(p3); - // pro::proxy p5 = p4; // Won't compile - std::cout << ToString(*p4) << "\n"; // Prints "123" - std::cout << std::boolalpha << p3.has_value() << "\n"; // Prints "false" -} diff --git a/samples/basic_facade_builder/add_facade.cpp b/samples/basic_facade_builder/add_facade.cpp deleted file mode 100644 index 1b122f99..00000000 --- a/samples/basic_facade_builder/add_facade.cpp +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from add_facade.md. - -#include -#include - -#include "proxy.h" - -PRO_DEF_MEM_DISPATCH(MemSize, size); -PRO_DEF_MEM_DISPATCH(MemAt, at); -PRO_DEF_MEM_DISPATCH(MemEmplace, emplace); - -struct Copyable : pro::facade_builder - ::support_copy - ::build {}; - -struct BasicContainer : pro::facade_builder - ::add_convention - ::build {}; - -struct StringDictionary : pro::facade_builder - ::add_facade - ::add_facade - ::add_convention - ::build {}; - -struct MutableStringDictionary : pro::facade_builder - ::add_facade - ::add_convention - ::build {}; - -int main() { - pro::proxy p1 = - pro::make_proxy>(); - std::cout << p1->size() << "\n"; // Prints "0" - try { - std::cout << p1->at(123) << "\n"; // No output because the expression throws - } catch (const std::out_of_range& e) { - std::cerr << e.what() << "\n"; // Prints error message - } - p1->emplace(123, "lalala"); - auto p2 = p1; // Performs a deep copy - p2->emplace(456, "trivial"); - pro::proxy p3 = std::move(p2); // Performs an upward conversion from an rvalue reference - std::cout << p1->size() << "\n"; // Prints "1" - std::cout << p1->at(123) << "\n"; // Prints "lalala" - std::cout << std::boolalpha << p2.has_value() << "\n"; // Prints "false" because it is moved - std::cout << p3->size() << "\n"; // Prints "2" - std::cout << p3->at(123) << "\n"; // Prints "lalala" - std::cout << p3->at(456) << "\n"; // Prints "trivial" -} diff --git a/samples/basic_facade_builder/add_reflection.cpp b/samples/basic_facade_builder/add_reflection.cpp deleted file mode 100644 index e0b91e54..00000000 --- a/samples/basic_facade_builder/add_reflection.cpp +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from add_reflection.md. - -#include -#include - -#include "proxy.h" - -struct LayoutReflector { - public: - template - constexpr explicit LayoutReflector(std::in_place_type_t) - : Size(sizeof(T)), Align(alignof(T)) {} - - template - struct accessor { - friend std::size_t SizeOf(const std::conditional_t, - pro::proxy_indirect_accessor>& self) noexcept { - const LayoutReflector& refl = pro::proxy_reflect(pro::access_proxy(self)); - return refl.Size; - } - - friend std::size_t AlignOf(const std::conditional_t, - pro::proxy_indirect_accessor>& self) noexcept { - const LayoutReflector& refl = pro::proxy_reflect(pro::access_proxy(self)); - return refl.Align; - } - }; - - std::size_t Size, Align; -}; - -struct LayoutAware : pro::facade_builder - ::add_direct_reflection - ::add_indirect_reflection - ::build {}; - -int main() { - int a = 123; - pro::proxy p = &a; - std::cout << SizeOf(p) << "\n"; // Prints sizeof(raw pointer) - std::cout << AlignOf(p) << "\n"; // Prints alignof(raw pointer) - std::cout << SizeOf(*p) << "\n"; // Prints sizeof(int) - std::cout << AlignOf(*p) << "\n"; // Prints alignof(int) - - p = pro::make_proxy(123); // SBO enabled - std::cout << SizeOf(p) << "\n"; // Prints sizeof(int) - std::cout << AlignOf(p) << "\n"; // Prints alignof(int) - std::cout << SizeOf(*p) << "\n"; // Prints sizeof(int) - std::cout << AlignOf(*p) << "\n"; // Prints alignof(int) - - p = pro::make_proxy>(); // SBO disabled - std::cout << SizeOf(p) << "\n"; // Prints sizeof(raw pointer) - std::cout << AlignOf(p) << "\n"; // Prints alignof(raw pointer) - std::cout << SizeOf(*p) << "\n"; // Prints "100" - std::cout << AlignOf(*p) << "\n"; // Prints "1" -} diff --git a/samples/basic_facade_builder/build.cpp b/samples/basic_facade_builder/build.cpp deleted file mode 100644 index 1df9c14f..00000000 --- a/samples/basic_facade_builder/build.cpp +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from build.md. - -#include - -#include "proxy.h" - -struct DefaultBase : pro::facade_builder - ::build {}; - -struct CopyableBase : pro::facade_builder - ::support_copy - ::build {}; - -struct TrivialBase : pro::facade_builder - ::support_copy - ::support_relocation - ::support_destruction - ::restrict_layout - ::build {}; - -int main() { - static_assert(!std::is_copy_constructible_v>); - static_assert(std::is_nothrow_move_constructible_v>); - static_assert(std::is_nothrow_destructible_v>); - - static_assert(std::is_copy_constructible_v>); - static_assert(std::is_nothrow_move_constructible_v>); - static_assert(std::is_nothrow_destructible_v>); - - static_assert(std::is_trivially_copy_constructible_v>); - static_assert(std::is_trivially_move_constructible_v>); - static_assert(std::is_trivially_destructible_v>); -} diff --git a/samples/basic_facade_builder/restrict_layout.cpp b/samples/basic_facade_builder/restrict_layout.cpp deleted file mode 100644 index c23b0484..00000000 --- a/samples/basic_facade_builder/restrict_layout.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from restrict_layout.md. - -#include -#include - -#include "proxy.h" - -struct DefaultFacade : pro::facade_builder::build {}; - -struct SmallFacade : pro::facade_builder - ::restrict_layout - ::build {}; - -int main() { - static_assert(sizeof(pro::proxy) > sizeof(pro::proxy)); - static_assert(pro::proxiable, DefaultFacade>); - static_assert(pro::proxiable, SmallFacade>); - static_assert(pro::proxiable, DefaultFacade>); - static_assert(!pro::proxiable, SmallFacade>); - static_assert(pro::inplace_proxiable_target, DefaultFacade>); - static_assert(!pro::inplace_proxiable_target, SmallFacade>); - static_assert(!pro::inplace_proxiable_target, DefaultFacade>); - static_assert(!pro::inplace_proxiable_target, SmallFacade>); - pro::proxy p1 = std::make_shared(123); - // pro::proxy p2 = std::make_shared(123); // Won't compile -} diff --git a/samples/basic_facade_builder/support_copy.cpp b/samples/basic_facade_builder/support_copy.cpp deleted file mode 100644 index 97e9904d..00000000 --- a/samples/basic_facade_builder/support_copy.cpp +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from support_copy.md. - -#include - -#include "proxy.h" - -struct Movable : pro::facade_builder::build {}; - -struct Copyable : pro::facade_builder - ::support_copy - ::build {}; - -int main() { - pro::proxy p1 = std::make_unique(123); - // pro::proxy p2 = std::make_unique(123); // Won't compile - pro::proxy p3 = std::make_shared(456); - // auto p4 = p1; // Won't compile - auto p5 = p3; -} diff --git a/samples/basic_facade_builder/support_destruction.cpp b/samples/basic_facade_builder/support_destruction.cpp deleted file mode 100644 index 2f591082..00000000 --- a/samples/basic_facade_builder/support_destruction.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from support_destruction.md. - -#include - -#include "proxy.h" - -struct Movable : pro::facade_builder::build {}; - -struct NonriviallyDestructible : pro::facade_builder - ::support_relocation - ::support_destruction - ::build {}; - -int main() { - static_assert(std::is_nothrow_destructible_v>); - static_assert(!std::is_nothrow_destructible_v>); -} diff --git a/samples/basic_facade_builder/support_format.cpp b/samples/basic_facade_builder/support_format.cpp deleted file mode 100644 index 0869bd6f..00000000 --- a/samples/basic_facade_builder/support_format.cpp +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from support_format.md. - -#include -#include - -#include "proxy.h" - -struct Formattable : pro::facade_builder - ::support_format - ::build {}; - -int main() { - pro::proxy p = pro::make_proxy(123); - std::cout << std::format("{}", *p) << "\n"; // Prints "123" - std::cout << std::format("{:*<6}", *p) << "\n"; // Prints "123***" -} diff --git a/samples/basic_facade_builder/support_relocation.cpp b/samples/basic_facade_builder/support_relocation.cpp deleted file mode 100644 index 4e46436c..00000000 --- a/samples/basic_facade_builder/support_relocation.cpp +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from support_relocation.md. - -#include - -#include "proxy.h" - -struct Movable : pro::facade_builder::build {}; - -struct Trivial : pro::facade_builder - ::support_copy - ::support_relocation - ::support_destruction - ::build {}; - -int main() { - pro::proxy p1 = std::make_unique(123); - // pro::proxy p2 = std::make_unique(456); // Won't compile - double v = 3.14; - pro::proxy p3 = &v; // Compiles because double* is trivial -} diff --git a/samples/basic_facade_builder/support_rtti.cpp b/samples/basic_facade_builder/support_rtti.cpp deleted file mode 100644 index 1d46efbe..00000000 --- a/samples/basic_facade_builder/support_rtti.cpp +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from support_rtti.md. - -#include - -#include "proxy.h" - -struct RttiAware : pro::facade_builder - ::support_rtti - ::support_direct_rtti - ::build {}; - -int main() { - int v = 123; - pro::proxy p = &v; - std::cout << proxy_typeid(p).name() << "\n"; // Prints "Pi" (assuming GCC) - std::cout << proxy_cast(p) << "\n"; // Prints the address of v - std::cout << proxy_typeid(*p).name() << "\n"; // Prints "i" (assuming GCC) - std::cout << proxy_cast(*p) << "\n"; // Prints "123" -} diff --git a/samples/basic_facade_builder/support_rtti/proxy_cast.cpp b/samples/basic_facade_builder/support_rtti/proxy_cast.cpp deleted file mode 100644 index 25ab381c..00000000 --- a/samples/basic_facade_builder/support_rtti/proxy_cast.cpp +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from proxy_cast.md. - -#include - -#include "proxy.h" - -struct RttiAware : pro::facade_builder - ::support_rtti - ::build {}; - -int main() { - int v = 123; - pro::proxy p; - try { - proxy_cast(*p); // Throws - } catch (const pro::bad_proxy_cast& e) { - std::cout << e.what() << "\n"; // Prints an explanatory string - } - p = &v; - std::cout << proxy_cast(*p) << "\n"; // Prints "123" - proxy_cast(*p) = 456; - std::cout << v << "\n"; // Prints "456" - try { - proxy_cast(*p); // Throws - } catch (const pro::bad_proxy_cast& e) { - std::cout << e.what() << "\n"; // Prints an explanatory string - } - int* ptr1 = proxy_cast(&*p); - std::cout << ptr1 << "\n"; // Prints an address - std::cout << &v << "\n"; // Prints the same address as above - double* ptr2 = proxy_cast(&*p); - std::cout << ptr2 << "\n"; // Prints "0" -} diff --git a/samples/basic_facade_builder/support_rtti/proxy_typeid.cpp b/samples/basic_facade_builder/support_rtti/proxy_typeid.cpp deleted file mode 100644 index 1d498206..00000000 --- a/samples/basic_facade_builder/support_rtti/proxy_typeid.cpp +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from proxy_typeid.md. - -#include - -#include "proxy.h" - -struct RttiAware : pro::facade_builder - ::support_rtti - ::build {}; - -int main() { - pro::proxy p; - std::cout << proxy_typeid(*p).name() << "\n"; // Prints "v" (assuming GCC) - p = pro::make_proxy(123); - std::cout << proxy_typeid(*p).name() << "\n"; // Prints "i" (assuming GCC) -} diff --git a/samples/basic_facade_builder/support_view.cpp b/samples/basic_facade_builder/support_view.cpp deleted file mode 100644 index c6216237..00000000 --- a/samples/basic_facade_builder/support_view.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from support_view.md. - -#include - -#include "proxy.h" - -struct RttiAware : pro::facade_builder - ::support_rtti - ::support_view - ::build {}; - -int main() { - pro::proxy p = pro::make_proxy(123); - pro::proxy_view pv = p; - proxy_cast(*pv) = 456; // Modifies the contained object of p - std::cout << proxy_cast(*pv) << "\n"; // Prints "456" - std::cout << proxy_cast(*p) << "\n"; // Prints "456" -} diff --git a/samples/basic_facade_builder/support_weak.cpp b/samples/basic_facade_builder/support_weak.cpp deleted file mode 100644 index 4f699098..00000000 --- a/samples/basic_facade_builder/support_weak.cpp +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from support_weak.md. - -#include - -#include "proxy.h" - -struct Formattable : pro::facade_builder - ::support_format - ::support_weak - ::build {}; - -int main() { - pro::proxy p1 = pro::make_proxy_shared(123); - pro::weak_proxy wp = p1; - pro::proxy p2 = wp.lock(); - std::cout << std::boolalpha << p2.has_value() << "\n"; // Prints "true" - std::cout << std::format("{}\n", *p2); // Prints "123" - - p1.reset(); - p2.reset(); - p2 = wp.lock(); - std::cout << p2.has_value() << "\n"; // Prints "false" -} diff --git a/samples/explicit_conversion_dispatch.cpp b/samples/explicit_conversion_dispatch.cpp deleted file mode 100644 index 68266639..00000000 --- a/samples/explicit_conversion_dispatch.cpp +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from explicit_conversion_dispatch.md. - -#include - -#include "proxy.h" - -struct IntConvertible : pro::facade_builder - ::add_convention - ::build {}; - -int main() { - pro::proxy p = pro::make_proxy(123); // p holds a short - std::cout << static_cast(*p) << "\n"; // Prints "123" -} diff --git a/samples/facade_aware_overload_t.cpp b/samples/facade_aware_overload_t.cpp deleted file mode 100644 index e916560b..00000000 --- a/samples/facade_aware_overload_t.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from facade_aware_overload_t.md. - -#include - -#include "proxy.h" - -template -using BinaryOverload = pro::proxy(const pro::proxy_indirect_accessor& rhs) const; - -template -pro::proxy operator+(const T& value, const pro::proxy_indirect_accessor& rhs) - requires(!std::is_same_v>) - { return pro::make_proxy(value + proxy_cast(rhs)); } - -struct Addable : pro::facade_builder - ::support_rtti - ::support_format - ::add_convention, pro::facade_aware_overload_t> - ::build {}; - -int main() { - pro::proxy p1 = pro::make_proxy(1); - pro::proxy p2 = pro::make_proxy(2); - pro::proxy p3 = *p1 + *p2; - std::cout << std::format("{}\n", *p3); // Prints "3" -} diff --git a/samples/implicit_conversion_dispatch.cpp b/samples/implicit_conversion_dispatch.cpp deleted file mode 100644 index e818ab68..00000000 --- a/samples/implicit_conversion_dispatch.cpp +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from implicit_conversion_dispatch.md. - -#include - -#include "proxy.h" - -struct Runnable : pro::facade_builder - ::add_convention, void()> - ::build {}; - -struct CopyableRunnable : pro::facade_builder - ::support_copy - ::add_facade - ::add_direct_convention() const&, pro::proxy() &&> - ::build {}; - -int main() { - pro::proxy p1 = pro::make_proxy( - [] { std::cout << "Lambda expression invoked\n"; }); - auto p2 = p1; // Copy construction - pro::proxy p3 = p2; // Implicit conversion via const reference of pro::proxy - std::cout << std::boolalpha << p2.has_value() << "\n"; // Prints "true" - // auto p4 = p3; // Won't compile because pro::proxy is not copy-constructible - pro::proxy p5 = std::move(p2); // Implicit conversion via rvalue reference of pro::proxy - std::cout << p2.has_value() << "\n"; // Prints "false" - (*p5)(); // Prints "Lambda expression invoked" -} diff --git a/samples/inplace_proxiable_target.cpp b/samples/inplace_proxiable_target.cpp deleted file mode 100644 index 7930c45c..00000000 --- a/samples/inplace_proxiable_target.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from inplace_proxiable_target.md. - -#include - -#include "proxy.h" - -// By default, the maximum pointer size defined by pro::facade_builder -// is 2 * sizeof(void*). This value can be overridden by `restrict_layout`. -struct Any : pro::facade_builder::build {}; - -int main() { - // sizeof(int) is usually not greater than sizeof(void*) for modern - // 32/64-bit compilers - static_assert(pro::inplace_proxiable_target); - - // sizeof(std::array) is usually greater than 2 * sizeof(void*) - static_assert(!pro::inplace_proxiable_target, Any>); -} diff --git a/samples/make_proxy.cpp b/samples/make_proxy.cpp deleted file mode 100644 index 7fd20c67..00000000 --- a/samples/make_proxy.cpp +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from make_proxy.md. - -#include -#include -#include - -#include "proxy.h" - -struct Printable : pro::facade_builder - ::add_convention, std::ostream&(std::ostream&) const> - ::build {}; - -int main() { - pro::proxy p1 = pro::make_proxy(true); // From bool - pro::proxy p2 = pro::make_proxy(123); // From int - pro::proxy p3 = pro::make_proxy(3.1415926); // From double - pro::proxy p4 = pro::make_proxy("lalala"); // From const char* - pro::proxy p5 = pro::make_proxy(5, 'x'); // From a in-place constructed string - std::cout << std::boolalpha << *p1 << "\n"; // Prints "true" - std::cout << *p2 << "\n"; // Prints "123" - std::cout << std::fixed << std::setprecision(10) << *p3 << "\n"; // Prints "3.1415926000" - std::cout << *p4 << "\n"; // Prints "lalala" - std::cout << *p5 << "\n"; // Prints "xxxxx" -} diff --git a/samples/make_proxy_inplace.cpp b/samples/make_proxy_inplace.cpp deleted file mode 100644 index 0f3d6b60..00000000 --- a/samples/make_proxy_inplace.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from make_proxy_inplace.md. - -#include - -#include "proxy.h" - -// By default, the maximum pointer size defined by pro::facade_builder -// is 2 * sizeof(void*). This value can be overridden by `restrict_layout`. -struct Any : pro::facade_builder::build {}; - -int main() { - // sizeof(int) is usually not greater than sizeof(void*) for modern - // 32/64-bit compilers - pro::proxy p1 = pro::make_proxy_inplace(123); - - // sizeof(std::array) is usually greater than 2 * sizeof(void*) - // pro::proxy p2 = pro::make_proxy_inplace>(); // Won't compile -} diff --git a/samples/make_proxy_shared.cpp b/samples/make_proxy_shared.cpp deleted file mode 100644 index 7fade471..00000000 --- a/samples/make_proxy_shared.cpp +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from make_proxy_shared.md. - -#include - -#include "proxy.h" - -struct RttiAware : pro::facade_builder - ::support_copy - ::support_rtti - ::support_weak - ::build {}; - -int main() { - pro::proxy p1 = pro::make_proxy_shared(123); - pro::weak_proxy p2 = p1; - pro::proxy p3 = p2.lock(); - std::cout << std::boolalpha << p3.has_value() << "\n"; // Prints "true" - std::cout << proxy_cast(*p3) << "\n"; // Prints "123" - - p3.reset(); - p1.reset(); - p3 = p2.lock(); - std::cout << std::boolalpha << p3.has_value() << "\n"; // Prints "false" -} diff --git a/samples/make_proxy_view.cpp b/samples/make_proxy_view.cpp deleted file mode 100644 index bd359577..00000000 --- a/samples/make_proxy_view.cpp +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from make_proxy_view.md. - -#include -#include -#include - -#include "proxy.h" - -PRO_DEF_MEM_DISPATCH(MemAt, at); - -struct ResourceDictionary : pro::facade_builder - ::add_convention - ::build {}; - -int main() { - std::map dict; - dict[1] = "init"; - pro::proxy_view pv = pro::make_proxy_view(dict); - static_assert(std::is_same_vat(1)), std::string&>, "Non-const overload"); - static_assert(std::is_same_vat(1)), const std::string&>, "Const overload"); - std::cout << std::as_const(pv)->at(1) << "\n"; // Invokes the const overload and prints "init" - pv->at(1) = "modified"; // Invokes the non-const overload - std::cout << std::as_const(pv)->at(1) << "\n"; // Invokes the const overload and prints "modified" -} diff --git a/samples/msft_lib_proxy.cpp b/samples/msft_lib_proxy.cpp deleted file mode 100644 index 4bbb0d91..00000000 --- a/samples/msft_lib_proxy.cpp +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from msft_lib_proxy.md. - -#include - -#include "proxy.h" - -int main() { -#if defined(__msft_lib_proxy) && __msft_lib_proxy >= 202408L - puts("Compiled with library Proxy 3.0.0 or above."); -#else - puts("Cannot determine the version of library Proxy."); -#endif -} diff --git a/samples/operator_dispatch.cpp b/samples/operator_dispatch.cpp deleted file mode 100644 index 535c2391..00000000 --- a/samples/operator_dispatch.cpp +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from operator_dispatch.md. - -#include -#include -#include - -#include "proxy.h" - -struct Number : pro::facade_builder - ::add_convention, void(int)> - ::add_convention, std::ostream&(std::ostream&) const&> - ::build {}; - -int main() { - pro::proxy p1 = pro::make_proxy(std::numbers::pi); - *p1 *= 3; - std::cout << std::setprecision(10) << *p1 << "\n"; // Prints: 9.424777961 - - pro::proxy p2 = pro::make_proxy(10); - *p2 *= 5; - std::cout << *p2 << "\n"; // Prints: 50 -} diff --git a/samples/proxiable.cpp b/samples/proxiable.cpp deleted file mode 100644 index f7309129..00000000 --- a/samples/proxiable.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from proxiable.md. - -#include -#include - -#include "proxy.h" - -PRO_DEF_FREE_DISPATCH(FreeToString, std::to_string, ToString); - -struct Stringable : pro::facade_builder - ::add_convention - ::build {}; - -int main() { - static_assert(pro::proxiable); - static_assert(pro::proxiable, Stringable>); - static_assert(!pro::proxiable*, Stringable>); -} diff --git a/samples/proxiable_target.cpp b/samples/proxiable_target.cpp deleted file mode 100644 index 0d89e7e7..00000000 --- a/samples/proxiable_target.cpp +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from proxiable_target.md. - -#include "proxy.h" - -struct Runnable : pro::facade_builder - ::add_convention, void()> - ::build {}; - -int main() { - auto fun = [] {}; - static_assert(pro::proxiable_target); - static_assert(!pro::proxiable_target); -} diff --git a/samples/proxy.cpp b/samples/proxy.cpp deleted file mode 100644 index 01521c6e..00000000 --- a/samples/proxy.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from proxy.md. - -#include -#include -#include -#include -#include - -#include "proxy.h" - -PRO_DEF_MEM_DISPATCH(MemAt, at); - -struct Dictionary : pro::facade_builder - ::add_convention - ::build {}; - -// This is a function, rather than a function template -void PrintDictionary(pro::proxy dictionary) { - std::cout << dictionary->at(1) << "\n"; -} - -int main() { - static std::map container1{{1, "hello"}}; - auto container2 = std::make_shared>(); - container2->push_back("hello"); - container2->push_back("world"); - PrintDictionary(&container1); // Prints "hello" - PrintDictionary(container2); // Prints "world" -} diff --git a/samples/proxy/constructor.cpp b/samples/proxy/constructor.cpp deleted file mode 100644 index 47411034..00000000 --- a/samples/proxy/constructor.cpp +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from constructor.md. - -#include -#include -#include - -#include "proxy.h" - -PRO_DEF_MEM_DISPATCH(MemSize, size); -PRO_DEF_MEM_DISPATCH(MemClear, clear); - -struct BasicContainer : pro::facade_builder - ::add_convention - ::add_convention - ::support_copy - ::build {}; - -int main() { - std::vector v{1, 2, 3}; - - pro::proxy p0; - std::cout << std::boolalpha << p0.has_value() << "\n"; // Prints "false" - - // Construct a proxy with a raw pointer - pro::proxy p1 = &v; - std::cout << p1.has_value() << ", " << p1->size() << "\n"; // Prints "true,3" - - // Construct a proxy with a smart pointer - pro::proxy p2 = std::make_shared>(10); - std::cout << p2.has_value() << ", " << p2->size() << "\n"; // Prints "true,10" - - // Copy construction - pro::proxy p3 = p2; - std::cout << p3.has_value() << ", " << p3->size() << "\n"; // Prints "true,10" - - // Move construction - pro::proxy p4 = std::move(p3); - std::cout << p4.has_value() << ", " << p4->size() << "\n"; // Prints "true,10" - - // p3 no longer contains a value - std::cout << p3.has_value() << "\n"; // Prints "false" - - // p2 and p4 shares the same object of std::deque - p2->clear(); - std::cout << p4.has_value() << ", " << p4->size() << "\n"; // Prints "true,0" -} diff --git a/samples/proxy/destructor.cpp b/samples/proxy/destructor.cpp deleted file mode 100644 index bf104c35..00000000 --- a/samples/proxy/destructor.cpp +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from destructor.md. - -#include - -#include "proxy.h" - -struct AnyMovable : pro::facade_builder::build {}; - -struct Foo { - ~Foo() { puts("Destroy Foo"); } -}; - -int main() { - pro::proxy p = pro::make_proxy(); -} // The destructor of `Foo` is called when `p` is destroyed diff --git a/samples/proxy/emplace.cpp b/samples/proxy/emplace.cpp deleted file mode 100644 index aa533b84..00000000 --- a/samples/proxy/emplace.cpp +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from emplace.md. - -#include -#include -#include - -#include "proxy.h" - -struct AnyCopyable : pro::facade_builder - ::support_copy - ::build {}; - -struct Foo { - ~Foo() { puts("Destroy Foo"); } - - int payload[10000]; -}; - -int main() { - static std::pmr::unsynchronized_pool_resource my_memory_pool; - - std::pmr::polymorphic_allocator<> alloc{&my_memory_pool}; - auto deleter = [alloc](auto* ptr) mutable { alloc.delete_object(ptr); }; - - pro::proxy p0; - p0.emplace>(alloc.new_object(), deleter); - pro::proxy p1 = p0; // `Foo` is not copied. Only the reference count is increased. -} // The destructor of `Foo` is called once when both `p0` and `p1` are destroyed diff --git a/samples/proxy/friend_operator_equality.cpp b/samples/proxy/friend_operator_equality.cpp deleted file mode 100644 index 1a050654..00000000 --- a/samples/proxy/friend_operator_equality.cpp +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from friend_operator_equality.md. - -#include - -#include "proxy.h" - -struct AnyMovable : pro::facade_builder::build {}; - -int main() { - pro::proxy p; - std::cout << std::boolalpha << (p == nullptr) << "\n"; // Prints "true" - std::cout << (p != nullptr) << "\n"; // Prints "false" - p = std::make_unique(123); - std::cout << (p == nullptr) << "\n"; // Prints "false" - std::cout << (p != nullptr) << "\n"; // Prints "true" -} diff --git a/samples/proxy/friend_swap.cpp b/samples/proxy/friend_swap.cpp deleted file mode 100644 index 88bc17b1..00000000 --- a/samples/proxy/friend_swap.cpp +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from friend_swap.md. - -#include -#include -#include - -#include "proxy.h" - -PRO_DEF_FREE_DISPATCH(FreeToString, std::to_string, ToString); - -struct Stringable : pro::facade_builder - ::add_convention - ::build {}; - -int main() { - pro::proxy p0 = pro::make_proxy(123); - pro::proxy p1 = pro::make_proxy(std::numbers::pi); - std::cout << ToString(*p0) << "\n"; // Prints "10" - std::cout << ToString(*p1) << "\n"; // Prints "3.14..." - std::ranges::swap(p0, p1); // finds the hidden friend - std::cout << ToString(*p0) << "\n"; // Prints "3.14..." - std::cout << ToString(*p1) << "\n"; // Prints "10" -} diff --git a/samples/proxy/indirection.cpp b/samples/proxy/indirection.cpp deleted file mode 100644 index d5b63946..00000000 --- a/samples/proxy/indirection.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from indirection.md. - -#include -#include -#include - -#include "proxy.h" - -PRO_DEF_MEM_DISPATCH(MemSize, size); - -struct BasicContainer : pro::facade_builder - ::add_convention - ::build {}; - -PRO_DEF_FREE_DISPATCH(FreeToString, std::to_string, ToString); - -struct Stringable : pro::facade_builder - ::add_convention - ::build {}; - -int main() { - std::vector v(10); - pro::proxy p0 = &v; - std::cout << p0->size() << "\n"; // Prints "10" - std::cout << (*p0).size() << "\n"; // Prints "10" - - pro::proxy p1 = pro::make_proxy(123); - std::cout << ToString(*p1) << "\n"; // Prints "123" -} diff --git a/samples/proxy/operator_bool.cpp b/samples/proxy/operator_bool.cpp deleted file mode 100644 index 1e2ebf63..00000000 --- a/samples/proxy/operator_bool.cpp +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from operator_bool.md. - -#include - -#include "proxy.h" - -struct AnyMovable : pro::facade_builder::build {}; - -int main() { - pro::proxy p; - std::cout << std::boolalpha << p.has_value() << "\n"; // Prints "false" - p = pro::make_proxy(123); - std::cout << p.has_value() << "\n"; // Prints "true" - p = nullptr; - std::cout << static_cast(p) << "\n"; // Prints "false" -} diff --git a/samples/proxy/reset.cpp b/samples/proxy/reset.cpp deleted file mode 100644 index f4039534..00000000 --- a/samples/proxy/reset.cpp +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from reset.md. - -#include - -#include "proxy.h" - -struct AnyMovable : pro::facade_builder::build {}; - -int main() { - pro::proxy p = pro::make_proxy(123); - std::cout << std::boolalpha << p.has_value() << "\n"; // Prints "true" - p.reset(); - std::cout << p.has_value() << "\n"; // Prints "false" -} diff --git a/samples/proxy_invoke.cpp b/samples/proxy_invoke.cpp deleted file mode 100644 index 9da35ae0..00000000 --- a/samples/proxy_invoke.cpp +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from proxy_invoke.md. - -#include -#include - -#include "proxy.h" - -PRO_DEF_FREE_DISPATCH(FreeToString, std::to_string, ToString); - -struct Stringable : pro::facade_builder - ::add_convention - ::build {}; - -int main() { - int a = 123; - pro::proxy p = &a; - std::cout << ToString(*p) << "\n"; // Invokes with accessor, prints: "123" - std::cout << pro::proxy_invoke(p) << "\n"; // Invokes with proxy_invoke, also prints: "123" -} diff --git a/samples/proxy_reflect.cpp b/samples/proxy_reflect.cpp deleted file mode 100644 index 8e03450c..00000000 --- a/samples/proxy_reflect.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from proxy_reflect.md. - -#include -#include -#include - -#include "proxy.h" - -class CopyabilityReflector { - public: - template - constexpr explicit CopyabilityReflector(std::in_place_type_t) - : copyable_(std::is_copy_constructible_v) {} - - template - struct accessor { - bool IsCopyable() const noexcept { - const CopyabilityReflector& self = pro::proxy_reflect(pro::access_proxy(*this)); - return self.copyable_; - } - }; - - private: - bool copyable_; -}; - -struct CopyabilityAware : pro::facade_builder - ::add_direct_reflection - ::build {}; - -int main() { - pro::proxy p1 = std::make_unique(); - std::cout << std::boolalpha << p1.IsCopyable() << "\n"; // Prints "false" - - pro::proxy p2 = std::make_shared(); - std::cout << p2.IsCopyable() << "\n"; // Prints "true" -} diff --git a/samples/proxy_view.cpp b/samples/proxy_view.cpp deleted file mode 100644 index 41f53182..00000000 --- a/samples/proxy_view.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from proxy_view.md. - -#include - -#include "proxy.h" - -template -struct FMap : pro::facade_builder - ::add_convention, V&(const K& key)> - ::build {}; - -int main() { - std::map v; - pro::proxy_view> p = &v; - (*p)[1] = 123; - printf("%d\n", v.at(1)); // Prints "123" -} diff --git a/samples/weak_dispatch.cpp b/samples/weak_dispatch.cpp deleted file mode 100644 index c57d6e61..00000000 --- a/samples/weak_dispatch.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from weak_dispatch.md. - -#include -#include -#include - -#include "proxy.h" - -PRO_DEF_MEM_DISPATCH(MemAt, at); - -struct WeakDictionary : pro::facade_builder - ::add_convention, std::string(int index) const> - ::build {}; - -int main() { - std::vector v{"hello", "world"}; - pro::proxy p1 = &v; - std::cout << p1->at(1) << "\n"; // Prints "world" - pro::proxy p2 = pro::make_proxy(123); - try { - p2->at(1); - } catch (const pro::not_implemented& e) { - std::cout << e.what() << "\n"; // Prints an explanatory string - } -} diff --git a/samples/weak_proxy.cpp b/samples/weak_proxy.cpp deleted file mode 100644 index 632ee8d3..00000000 --- a/samples/weak_proxy.cpp +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from weak_proxy.md. - -#include - -#include "proxy.h" - -struct Formattable : pro::facade_builder - ::support_format - ::build {}; - -int main() { - std::shared_ptr val = std::make_shared(123); - pro::weak_proxy wp = std::weak_ptr{val}; - pro::proxy p = wp.lock(); - std::cout << std::boolalpha << p.has_value() << "\n"; // Prints "true" - std::cout << std::format("{}\n", *p); // Prints "123" - - p.reset(); - val.reset(); - p = wp.lock(); - std::cout << p.has_value() << "\n"; // Prints "false" -} diff --git a/tools/extract_example_code_from_docs.py b/tools/extract_example_code_from_docs.py new file mode 100644 index 00000000..69730ac6 --- /dev/null +++ b/tools/extract_example_code_from_docs.py @@ -0,0 +1,42 @@ +import os +import re +import sys + +def extract_cpp_code(md_path, cpp_path): + with open(md_path, 'r', encoding='utf-8') as f: + content = f.read() + + pattern = r'## Example\r?\n\r?\n```cpp\r?\n(.*?)\r?\n```' + code_blocks = re.findall(pattern, content, re.DOTALL) + + if len(code_blocks) == 0: + return # No match, skip + elif len(code_blocks) > 1: + raise ValueError(f"File '{md_path}' contains more than one '## Example' C++ code block.") + + cpp_code = code_blocks[0] + header = f"// This file was auto-generated from: {md_path}\n// Do not edit this file manually.\n\n" + + with open(cpp_path, 'w', encoding='utf-8') as out: + out.write(header) + out.write(cpp_code) + +def main(): + if len(sys.argv) != 3: + print("Usage: python extract_example_code_from_docs.py ") + sys.exit(1) + + input_dir = sys.argv[1] + output_dir = sys.argv[2] + + for root, _, files in os.walk(input_dir): + for file in files: + if file.endswith('.md'): + md_path = os.path.join(root, file) + rel_path = os.path.relpath(md_path, input_dir) + rel_base = os.path.splitext(rel_path)[0].replace(os.sep, '_') + cpp_path = os.path.join(output_dir, f"example_{rel_base}.cpp") + extract_cpp_code(md_path, cpp_path) + +if __name__ == '__main__': + main() From 0336f718eed14d32a3b9020a56ff5a00a917303c Mon Sep 17 00:00:00 2001 From: Mingxin Wang Date: Sat, 7 Jun 2025 11:51:56 +0800 Subject: [PATCH 5/8] Backport structure change (#308) --- CMakeLists.txt | 35 +++++++++++++++---- README.md | 29 ++++++++++----- .../proxy_invocation_benchmark_context.h | 2 +- benchmarks/proxy_management_benchmark.cpp | 2 +- docs/PRO_DEF_FREE_AS_MEM_DISPATCH.md | 2 +- docs/PRO_DEF_FREE_DISPATCH.md | 2 +- docs/PRO_DEF_MEM_DISPATCH.md | 2 +- docs/PRO_DEF_WEAK_DISPATCH.md | 2 +- docs/access_proxy.md | 2 +- docs/allocate_proxy.md | 2 +- docs/allocate_proxy_shared.md | 2 +- docs/basic_facade_builder.md | 2 +- docs/basic_facade_builder/add_convention.md | 2 +- docs/basic_facade_builder/add_facade.md | 2 +- docs/basic_facade_builder/add_reflection.md | 2 +- docs/basic_facade_builder/build.md | 2 +- docs/basic_facade_builder/restrict_layout.md | 2 +- docs/basic_facade_builder/support_copy.md | 2 +- .../support_destruction.md | 2 +- docs/basic_facade_builder/support_format.md | 2 +- .../support_relocation.md | 2 +- docs/basic_facade_builder/support_rtti.md | 2 +- .../support_rtti/proxy_cast.md | 2 +- .../support_rtti/proxy_typeid.md | 2 +- docs/basic_facade_builder/support_view.md | 2 +- docs/basic_facade_builder/support_weak.md | 2 +- docs/explicit_conversion_dispatch.md | 2 +- docs/facade_aware_overload_t.md | 2 +- docs/implicit_conversion_dispatch.md | 2 +- docs/inplace_proxiable_target.md | 2 +- docs/make_proxy.md | 2 +- docs/make_proxy_inplace.md | 2 +- docs/make_proxy_shared.md | 2 +- docs/make_proxy_view.md | 2 +- docs/msft_lib_proxy.md | 2 +- docs/operator_dispatch.md | 2 +- docs/proxiable.md | 2 +- docs/proxiable_target.md | 2 +- docs/proxy.md | 2 +- docs/proxy/constructor.md | 2 +- docs/proxy/destructor.md | 2 +- docs/proxy/emplace.md | 2 +- docs/proxy/friend_operator_equality.md | 2 +- docs/proxy/friend_swap.md | 2 +- docs/proxy/indirection.md | 2 +- docs/proxy/operator_bool.md | 2 +- docs/proxy/reset.md | 2 +- docs/proxy_invoke.md | 2 +- docs/proxy_reflect.md | 2 +- docs/proxy_view.md | 2 +- docs/weak_dispatch.md | 2 +- docs/weak_proxy.md | 2 +- proxy.h => include/proxy/proxy.h | 0 samples/PRO_DEF_WEAK_DISPATCH.cpp | 35 ------------------- .../freestanding/proxy_freestanding_tests.cpp | 2 +- tests/proxy_creation_tests.cpp | 4 +-- tests/proxy_dispatch_tests.cpp | 2 +- tests/proxy_format_tests.cpp | 2 +- tests/proxy_integration_tests.cpp | 2 +- tests/proxy_invocation_tests.cpp | 2 +- tests/proxy_lifetime_tests.cpp | 4 +-- tests/proxy_reflection_tests.cpp | 4 +-- tests/proxy_regression_tests.cpp | 2 +- tests/proxy_rtti_tests.cpp | 2 +- tests/proxy_traits_tests.cpp | 4 +-- tests/proxy_view_tests.cpp | 4 +-- tests/utils.h | 1 + 67 files changed, 118 insertions(+), 116 deletions(-) rename proxy.h => include/proxy/proxy.h (100%) delete mode 100644 samples/PRO_DEF_WEAK_DISPATCH.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index d3da5a3d..c8c041be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,17 +1,40 @@ cmake_minimum_required(VERSION 3.10) -project(msft_proxy VERSION 3.3.0 LANGUAGES CXX) +project(msft_proxy VERSION 3.4.0 LANGUAGES CXX) add_library(msft_proxy INTERFACE) + +# Do not enable building tests if proxy is consumed as +# subdirectory (e.g. by CMake FetchContent_Declare). +if(PROJECT_IS_TOP_LEVEL) + option(BUILD_TESTING "Build tests" ON) +else() + option(BUILD_TESTING "Build tests" OFF) +endif() + +target_sources(msft_proxy + INTERFACE + FILE_SET public_headers + TYPE HEADERS + BASE_DIRS include + FILES + include/proxy/proxy.h +) + target_compile_features(msft_proxy INTERFACE cxx_std_20) -target_include_directories(msft_proxy INTERFACE $ +target_include_directories(msft_proxy INTERFACE $ $) +set(proxy_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include") +if(NOT PROJECT_IS_TOP_LEVEL) + set(proxy_INCLUDE_DIR "${proxy_INCLUDE_DIR}" PARENT_SCOPE) +endif() + # install and export the project. project name - proxy include(GNUInstallDirs) install(TARGETS msft_proxy - EXPORT proxyConfig) -install(FILES proxy.h - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/proxy) + EXPORT proxyConfig + FILE_SET public_headers DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} +) install(EXPORT proxyConfig DESTINATION ${CMAKE_INSTALL_DATADIR}/proxy) export(TARGETS msft_proxy FILE proxyConfig.cmake) include(CMakePackageConfigHelpers) @@ -22,8 +45,8 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/proxyConfigVersion.cmake DESTINATION ${CMAKE_INSTALL_DATADIR}/proxy) # build tests if BUILD_TESTING is ON -include(CTest) if (BUILD_TESTING) + include(CTest) add_subdirectory(tests) add_subdirectory(benchmarks) add_subdirectory(docs) diff --git a/README.md b/README.md index 80fb1052..5ebbbaca 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,20 @@ Please refer to the [Proxy's Frequently Asked Questions](https://microsoft.githu ## Quick Start -"Proxy" is a header-only C++20 library. To use the library, make sure your compiler meets the [minimum requirements](#compiler-req) and just include the header file [proxy.h](https://github.com/microsoft/proxy/blob/main/proxy.h) in your source code. Alternatively, you can install the library via [vcpkg](https://learn.microsoft.com/en-us/vcpkg/get_started/overview) or [conan](https://conan.io/), by searching for "proxy" (see [vcpkg.io](https://vcpkg.io/en/package/proxy) and [conan.io](https://conan.io/center/recipes/proxy)). +"Proxy" is a header-only C++20 library. To use the library, make sure your compiler meets the [minimum requirements](#compiler-req) and just put the [proxy](https://github.com/microsoft/proxy/tree/main/include/proxy) directory in your project's include directory. Alternatively, you can install the library via: + +- [vcpkg](https://learn.microsoft.com/en-us/vcpkg/get_started/overview): [proxy port on vcpkg.io](https://vcpkg.io/en/package/proxy) +- [conan](https://conan.io/): [proxy recipe on conan.io](https://conan.io/center/recipes/proxy) +- [CPM](https://github.com/cpm-cmake/CPM.cmake) / CMake [FetchContent_Declare](https://cmake.org/cmake/help/latest/module/FetchContent.html): + + ```cmake + CPMAddPackage( + NAME proxy + GIT_TAG 3.4.0 # or above + GIT_REPOSITORY https://github.com/microsoft/proxy.git + ) + target_link_libraries(main PRIVATE msft_proxy) + ``` ### Hello World @@ -38,7 +51,7 @@ Let's get started with the following "Hello World" example ([run](https://godbol #include #include -#include "proxy.h" +#include struct Formattable : pro::facade_builder ::support_format @@ -62,7 +75,7 @@ Here is a step-by-step explanation: - `#include `: For [`std::format`](https://en.cppreference.com/w/cpp/utility/format/format). - `#include `: For [`std::cout`](https://en.cppreference.com/w/cpp/io/cout). - `#include `: For [`std::string`](https://en.cppreference.com/w/cpp/string/basic_string). -- `#include "proxy.h"`: For the "Proxy" library. Most of the facilities of the library are defined in namespace `pro`. If the library is consumed via [vcpkg](https://learn.microsoft.com/en-us/vcpkg/get_started/overview) or [conan](https://conan.io/), this line should be changed into `#include `. +- `#include `: For the "Proxy" library. Most of the facilities of the library are defined in namespace `pro`. - `struct Formattable : pro::facade_builder ... ::build {}`: Defines a facade type `Formattable`. The term "facade", formally defined as the [*ProFacade* requirements](https://microsoft.github.io/proxy/docs/ProFacade.html), is how the "Proxy" library models runtime abstraction. Specifically, - [`pro::facade_builder`](https://microsoft.github.io/proxy/docs/basic_facade_builder.html): Provides capability to build a facade type at compile-time. - [`support_format`](https://microsoft.github.io/proxy/docs/basic_facade_builder/support_format.html): Specifies the capability of formatting (via [standard formatting functions](https://en.cppreference.com/w/cpp/utility/format)). @@ -87,7 +100,7 @@ In the previous "Hello Word" example, we demonstrated how `proxy` could manage d #include #include -#include "proxy.h" +#include struct Streamable : pro::facade_builder ::add_convention, std::ostream&(std::ostream& out) const> @@ -108,10 +121,10 @@ int main() { Here is a step-by-step explanation: -- `#include `: For [`std::setprecision`](https://en.cppreference.com/w/cpp/io/manip/setprecision). +- `#include `: For [`std::setprecision`](https://en.cppreference.com/w/cpp/io/manip/setprecision). - `#include `: For [`std::cout`](https://en.cppreference.com/w/cpp/io/cout). - `#include `: For [`std::string`](https://en.cppreference.com/w/cpp/string/basic_string). -- `#include "proxy.h"`: For the "Proxy" library. +- `#include `: For the "Proxy" library. - `struct Streamable : pro::facade_builder ... ::build {}`: Defines a facade type `Streamable`. Specifically, - [`pro::facade_builder`](https://microsoft.github.io/proxy/docs/basic_facade_builder.html): Gets prepared to build another facade. - [`add_convention`](https://microsoft.github.io/proxy/docs/basic_facade_builder/add_convention.html): Adds a generalized "calling convention", defined by a "dispatch" and several "overloads", to the build context. @@ -142,7 +155,7 @@ Note that some facilities are provided as macro, because C++ templates today do #include #include -#include "proxy.h" +#include PRO_DEF_MEM_DISPATCH(MemDraw, Draw); PRO_DEF_MEM_DISPATCH(MemArea, Area); @@ -187,7 +200,7 @@ Here is a step-by-step explanation: - `#include `: For [`std::cout`](https://en.cppreference.com/w/cpp/io/cout). - `#include `: For [`std::stringstream`](https://en.cppreference.com/w/cpp/io/basic_stringstream). -- `#include "proxy.h"`: For the "Proxy" library. +- `#include `: For the "Proxy" library. - [`PRO_DEF_MEM_DISPATCH`](https://microsoft.github.io/proxy/docs/PRO_DEF_MEM_DISPATCH.html)`(MemDraw, Draw)`: Defines a dispatch type `MemDraw` for expressions of calling member function `Draw`. - [`PRO_DEF_MEM_DISPATCH`](https://microsoft.github.io/proxy/docs/PRO_DEF_MEM_DISPATCH.html)`(MemArea, Area)`: Defines a dispatch type `MemArea` for expressions of calling member function `Area`. - `struct Drawable : pro::facade_builder ... ::build {}`: Defines a facade type `Drawable`. Specifically, diff --git a/benchmarks/proxy_invocation_benchmark_context.h b/benchmarks/proxy_invocation_benchmark_context.h index 9477b2a5..752edf5b 100644 --- a/benchmarks/proxy_invocation_benchmark_context.h +++ b/benchmarks/proxy_invocation_benchmark_context.h @@ -4,7 +4,7 @@ #include #include -#include "proxy.h" +#include PRO_DEF_MEM_DISPATCH(MemFun, Fun); diff --git a/benchmarks/proxy_management_benchmark.cpp b/benchmarks/proxy_management_benchmark.cpp index ce7b2501..273576a9 100644 --- a/benchmarks/proxy_management_benchmark.cpp +++ b/benchmarks/proxy_management_benchmark.cpp @@ -9,7 +9,7 @@ #include -#include "proxy.h" +#include namespace { diff --git a/docs/PRO_DEF_FREE_AS_MEM_DISPATCH.md b/docs/PRO_DEF_FREE_AS_MEM_DISPATCH.md index d2fb494f..75772271 100644 --- a/docs/PRO_DEF_FREE_AS_MEM_DISPATCH.md +++ b/docs/PRO_DEF_FREE_AS_MEM_DISPATCH.md @@ -51,7 +51,7 @@ struct dispatch_name { #include #include -#include "proxy.h" +#include PRO_DEF_FREE_AS_MEM_DISPATCH(FreeToString, std::to_string, ToString); diff --git a/docs/PRO_DEF_FREE_DISPATCH.md b/docs/PRO_DEF_FREE_DISPATCH.md index c65ecc81..ad02a16f 100644 --- a/docs/PRO_DEF_FREE_DISPATCH.md +++ b/docs/PRO_DEF_FREE_DISPATCH.md @@ -49,7 +49,7 @@ struct dispatch_name { #include #include -#include "proxy.h" +#include PRO_DEF_FREE_DISPATCH(FreeToString, std::to_string, ToString); diff --git a/docs/PRO_DEF_MEM_DISPATCH.md b/docs/PRO_DEF_MEM_DISPATCH.md index 55f3641b..9a86326a 100644 --- a/docs/PRO_DEF_MEM_DISPATCH.md +++ b/docs/PRO_DEF_MEM_DISPATCH.md @@ -52,7 +52,7 @@ struct dispatch_name { #include #include -#include "proxy.h" +#include PRO_DEF_MEM_DISPATCH(MemAt, at); diff --git a/docs/PRO_DEF_WEAK_DISPATCH.md b/docs/PRO_DEF_WEAK_DISPATCH.md index 09714915..7cd29167 100644 --- a/docs/PRO_DEF_WEAK_DISPATCH.md +++ b/docs/PRO_DEF_WEAK_DISPATCH.md @@ -39,7 +39,7 @@ In [Java](https://docs.oracle.com/javase/specs/jls/se23/html/jls-9.html#jls-9.4- #include #include -#include "proxy.h" +#include struct NotImplemented { explicit NotImplemented(auto&&...) { throw std::runtime_error{ "Not implemented!" }; } diff --git a/docs/access_proxy.md b/docs/access_proxy.md index 0d1bfe6d..0a39823c 100644 --- a/docs/access_proxy.md +++ b/docs/access_proxy.md @@ -33,7 +33,7 @@ Similar to [`proxy_invoke`](proxy_invoke.md), this function can be used to imple #include #include -#include "proxy.h" +#include PRO_DEF_FREE_DISPATCH(FreeToString, std::to_string, ToString); diff --git a/docs/allocate_proxy.md b/docs/allocate_proxy.md index cb9a911d..1e2f70ec 100644 --- a/docs/allocate_proxy.md +++ b/docs/allocate_proxy.md @@ -41,7 +41,7 @@ The implementation of `allocated-ptr` may vary depending on the definition of `F ```cpp #include -#include "proxy.h" +#include // By default, the maximum pointer size defined by pro::facade_builder // is 2 * sizeof(void*). This value can be overridden by `restrict_layout`. diff --git a/docs/allocate_proxy_shared.md b/docs/allocate_proxy_shared.md index 14d6006f..c1e2ccf2 100644 --- a/docs/allocate_proxy_shared.md +++ b/docs/allocate_proxy_shared.md @@ -42,7 +42,7 @@ The implementation of `strong-compact-ptr` may vary depending on the definition #include #include -#include "proxy.h" +#include struct RttiAware : pro::facade_builder ::support_copy diff --git a/docs/basic_facade_builder.md b/docs/basic_facade_builder.md index 39e5107b..b231b557 100644 --- a/docs/basic_facade_builder.md +++ b/docs/basic_facade_builder.md @@ -115,7 +115,7 @@ struct CopyableCallable : pro::facade_builder ```cpp #include -#include "proxy.h" +#include template struct MovableCallable : pro::facade_builder diff --git a/docs/basic_facade_builder/add_convention.md b/docs/basic_facade_builder/add_convention.md index 165ddc1a..aba5f395 100644 --- a/docs/basic_facade_builder/add_convention.md +++ b/docs/basic_facade_builder/add_convention.md @@ -38,7 +38,7 @@ Adding duplicated combinations of some dispatch type and overload type is well-d #include #include -#include "proxy.h" +#include PRO_DEF_FREE_DISPATCH(FreeToString, std::to_string, ToString); diff --git a/docs/basic_facade_builder/add_facade.md b/docs/basic_facade_builder/add_facade.md index 0fa12812..6a843bc1 100644 --- a/docs/basic_facade_builder/add_facade.md +++ b/docs/basic_facade_builder/add_facade.md @@ -17,7 +17,7 @@ Adding a facade type that contains duplicated convention or reflection types alr #include #include -#include "proxy.h" +#include PRO_DEF_MEM_DISPATCH(MemSize, size); PRO_DEF_MEM_DISPATCH(MemAt, at); diff --git a/docs/basic_facade_builder/add_reflection.md b/docs/basic_facade_builder/add_reflection.md index 4edc03a8..7a5e99d9 100644 --- a/docs/basic_facade_builder/add_reflection.md +++ b/docs/basic_facade_builder/add_reflection.md @@ -35,7 +35,7 @@ Adding duplicate reflection types is well-defined, whether done directly via `ad #include #include -#include "proxy.h" +#include struct LayoutReflector { public: diff --git a/docs/basic_facade_builder/build.md b/docs/basic_facade_builder/build.md index d365fa0b..75ab53fa 100644 --- a/docs/basic_facade_builder/build.md +++ b/docs/basic_facade_builder/build.md @@ -57,7 +57,7 @@ The default values of the fields of [`proxiable_ptr_constraints`](../proxiable_p ```cpp #include -#include "proxy.h" +#include struct DefaultBase : pro::facade_builder ::build {}; diff --git a/docs/basic_facade_builder/restrict_layout.md b/docs/basic_facade_builder/restrict_layout.md index 3d78fb61..c291d368 100644 --- a/docs/basic_facade_builder/restrict_layout.md +++ b/docs/basic_facade_builder/restrict_layout.md @@ -18,7 +18,7 @@ If no layout restriction is applied before specifying [`build`](build.md), the d #include #include -#include "proxy.h" +#include struct DefaultFacade : pro::facade_builder::build {}; diff --git a/docs/basic_facade_builder/support_copy.md b/docs/basic_facade_builder/support_copy.md index 79a7d508..986a2832 100644 --- a/docs/basic_facade_builder/support_copy.md +++ b/docs/basic_facade_builder/support_copy.md @@ -16,7 +16,7 @@ If no copyability support is applied before specifying [`build`](build.md), the ```cpp #include -#include "proxy.h" +#include struct Movable : pro::facade_builder::build {}; diff --git a/docs/basic_facade_builder/support_destruction.md b/docs/basic_facade_builder/support_destruction.md index 66f705e1..e7387af6 100644 --- a/docs/basic_facade_builder/support_destruction.md +++ b/docs/basic_facade_builder/support_destruction.md @@ -16,7 +16,7 @@ If no destructibility support is applied before specifying [`build`](build.md), ```cpp #include -#include "proxy.h" +#include struct Movable : pro::facade_builder::build {}; diff --git a/docs/basic_facade_builder/support_format.md b/docs/basic_facade_builder/support_format.md index 3866fcfa..a44a5691 100644 --- a/docs/basic_facade_builder/support_format.md +++ b/docs/basic_facade_builder/support_format.md @@ -16,7 +16,7 @@ The member types `support_format` and `support_wformat` of `basic_facade_builder #include #include -#include "proxy.h" +#include struct Formattable : pro::facade_builder ::support_format diff --git a/docs/basic_facade_builder/support_relocation.md b/docs/basic_facade_builder/support_relocation.md index a59cfade..f5f5b7af 100644 --- a/docs/basic_facade_builder/support_relocation.md +++ b/docs/basic_facade_builder/support_relocation.md @@ -16,7 +16,7 @@ If no relocatability support is applied before specifying [`build`](build.md), t ```cpp #include -#include "proxy.h" +#include struct Movable : pro::facade_builder::build {}; diff --git a/docs/basic_facade_builder/support_rtti.md b/docs/basic_facade_builder/support_rtti.md index f6fdc917..92a7bf99 100644 --- a/docs/basic_facade_builder/support_rtti.md +++ b/docs/basic_facade_builder/support_rtti.md @@ -22,7 +22,7 @@ The member types `support_rtti`, `support_indirect_rtti` and `support_direct_rtt ```cpp #include -#include "proxy.h" +#include struct RttiAware : pro::facade_builder ::support_rtti diff --git a/docs/basic_facade_builder/support_rtti/proxy_cast.md b/docs/basic_facade_builder/support_rtti/proxy_cast.md index 8922cb57..9419bbab 100644 --- a/docs/basic_facade_builder/support_rtti/proxy_cast.md +++ b/docs/basic_facade_builder/support_rtti/proxy_cast.md @@ -61,7 +61,7 @@ These functions are not visible to ordinary [unqualified](https://en.cppreferenc ```cpp #include -#include "proxy.h" +#include struct RttiAware : pro::facade_builder ::support_rtti diff --git a/docs/basic_facade_builder/support_rtti/proxy_typeid.md b/docs/basic_facade_builder/support_rtti/proxy_typeid.md index d5fae268..9d8e8531 100644 --- a/docs/basic_facade_builder/support_rtti/proxy_typeid.md +++ b/docs/basic_facade_builder/support_rtti/proxy_typeid.md @@ -20,7 +20,7 @@ These functions are not visible to ordinary [unqualified](https://en.cppreferenc ```cpp #include -#include "proxy.h" +#include struct RttiAware : pro::facade_builder ::support_rtti diff --git a/docs/basic_facade_builder/support_view.md b/docs/basic_facade_builder/support_view.md index ca6324bb..900d0d93 100644 --- a/docs/basic_facade_builder/support_view.md +++ b/docs/basic_facade_builder/support_view.md @@ -17,7 +17,7 @@ Let `p` be a value of type `proxy`, `ptr` be the contained value of `p` (if a ```cpp #include -#include "proxy.h" +#include struct RttiAware : pro::facade_builder ::support_rtti diff --git a/docs/basic_facade_builder/support_weak.md b/docs/basic_facade_builder/support_weak.md index 81a3378c..3ea1bbd1 100644 --- a/docs/basic_facade_builder/support_weak.md +++ b/docs/basic_facade_builder/support_weak.md @@ -17,7 +17,7 @@ Let `p` be a value of type `proxy`, `ptr` of type `P` be the contained value ```cpp #include -#include "proxy.h" +#include struct Formattable : pro::facade_builder ::support_format diff --git a/docs/explicit_conversion_dispatch.md b/docs/explicit_conversion_dispatch.md index 44072034..ecb159de 100644 --- a/docs/explicit_conversion_dispatch.md +++ b/docs/explicit_conversion_dispatch.md @@ -26,7 +26,7 @@ Class `explicit_conversion_dispatch` models a [dispatch](ProDispatch.md) type fo ```cpp #include -#include "proxy.h" +#include struct IntConvertible : pro::facade_builder ::add_convention diff --git a/docs/facade_aware_overload_t.md b/docs/facade_aware_overload_t.md index 67865984..97f132eb 100644 --- a/docs/facade_aware_overload_t.md +++ b/docs/facade_aware_overload_t.md @@ -16,7 +16,7 @@ Class template `facade_aware_overload_t` specifies a facade-aware overload te ```cpp #include -#include "proxy.h" +#include template using BinaryOverload = pro::proxy(const pro::proxy_indirect_accessor& rhs) const; diff --git a/docs/implicit_conversion_dispatch.md b/docs/implicit_conversion_dispatch.md index ae57ffc9..dbaa2a01 100644 --- a/docs/implicit_conversion_dispatch.md +++ b/docs/implicit_conversion_dispatch.md @@ -24,7 +24,7 @@ Class `implicit_conversion_dispatch` models a [dispatch](ProDispatch.md) type fo ```cpp #include -#include "proxy.h" +#include struct Runnable : pro::facade_builder ::add_convention, void()> diff --git a/docs/inplace_proxiable_target.md b/docs/inplace_proxiable_target.md index 22e182ed..a6cfb8db 100644 --- a/docs/inplace_proxiable_target.md +++ b/docs/inplace_proxiable_target.md @@ -12,7 +12,7 @@ See [`make_proxy_inplace`](make_proxy_inplace.md) for the definition of the expo ```cpp #include -#include "proxy.h" +#include // By default, the maximum pointer size defined by pro::facade_builder // is 2 * sizeof(void*). This value can be overridden by `restrict_layout`. diff --git a/docs/make_proxy.md b/docs/make_proxy.md index 07482bd1..da61ac8c 100644 --- a/docs/make_proxy.md +++ b/docs/make_proxy.md @@ -50,7 +50,7 @@ Throws any exception thrown by allocation and the constructor of `T`. #include #include -#include "proxy.h" +#include struct Printable : pro::facade_builder ::add_convention, std::ostream&(std::ostream&) const> diff --git a/docs/make_proxy_inplace.md b/docs/make_proxy_inplace.md index c2143c5c..b622e9b6 100644 --- a/docs/make_proxy_inplace.md +++ b/docs/make_proxy_inplace.md @@ -44,7 +44,7 @@ Throws any exception thrown by the constructor of `T`. ```cpp #include -#include "proxy.h" +#include // By default, the maximum pointer size defined by pro::facade_builder // is 2 * sizeof(void*). This value can be overridden by `restrict_layout`. diff --git a/docs/make_proxy_shared.md b/docs/make_proxy_shared.md index c6a5f7d0..09cf6689 100644 --- a/docs/make_proxy_shared.md +++ b/docs/make_proxy_shared.md @@ -35,7 +35,7 @@ Throws any exception thrown by allocation and the constructor of `T`. ```cpp #include -#include "proxy.h" +#include struct RttiAware : pro::facade_builder ::support_copy diff --git a/docs/make_proxy_view.md b/docs/make_proxy_view.md index 9316049a..b18b9d26 100644 --- a/docs/make_proxy_view.md +++ b/docs/make_proxy_view.md @@ -20,7 +20,7 @@ The constructed `proxy_view` object. #include #include -#include "proxy.h" +#include PRO_DEF_MEM_DISPATCH(MemAt, at); diff --git a/docs/msft_lib_proxy.md b/docs/msft_lib_proxy.md index 9b8836c3..4f642c1e 100644 --- a/docs/msft_lib_proxy.md +++ b/docs/msft_lib_proxy.md @@ -19,7 +19,7 @@ Similar to the standard [feature test macros](https://en.cppreference.com/w/cpp/ ```cpp #include -#include "proxy.h" +#include int main() { #if defined(__msft_lib_proxy) && __msft_lib_proxy >= 202408L diff --git a/docs/operator_dispatch.md b/docs/operator_dispatch.md index 52114d4e..1db33def 100644 --- a/docs/operator_dispatch.md +++ b/docs/operator_dispatch.md @@ -120,7 +120,7 @@ Let `self` be the operand of [`proxy`](proxy.md), and `other` and `others...` be #include #include -#include "proxy.h" +#include struct Number : pro::facade_builder ::add_convention, void(int)> diff --git a/docs/proxiable.md b/docs/proxiable.md index 70bcb12f..33237d0b 100644 --- a/docs/proxiable.md +++ b/docs/proxiable.md @@ -13,7 +13,7 @@ The concept `proxiable` specifies that [`proxy`](proxy.md) can potentia #include #include -#include "proxy.h" +#include PRO_DEF_FREE_DISPATCH(FreeToString, std::to_string, ToString); diff --git a/docs/proxiable_target.md b/docs/proxiable_target.md index c077c28a..444b7adc 100644 --- a/docs/proxiable_target.md +++ b/docs/proxiable_target.md @@ -10,7 +10,7 @@ See [`make_proxy_view`](make_proxy_view.md) for the definition of the exposition ## Example ```cpp -#include "proxy.h" +#include struct Runnable : pro::facade_builder ::add_convention, void()> diff --git a/docs/proxy.md b/docs/proxy.md index 68559a16..4ebf400c 100644 --- a/docs/proxy.md +++ b/docs/proxy.md @@ -48,7 +48,7 @@ Another major difference is that `proxy` is open to abstractions. Unlike `std::f #include #include -#include "proxy.h" +#include PRO_DEF_MEM_DISPATCH(MemAt, at); diff --git a/docs/proxy/constructor.md b/docs/proxy/constructor.md index d3f1df2c..523d4f53 100644 --- a/docs/proxy/constructor.md +++ b/docs/proxy/constructor.md @@ -85,7 +85,7 @@ The constructors of `proxy` are similar to but have certain differences from #include #include -#include "proxy.h" +#include PRO_DEF_MEM_DISPATCH(MemSize, size); PRO_DEF_MEM_DISPATCH(MemClear, clear); diff --git a/docs/proxy/destructor.md b/docs/proxy/destructor.md index 2e85df2e..08066a3a 100644 --- a/docs/proxy/destructor.md +++ b/docs/proxy/destructor.md @@ -15,7 +15,7 @@ Destroys the `proxy` object. If the `proxy` contains a value, the contained valu ```cpp #include -#include "proxy.h" +#include struct AnyMovable : pro::facade_builder::build {}; diff --git a/docs/proxy/emplace.md b/docs/proxy/emplace.md index 3225528e..ef98f205 100644 --- a/docs/proxy/emplace.md +++ b/docs/proxy/emplace.md @@ -47,7 +47,7 @@ Similar to [`std::any::emplace`](https://en.cppreference.com/w/cpp/utility/any/e #include #include -#include "proxy.h" +#include struct AnyCopyable : pro::facade_builder ::support_copy diff --git a/docs/proxy/friend_operator_equality.md b/docs/proxy/friend_operator_equality.md index 0e281abc..e4b7e0a5 100644 --- a/docs/proxy/friend_operator_equality.md +++ b/docs/proxy/friend_operator_equality.md @@ -19,7 +19,7 @@ The `!=` operator is [synthesized](https://en.cppreference.com/w/cpp/language/de ```cpp #include -#include "proxy.h" +#include struct AnyMovable : pro::facade_builder::build {}; diff --git a/docs/proxy/friend_swap.md b/docs/proxy/friend_swap.md index 637dbcc3..ee5c1e16 100644 --- a/docs/proxy/friend_swap.md +++ b/docs/proxy/friend_swap.md @@ -15,7 +15,7 @@ This function is not visible to ordinary [unqualified](https://en.cppreference.c #include #include -#include "proxy.h" +#include PRO_DEF_FREE_DISPATCH(FreeToString, std::to_string, ToString); diff --git a/docs/proxy/indirection.md b/docs/proxy/indirection.md index c2160557..fb6ae42d 100644 --- a/docs/proxy/indirection.md +++ b/docs/proxy/indirection.md @@ -38,7 +38,7 @@ These operators do not check whether the `proxy` contains a value. To check whet #include #include -#include "proxy.h" +#include PRO_DEF_MEM_DISPATCH(MemSize, size); diff --git a/docs/proxy/operator_bool.md b/docs/proxy/operator_bool.md index d5409afb..b7507c04 100644 --- a/docs/proxy/operator_bool.md +++ b/docs/proxy/operator_bool.md @@ -16,7 +16,7 @@ Checks whether `*this` contains a value. ```cpp #include -#include "proxy.h" +#include struct AnyMovable : pro::facade_builder::build {}; diff --git a/docs/proxy/reset.md b/docs/proxy/reset.md index fedd8af7..0d867832 100644 --- a/docs/proxy/reset.md +++ b/docs/proxy/reset.md @@ -13,7 +13,7 @@ Destroys the contained value if it exists. After the call, `*this` does not cont ```cpp #include -#include "proxy.h" +#include struct AnyMovable : pro::facade_builder::build {}; diff --git a/docs/proxy_invoke.md b/docs/proxy_invoke.md index 61ea063e..0ae4ba11 100644 --- a/docs/proxy_invoke.md +++ b/docs/proxy_invoke.md @@ -45,7 +45,7 @@ It is generally not recommended to call `proxy_invoke` directly. Using an [`acce #include #include -#include "proxy.h" +#include PRO_DEF_FREE_DISPATCH(FreeToString, std::to_string, ToString); diff --git a/docs/proxy_reflect.md b/docs/proxy_reflect.md index 6e08849f..a1ae872c 100644 --- a/docs/proxy_reflect.md +++ b/docs/proxy_reflect.md @@ -20,7 +20,7 @@ This function is useful when only metadata deduced from a type is needed. While #include #include -#include "proxy.h" +#include class CopyabilityReflector { public: diff --git a/docs/proxy_view.md b/docs/proxy_view.md index be7e1292..a1dad95a 100644 --- a/docs/proxy_view.md +++ b/docs/proxy_view.md @@ -28,7 +28,7 @@ Class template `observer_facade` is a [facade](facade.md) type for observer poin ```cpp #include -#include "proxy.h" +#include template struct FMap : pro::facade_builder diff --git a/docs/weak_dispatch.md b/docs/weak_dispatch.md index 8e7cdf77..0633b5bb 100644 --- a/docs/weak_dispatch.md +++ b/docs/weak_dispatch.md @@ -28,7 +28,7 @@ In [Java](https://docs.oracle.com/javase/specs/jls/se23/html/jls-9.html#jls-9.4- #include #include -#include "proxy.h" +#include PRO_DEF_MEM_DISPATCH(MemAt, at); diff --git a/docs/weak_proxy.md b/docs/weak_proxy.md index c663f161..f0681b77 100644 --- a/docs/weak_proxy.md +++ b/docs/weak_proxy.md @@ -28,7 +28,7 @@ Class template `weak_facade` is a [facade](facade.md) type for weak pointers (e. ```cpp #include -#include "proxy.h" +#include struct Formattable : pro::facade_builder ::support_format diff --git a/proxy.h b/include/proxy/proxy.h similarity index 100% rename from proxy.h rename to include/proxy/proxy.h diff --git a/samples/PRO_DEF_WEAK_DISPATCH.cpp b/samples/PRO_DEF_WEAK_DISPATCH.cpp deleted file mode 100644 index 2ea7fb48..00000000 --- a/samples/PRO_DEF_WEAK_DISPATCH.cpp +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// This file contains example code from PRO_DEF_WEAK_DISPATCH.md. - -#include -#include -#include - -#include "proxy.h" - -struct NotImplemented { - explicit NotImplemented(auto&&...) { throw std::runtime_error{ "Not implemented!" }; } - - template - operator T() const noexcept { std::terminate(); } // Or std::unreachable() in C++23 -}; - -PRO_DEF_MEM_DISPATCH(MemAt, at); -PRO_DEF_WEAK_DISPATCH(WeakMemAt, MemAt, NotImplemented); - -struct WeakDictionary : pro::facade_builder - ::add_convention - ::build {}; - -int main() { - std::vector v{"hello", "world"}; - pro::proxy p1 = &v; - std::cout << p1->at(1) << "\n"; // Prints "world" - pro::proxy p2 = pro::make_proxy(123); - try { - p2->at(1); - } catch (const std::runtime_error& e) { - std::cout << e.what() << "\n"; // Prints "Not implemented!" - } -} diff --git a/tests/freestanding/proxy_freestanding_tests.cpp b/tests/freestanding/proxy_freestanding_tests.cpp index fc584e55..9659d19c 100644 --- a/tests/freestanding/proxy_freestanding_tests.cpp +++ b/tests/freestanding/proxy_freestanding_tests.cpp @@ -2,7 +2,7 @@ #error "This file shall be compiled targeting a freestanding environment." #endif // __STDC_HOSTED__ -#include "proxy.h" +#include constexpr unsigned DefaultHash = -1; unsigned GetHash(int v) { return static_cast(v + 3) * 31; } diff --git a/tests/proxy_creation_tests.cpp b/tests/proxy_creation_tests.cpp index ad78f3f2..afb331f6 100644 --- a/tests/proxy_creation_tests.cpp +++ b/tests/proxy_creation_tests.cpp @@ -1,10 +1,10 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +#include "utils.h" #include #include -#include "proxy.h" -#include "utils.h" +#include namespace proxy_creation_tests_details { diff --git a/tests/proxy_dispatch_tests.cpp b/tests/proxy_dispatch_tests.cpp index aa08a6d0..373e3d31 100644 --- a/tests/proxy_dispatch_tests.cpp +++ b/tests/proxy_dispatch_tests.cpp @@ -8,7 +8,7 @@ #pragma warning(push) #pragma warning(disable: 4834) // False alarm from MSVC: warning C4834: discarding return value of function with [[nodiscard]] attribute #endif // defined(_MSC_VER) && !defined(__clang__) -#include "proxy.h" +#include #if defined(_MSC_VER) && !defined(__clang__) #pragma warning(pop) #endif // defined(_MSC_VER) && !defined(__clang__) diff --git a/tests/proxy_format_tests.cpp b/tests/proxy_format_tests.cpp index c5beab21..432728c6 100644 --- a/tests/proxy_format_tests.cpp +++ b/tests/proxy_format_tests.cpp @@ -2,7 +2,7 @@ // Licensed under the MIT License. #include -#include "proxy.h" +#include namespace proxy_format_tests_details { diff --git a/tests/proxy_integration_tests.cpp b/tests/proxy_integration_tests.cpp index a85f162e..a0a76e8a 100644 --- a/tests/proxy_integration_tests.cpp +++ b/tests/proxy_integration_tests.cpp @@ -6,10 +6,10 @@ #include #include #include +#include #include #include #include -#include "proxy.h" namespace proxy_integration_tests_details { diff --git a/tests/proxy_invocation_tests.cpp b/tests/proxy_invocation_tests.cpp index 3610138e..cb479963 100644 --- a/tests/proxy_invocation_tests.cpp +++ b/tests/proxy_invocation_tests.cpp @@ -17,7 +17,7 @@ #pragma warning(push) #pragma warning(disable: 4702) // False alarm from MSVC: warning C4702: unreachable code #endif // defined(_MSC_VER) && !defined(__clang__) -#include "proxy.h" +#include #if defined(_MSC_VER) && !defined(__clang__) #pragma warning(pop) #endif // defined(_MSC_VER) && !defined(__clang__) diff --git a/tests/proxy_lifetime_tests.cpp b/tests/proxy_lifetime_tests.cpp index feb447b0..707ff207 100644 --- a/tests/proxy_lifetime_tests.cpp +++ b/tests/proxy_lifetime_tests.cpp @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -#include -#include "proxy.h" #include "utils.h" +#include +#include namespace proxy_lifetime_tests_details { diff --git a/tests/proxy_reflection_tests.cpp b/tests/proxy_reflection_tests.cpp index e4c157a0..0571319b 100644 --- a/tests/proxy_reflection_tests.cpp +++ b/tests/proxy_reflection_tests.cpp @@ -1,11 +1,11 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +#include "utils.h" #include #include +#include #include -#include "proxy.h" -#include "utils.h" namespace proxy_reflection_tests_details { diff --git a/tests/proxy_regression_tests.cpp b/tests/proxy_regression_tests.cpp index 84ca515a..aabfda53 100644 --- a/tests/proxy_regression_tests.cpp +++ b/tests/proxy_regression_tests.cpp @@ -2,8 +2,8 @@ // Licensed under the MIT License. #include +#include #include -#include "proxy.h" namespace proxy_regression_tests_details { diff --git a/tests/proxy_rtti_tests.cpp b/tests/proxy_rtti_tests.cpp index 42b0b6fd..4c83a6fb 100644 --- a/tests/proxy_rtti_tests.cpp +++ b/tests/proxy_rtti_tests.cpp @@ -2,8 +2,8 @@ // Licensed under the MIT License. #include +#include #include -#include "proxy.h" namespace proxy_rtti_tests_details { diff --git a/tests/proxy_traits_tests.cpp b/tests/proxy_traits_tests.cpp index 55259c5b..77004ec7 100644 --- a/tests/proxy_traits_tests.cpp +++ b/tests/proxy_traits_tests.cpp @@ -1,11 +1,11 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +#include "utils.h" #include +#include #include #include -#include "proxy.h" -#include "utils.h" namespace proxy_traits_tests_details { diff --git a/tests/proxy_view_tests.cpp b/tests/proxy_view_tests.cpp index 7788007b..5835d549 100644 --- a/tests/proxy_view_tests.cpp +++ b/tests/proxy_view_tests.cpp @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -#include -#include "proxy.h" #include "utils.h" +#include +#include namespace proxy_view_tests_details { diff --git a/tests/utils.h b/tests/utils.h index 1ae4ba00..cdda99d9 100644 --- a/tests/utils.h +++ b/tests/utils.h @@ -4,6 +4,7 @@ #ifndef _MSFT_PROXY_TEST_UTILS_ #define _MSFT_PROXY_TEST_UTILS_ +#include #include #include From 20474cdb2732556901715bda8688d159c39d0981 Mon Sep 17 00:00:00 2001 From: Mingxin Wang Date: Mon, 9 Jun 2025 22:31:26 +0800 Subject: [PATCH 6/8] Backport compatibility changes (#310) --- CMakeLists.txt | 1 + docs/msft_lib_proxy.md | 1 + include/proxy/proxy.h | 2540 +------------------------------------ include/proxy/v3/proxy.h | 2606 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 2610 insertions(+), 2538 deletions(-) create mode 100644 include/proxy/v3/proxy.h diff --git a/CMakeLists.txt b/CMakeLists.txt index c8c041be..f615d7e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,7 @@ target_sources(msft_proxy BASE_DIRS include FILES include/proxy/proxy.h + include/proxy/v3/proxy.h ) target_compile_features(msft_proxy INTERFACE cxx_std_20) diff --git a/docs/msft_lib_proxy.md b/docs/msft_lib_proxy.md index 4f642c1e..356078a7 100644 --- a/docs/msft_lib_proxy.md +++ b/docs/msft_lib_proxy.md @@ -8,6 +8,7 @@ Similar to the standard [feature test macros](https://en.cppreference.com/w/cpp/ | Version | Value of `__msft_lib_proxy` | | ------- | --------------------------- | +| 3.4.0 | `202505L` | | 3.3.0 | `202503L` | | 3.2.1 | `202502L` | | 3.2.0 | `202501L` | diff --git a/include/proxy/proxy.h b/include/proxy/proxy.h index 02fde832..7ebd2f38 100644 --- a/include/proxy/proxy.h +++ b/include/proxy/proxy.h @@ -4,2542 +4,6 @@ #ifndef _MSFT_PROXY_ #define _MSFT_PROXY_ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "v3/proxy.h" // IWYU pragma: export -#if __STDC_HOSTED__ -#include -#include -#endif // __STDC_HOSTED__ - -#if __cpp_rtti >= 199711L -#include -#include -#endif // __cpp_rtti >= 199711L - -#if __has_cpp_attribute(msvc::no_unique_address) -#define ___PRO_NO_UNIQUE_ADDRESS_ATTRIBUTE msvc::no_unique_address -#elif __has_cpp_attribute(no_unique_address) -#define ___PRO_NO_UNIQUE_ADDRESS_ATTRIBUTE no_unique_address -#else -#error "Proxy requires C++20 attribute no_unique_address" -#endif - -#if __cpp_exceptions >= 199711L -#define ___PRO_THROW(...) throw __VA_ARGS__ -#else -#define ___PRO_THROW(...) std::abort() -#endif // __cpp_exceptions >= 199711L - -#if __cpp_static_call_operator >= 202207L -#define ___PRO_STATIC_CALL(__R, ...) static __R operator()(__VA_ARGS__) -#else -#define ___PRO_STATIC_CALL(__R, ...) __R operator()(__VA_ARGS__) const -#endif // __cpp_static_call_operator >= 202207L - -#ifdef _MSC_VER -#define ___PRO_ENFORCE_EBO __declspec(empty_bases) -#else -#define ___PRO_ENFORCE_EBO -#endif // _MSC_VER - -#ifdef NDEBUG -#define ___PRO_DEBUG(...) -#else -#define ___PRO_DEBUG(...) __VA_ARGS__ -#endif // NDEBUG - -#define __msft_lib_proxy 202503L - -namespace pro { - -namespace details { - -struct applicable_traits { static constexpr bool applicable = true; }; -struct inapplicable_traits { static constexpr bool applicable = false; }; - -template