Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.28)

project(msft_proxy4 VERSION 4.0.1 LANGUAGES CXX)
project(msft_proxy4 VERSION 4.0.2 LANGUAGES CXX)
add_library(msft_proxy4 INTERFACE)
set_target_properties(msft_proxy4 PROPERTIES EXPORT_NAME proxy)
add_library(msft_proxy4::proxy ALIAS msft_proxy4)
Expand Down
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MIT License

Copyright (c) 2022-2026 Microsoft Corporation.
Copyright (c) 2026-Present Next Gen C++ Foundation.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ If so, this library is for you.

"Proxy" is a modern C++ library that helps you use polymorphism (a way to use different types of objects interchangeably) without needing inheritance.

"Proxy" was created by Microsoft engineers and incubated at Microsoft from 2018 to Feb 2026, and has been used in the Windows operating system since 2022. It is now maintained by the Next Gen C++ Foundation (ngcpp). This repository was ported from https://github.com/microsoft/proxy, where more historical releases can be found. For many years, using inheritance was the main way to achieve polymorphism in C++. However, new programming languages like [Rust](https://doc.rust-lang.org/book/ch10-02-traits.html) offer better ways to do this. We have improved our understanding of object-oriented programming and decided to use *pointers* in C++ as the foundation for "Proxy". Specifically, the "Proxy" library is designed to be:
"Proxy" was created by Microsoft engineers and incubated at Microsoft from 2018 to Feb 2026, and has been used in the Windows operating system since 2022. It is now maintained by the Next Gen C++ Foundation (ngcpp). This repository was ported from [microsoft/proxy](https://github.com/microsoft/proxy), where more historical releases can be found. For many years, using inheritance was the main way to achieve polymorphism in C++. However, new programming languages like [Rust](https://doc.rust-lang.org/book/ch10-02-traits.html) offer better ways to do this. We have improved our understanding of object-oriented programming and decided to use *pointers* in C++ as the foundation for "Proxy". Specifically, the "Proxy" library is designed to be:

- **Portable**: "Proxy" was implemented as a header-only library in standard C++20. It can be used on any platform while the compiler supports C++20. The majority of the library is [freestanding](https://en.cppreference.com/w/cpp/freestanding), making it feasible for embedded engineering or kernel design of an operating system.
- **Non-intrusive**: An implementation type is no longer required to inherit from an abstract binding.
Expand Down
1 change: 1 addition & 0 deletions benchmarks/proxy_creation_benchmark.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2022-2026 Microsoft Corporation.
// Copyright (c) 2026-Present Next Gen C++ Foundation.
// Licensed under the MIT License.

#include <any>
Expand Down
1 change: 1 addition & 0 deletions benchmarks/proxy_operation_benchmark.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2022-2026 Microsoft Corporation.
// Copyright (c) 2026-Present Next Gen C++ Foundation.
// Licensed under the MIT License.

#include <benchmark/benchmark.h>
Expand Down
1 change: 1 addition & 0 deletions benchmarks/proxy_operation_benchmark_context.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2022-2026 Microsoft Corporation.
// Copyright (c) 2026-Present Next Gen C++ Foundation.
// Licensed under the MIT License.

#include "proxy_operation_benchmark_context.h"
Expand Down
1 change: 1 addition & 0 deletions benchmarks/proxy_operation_benchmark_context.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2022-2026 Microsoft Corporation.
// Copyright (c) 2026-Present Next Gen C++ Foundation.
// Licensed under the MIT License.

#include <any>
Expand Down
Binary file modified docs/resources/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/spec/msft_lib_proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Starting with 3.0.0, Proxy ships a feature-test macro that encodes the library v

| Version | Value of `__msft_lib_proxy` |
| ------- | --------------------------- |
| 4.0.2 | `202603L` |
| 4.0.1 | `202510L` |
| 4.0.0 | `202508L` |
| 3.4.0 | `202505L` |
Expand Down
1 change: 1 addition & 0 deletions include/proxy/proxy.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2022-2026 Microsoft Corporation.
// Copyright (c) 2026-Present Next Gen C++ Foundation.
// Licensed under the MIT License.

#ifndef MSFT_PROXY_PROXY_H_
Expand Down
1 change: 1 addition & 0 deletions include/proxy/proxy_fmt.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2022-2026 Microsoft Corporation.
// Copyright (c) 2026-Present Next Gen C++ Foundation.
// Licensed under the MIT License.

#ifndef MSFT_PROXY_PROXY_FMT_H_
Expand Down
1 change: 1 addition & 0 deletions include/proxy/proxy_macros.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2022-2026 Microsoft Corporation.
// Copyright (c) 2026-Present Next Gen C++ Foundation.
// Licensed under the MIT License.

#ifndef MSFT_PROXY_PROXY_MACROS_H_
Expand Down
46 changes: 39 additions & 7 deletions include/proxy/v4/proxy.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2022-2026 Microsoft Corporation.
// Copyright (c) 2026-Present Next Gen C++ Foundation.
// Licensed under the MIT License.

#ifndef MSFT_PROXY_V4_PROXY_H_
Expand Down Expand Up @@ -1288,10 +1289,26 @@ struct converter {
template <class T>
operator T() && noexcept(
std::is_nothrow_invocable_r_v<T, F, std::in_place_type_t<T>>)
requires(std::is_invocable_r_v<T, F, std::in_place_type_t<T>>)
requires(std::is_invocable_r_v<T, F, std::in_place_type_t<T>> &&
!std::is_invocable_r_v<T, F, std::in_place_type_t<T&>> &&
!std::is_invocable_r_v<T, F, std::in_place_type_t<T &&>>)
{
return std::move(f_)(std::in_place_type<T>);
}
template <class T>
operator T&() && noexcept(
std::is_nothrow_invocable_r_v<T&, F, std::in_place_type_t<T&>>)
requires(std::is_invocable_r_v<T&, F, std::in_place_type_t<T&>>)
{
return std::move(f_)(std::in_place_type<T&>);
}
template <class T>
operator T&&() && noexcept(
std::is_nothrow_invocable_r_v<T&&, F, std::in_place_type_t<T&&>>)
requires(std::is_invocable_r_v<T &&, F, std::in_place_type_t<T &&>>)
{
return std::move(f_)(std::in_place_type<T&&>);
}

private:
F f_;
Expand Down Expand Up @@ -2346,14 +2363,29 @@ struct sign {
template <std::size_t N>
sign(const char (&str)[N]) -> sign<N - 1u>;

struct wildcard {
wildcard() = delete;
// When std::reference_constructs_from_temporary_v (C++23) is not available, we
// fall back to a conservative approximation that disallows binding a temporary
// to a reference type if the source type is not a reference or if the source
// and target reference types are not compatible.
template <class T, class U>
concept explicitly_convertible =
std::is_constructible_v<U, T> &&
#if __cpp_lib_reference_from_temporary >= 202202L
!std::reference_constructs_from_temporary_v<U, T>;
#else
(!std::is_reference_v<U> ||
(std::is_reference_v<T> &&
std::is_convertible_v<std::add_pointer_t<std::remove_reference_t<T>>,
std::add_pointer_t<std::remove_reference_t<U>>>));
#endif // __cpp_lib_reference_from_temporary >= 202202L

struct noreturn_conversion {
template <class T>
[[noreturn]] operator T() const {
[[noreturn]] PRO4D_STATIC_CALL(T, std::in_place_type_t<T>) {
PROD_UNREACHABLE();
}
};
using wildcard = converter<noreturn_conversion>;

} // namespace details

Expand Down Expand Up @@ -2577,9 +2609,9 @@ struct explicit_conversion_dispatch : details::cast_dispatch_base<true, false> {
PRO4D_STATIC_CALL(auto, T&& self) noexcept {
return details::converter{
[&self]<class U>(std::in_place_type_t<U>) noexcept(
std::is_nothrow_constructible_v<U, T>)
requires(std::is_constructible_v<U, T>)
{ return U{std::forward<T>(self)}; }};
std::is_nothrow_constructible_v<U, T>) -> U
requires(details::explicitly_convertible < T &&, U >)
{ return static_cast<U>(std::forward<T>(self)); }};
}
};
using conversion_dispatch = explicit_conversion_dispatch;
Expand Down
1 change: 1 addition & 0 deletions include/proxy/v4/proxy_fmt.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2022-2026 Microsoft Corporation.
// Copyright (c) 2026-Present Next Gen C++ Foundation.
// Licensed under the MIT License.

#ifndef MSFT_PROXY_V4_PROXY_FMT_H_
Expand Down
3 changes: 2 additions & 1 deletion include/proxy/v4/proxy_macros.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2022-2026 Microsoft Corporation.
// Copyright (c) 2026-Present Next Gen C++ Foundation.
// Licensed under the MIT License.

#ifndef MSFT_PROXY_V4_PROXY_MACROS_H_
Expand Down Expand Up @@ -28,7 +29,7 @@
#define PRO4D_DEBUG(...) __VA_ARGS__
#endif // NDEBUG

#define __msft_lib_proxy4 202510L
#define __msft_lib_proxy4 202603L

#define PRO4D_DIRECT_FUNC_IMPL(...) \
noexcept(noexcept(__VA_ARGS__)) \
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
project(
'msft_proxy4',
'cpp',
version: '4.0.1',
version: '4.0.2',
license: 'MIT',
license_files: 'LICENSE',
meson_version: '>=1.3',
Expand Down
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
site_name: Proxy 4
site_url: https://ngcpp.github.io/proxy
site_description: Next Generation Polymorphism in C++
copyright: Copyright (c) 2022-2026 Microsoft Corporation
copyright: Copyright (c) 2022-2026 Microsoft Corporation<br />Copyright (c) 2026-Present Next Gen C++ Foundation
repo_url: https://github.com/ngcpp/proxy/
edit_uri: ""

Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ include(GoogleTest)

add_executable(msft_proxy_tests
proxy_creation_tests.cpp
proxy_details_tests.cpp
proxy_dispatch_tests.cpp
proxy_fmt_format_tests.cpp
proxy_format_tests.cpp
Expand Down
1 change: 1 addition & 0 deletions tests/proxy_creation_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2022-2026 Microsoft Corporation.
// Copyright (c) 2026-Present Next Gen C++ Foundation.
// Licensed under the MIT License.

#include "utils.h"
Expand Down
31 changes: 31 additions & 0 deletions tests/proxy_details_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) 2026-Present Next Gen C++ Foundation.
// Licensed under the MIT License.

#include <proxy/proxy.h>

namespace proxy_details_tests_details {

struct Base {
int v;
};
struct Derived : Base {};

static_assert(pro::details::explicitly_convertible<int, int>);
static_assert(pro::details::explicitly_convertible<long, int>);
static_assert(!pro::details::explicitly_convertible<int, int&&>);
static_assert(!pro::details::explicitly_convertible<int, const int&>);
static_assert(pro::details::explicitly_convertible<int&&, int&&>);
static_assert(pro::details::explicitly_convertible<int&&, const int&>);
static_assert(!pro::details::explicitly_convertible<long&&, int&&>);
static_assert(!pro::details::explicitly_convertible<long, int&&>);
static_assert(pro::details::explicitly_convertible<Derived&, Base&>);
static_assert(pro::details::explicitly_convertible<Derived&, const Base&>);
static_assert(!pro::details::explicitly_convertible<Derived&, Base&&>);
static_assert(!pro::details::explicitly_convertible<const Derived&, Base&>);
static_assert(
pro::details::explicitly_convertible<const Derived&, const Base&>);
static_assert(pro::details::explicitly_convertible<Derived, Base>);
static_assert(!pro::details::explicitly_convertible<Derived, Base&&>);
static_assert(!pro::details::explicitly_convertible<Base&, Derived&>);

} // namespace proxy_details_tests_details
9 changes: 6 additions & 3 deletions tests/proxy_dispatch_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2022-2026 Microsoft Corporation.
// Copyright (c) 2026-Present Next Gen C++ Foundation.
// Licensed under the MIT License.

#include <gtest/gtest.h>
Expand Down Expand Up @@ -783,11 +784,13 @@ TEST(ProxyDispatchTests, TestRhsOpPtrToMem) {

TEST(ProxyDispatchTests, TestIndirectConversion) {
struct TestFacade
: pro::facade_builder::add_convention<pro::conversion_dispatch,
int()>::build {};
: pro::facade_builder //
::add_convention<pro::conversion_dispatch, int(), short&()> //
::build {};
short v = 123;
pro::proxy<TestFacade> p = &v;
ASSERT_EQ(static_cast<int>(*p), 123);
static_cast<short&>(*p) = 456;
ASSERT_EQ(static_cast<int>(*p), 456);
}

TEST(ProxyDispatchTests, TestDirectConversion) {
Expand Down
1 change: 1 addition & 0 deletions tests/proxy_fmt_format_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2022-2026 Microsoft Corporation.
// Copyright (c) 2026-Present Next Gen C++ Foundation.
// Licensed under the MIT License.

#include <gtest/gtest.h>
Expand Down
1 change: 1 addition & 0 deletions tests/proxy_format_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2022-2026 Microsoft Corporation.
// Copyright (c) 2026-Present Next Gen C++ Foundation.
// Licensed under the MIT License.

#include <gtest/gtest.h>
Expand Down
1 change: 1 addition & 0 deletions tests/proxy_integration_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2022-2026 Microsoft Corporation.
// Copyright (c) 2026-Present Next Gen C++ Foundation.
// Licensed under the MIT License.

#include <gtest/gtest.h>
Expand Down
1 change: 1 addition & 0 deletions tests/proxy_invocation_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2022-2026 Microsoft Corporation.
// Copyright (c) 2026-Present Next Gen C++ Foundation.
// Licensed under the MIT License.

#include <algorithm>
Expand Down
1 change: 1 addition & 0 deletions tests/proxy_lifetime_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2022-2026 Microsoft Corporation.
// Copyright (c) 2026-Present Next Gen C++ Foundation.
// Licensed under the MIT License.

#include "utils.h"
Expand Down
1 change: 1 addition & 0 deletions tests/proxy_reflection_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2022-2026 Microsoft Corporation.
// Copyright (c) 2026-Present Next Gen C++ Foundation.
// Licensed under the MIT License.

#include "utils.h"
Expand Down
24 changes: 24 additions & 0 deletions tests/proxy_regression_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
// Copyright (c) 2022-2026 Microsoft Corporation.
// Copyright (c) 2026-Present Next Gen C++ Foundation.
// Licensed under the MIT License.

#include <gtest/gtest.h>
#if defined(_MSC_VER) && !defined(__clang__)
#pragma warning(push)
#pragma warning( \
disable : 4702) // False alarm from MSVC: warning C4702: unreachable code
#endif // defined(_MSC_VER) && !defined(__clang__)
#include <proxy/proxy.h>
#if defined(_MSC_VER) && !defined(__clang__)
#pragma warning(pop)
#endif // defined(_MSC_VER) && !defined(__clang__)
#include <vector>

namespace proxy_regression_tests_details {
Expand Down Expand Up @@ -39,6 +48,8 @@ struct Range : pro::facade_builder //
::template add_convention<MemEnd, pro::proxy<Iterator<T>>()> //
::build {};

PRO_DEF_MEM_DISPATCH(MemFun, Fun);

} // namespace proxy_regression_tests_details

namespace details = proxy_regression_tests_details;
Expand Down Expand Up @@ -69,3 +80,16 @@ TEST(ProxyRegressionTests, TestProxiableSelfDependency) {
}
EXPECT_EQ(expected, original);
}

// https://github.com/ngcpp/proxy/issues/10
TEST(ProxyRegressionTests, TestWeakDispatchReferenceReturningOverload) {
struct MyFacade
: pro::facade_builder //
::add_convention<pro::weak_dispatch<details::MemFun>, int&()> //
::build {};
static_assert(pro::proxiable<int*, MyFacade>);

int v = 123;
pro::proxy<MyFacade> p = &v;
EXPECT_THROW(p->Fun(), pro::not_implemented);
}
1 change: 1 addition & 0 deletions tests/proxy_rtti_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2022-2026 Microsoft Corporation.
// Copyright (c) 2026-Present Next Gen C++ Foundation.
// Licensed under the MIT License.

#include <gtest/gtest.h>
Expand Down
1 change: 1 addition & 0 deletions tests/proxy_traits_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2022-2026 Microsoft Corporation.
// Copyright (c) 2026-Present Next Gen C++ Foundation.
// Licensed under the MIT License.

#include "utils.h"
Expand Down
1 change: 1 addition & 0 deletions tests/proxy_view_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2022-2026 Microsoft Corporation.
// Copyright (c) 2026-Present Next Gen C++ Foundation.
// Licensed under the MIT License.

#include "utils.h"
Expand Down
1 change: 1 addition & 0 deletions tests/utils.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2022-2026 Microsoft Corporation.
// Copyright (c) 2026-Present Next Gen C++ Foundation.
// Licensed under the MIT License.

#ifndef _MSFT_PROXY_TEST_UTILS_
Expand Down
1 change: 1 addition & 0 deletions tools/report_generator/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2022-2026 Microsoft Corporation.
// Copyright (c) 2026-Present Next Gen C++ Foundation.
// Licensed under the MIT License.

#include <cstdio>
Expand Down
Loading