mirror of
https://github.com/boostorg/pfr.git
synced 2026-01-19 04:22:13 +00:00
core: add an implementation based on C++26 destructuring into a pack (#220)
Tested with clang-21 --------- Co-authored-by: Jean-Michaël Celerier <jeanmichael.celerier@gmail.com>
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
int main() {
|
||||
std::cout << "Platform info:" << '\n'
|
||||
<< "BOOST_PFR_USE_CPP17 == " << BOOST_PFR_USE_CPP17 << '\n'
|
||||
<< "BOOST_PFR_USE_CPP26 == " << BOOST_PFR_USE_CPP26 << '\n'
|
||||
<< "BOOST_PFR_USE_LOOPHOLE == " << BOOST_PFR_USE_LOOPHOLE << '\n'
|
||||
<< "BOOST_PFR_USE_STD_MAKE_INTEGRAL_SEQUENCE == " << BOOST_PFR_USE_STD_MAKE_INTEGRAL_SEQUENCE << '\n'
|
||||
<< "BOOST_PFR_HAS_GUARANTEED_COPY_ELISION == " << BOOST_PFR_HAS_GUARANTEED_COPY_ELISION << '\n'
|
||||
|
||||
@@ -23,7 +23,7 @@ project
|
||||
[ requires cxx14_constexpr ]
|
||||
;
|
||||
|
||||
########## BEGIN of helpers to detect Loophole trick support
|
||||
########## BEGIN of helpers to detect Loophole and variadic structured binding support
|
||||
|
||||
actions mp_simple_run_action
|
||||
{
|
||||
@@ -42,6 +42,9 @@ rule mp-run-simple ( sources + : args * : input-files * : requirements * : targe
|
||||
mp-run-simple loophole_detection.cpp : : : : compiler_supports_loophole ;
|
||||
explicit compiler_supports_loophole ;
|
||||
|
||||
mp-run-simple variadic_structured_binding_detection.cpp : : : : compiler_supports_vsb ;
|
||||
explicit compiler_supports_vsb ;
|
||||
|
||||
########## END of helpers to detect Loophole trick support
|
||||
|
||||
|
||||
@@ -49,10 +52,14 @@ local DISABLE_ON_MSVC = ; #<toolset>msvc:<build>no ;
|
||||
local REQUIRE_LOOPHOLE =
|
||||
[ check-target-builds ../core//compiler_supports_loophole : : <build>no ]
|
||||
;
|
||||
local REQUIRE_VSB =
|
||||
[ check-target-builds ../core//compiler_supports_vsb : : <build>no ]
|
||||
;
|
||||
|
||||
local STRUCTURED_BINDING_ENGINE = <define>BOOST_PFR_USE_LOOPHOLE=0 <define>BOOST_PFR_USE_CPP17=1 [ requires cxx17_structured_bindings ] ;
|
||||
local LOOPHOLE_ENGINE = <define>BOOST_PFR_USE_LOOPHOLE=1 <define>BOOST_PFR_USE_CPP17=0 $(REQUIRE_LOOPHOLE) ;
|
||||
local CLASSIC_ENGINE = <define>BOOST_PFR_USE_LOOPHOLE=0 <define>BOOST_PFR_USE_CPP17=0 $(DISABLE_ON_MSVC) ;
|
||||
local VARIADIC_STRUCTURED_BINDING_ENGINE = <define>BOOST_PFR_USE_LOOPHOLE=0 <define>BOOST_PFR_USE_CPP17=0 <define>BOOST_PFR_USE_CPP26=1 $(REQUIRE_VSB) ;
|
||||
local STRUCTURED_BINDING_ENGINE = <define>BOOST_PFR_USE_LOOPHOLE=0 <define>BOOST_PFR_USE_CPP17=1 <define>BOOST_PFR_USE_CPP26=0 [ requires cxx17_structured_bindings ] ;
|
||||
local LOOPHOLE_ENGINE = <define>BOOST_PFR_USE_LOOPHOLE=1 <define>BOOST_PFR_USE_CPP17=0 <define>BOOST_PFR_USE_CPP26=0 $(REQUIRE_LOOPHOLE) ;
|
||||
local CLASSIC_ENGINE = <define>BOOST_PFR_USE_LOOPHOLE=0 <define>BOOST_PFR_USE_CPP17=0 <define>BOOST_PFR_USE_CPP26=0 $(DISABLE_ON_MSVC) ;
|
||||
|
||||
test-suite pfr_tests
|
||||
:
|
||||
@@ -109,6 +116,7 @@ local BLACKLIST_TESTS_FOR_CLASSIC =
|
||||
for local source_file in [ glob ./run/*.cpp ] [ glob ../../example/*.cpp ]
|
||||
{
|
||||
local target_name = $(source_file[1]:B) ;
|
||||
pfr_tests += [ run $(source_file) : : : $(VARIADIC_STRUCTURED_BINDING_ENGINE) : $(target_name)_vsb ] ;
|
||||
pfr_tests += [ run $(source_file) : : : $(STRUCTURED_BINDING_ENGINE) : $(target_name)_sb ] ;
|
||||
|
||||
if ! $(target_name) in $(BLACKLIST_TESTS_FOR_LOOPHOLE)
|
||||
|
||||
@@ -24,7 +24,7 @@ struct A {
|
||||
};
|
||||
|
||||
int main() {
|
||||
#if BOOST_PFR_USE_CPP17 && !defined(BOOST_USE_MODULES) // TODO: fix for BOOST_USE_MODULES
|
||||
#if BOOST_PFR_USE_CPP17 && !BOOST_PFR_USE_CPP26 && !defined(BOOST_USE_MODULES) // TODO: fix for BOOST_USE_MODULES
|
||||
const volatile int cv_value = 0;
|
||||
volatile int v_value = 0;
|
||||
const int c_value = 0;
|
||||
|
||||
23
test/core/variadic_structured_binding_detection.cpp
Normal file
23
test/core/variadic_structured_binding_detection.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
// Copyright (c) 2020-2025 Antony Polukhin
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// Detection of variadic structured binding support
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
struct MyPair {
|
||||
int first;
|
||||
int second;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
auto test() {
|
||||
const auto& [...x] = T{};
|
||||
return x...[0];
|
||||
}
|
||||
|
||||
int main() {
|
||||
return ::test<MyPair>();
|
||||
}
|
||||
Reference in New Issue
Block a user