mirror of
https://github.com/boostorg/pfr.git
synced 2026-01-19 04:22:13 +00:00
Parsing ala boost type_index
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/pfr/config.hpp> // inclusion of an another PFR header may fail when BOOST_PFR_ENABLED=0
|
||||
#include <boost/preprocessor/stringize.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
@@ -15,6 +16,8 @@ int main() {
|
||||
<< "BOOST_PFR_HAS_GUARANTEED_COPY_ELISION == " << BOOST_PFR_HAS_GUARANTEED_COPY_ELISION << '\n'
|
||||
<< "BOOST_PFR_ENABLE_IMPLICIT_REFLECTION == " << BOOST_PFR_ENABLE_IMPLICIT_REFLECTION << '\n'
|
||||
<< "BOOST_PFR_ENABLE_GET_NAME_STATIC == " << BOOST_PFR_ENABLE_GET_NAME_STATIC << '\n'
|
||||
<< "BOOST_PFR_FUNCTION_SIGNATURE == " << BOOST_PP_STRINGIZE(BOOST_PFR_FUNCTION_SIGNATURE) << '\n'
|
||||
<< "BOOST_PFR_CORE_NAME_PARSING == " << BOOST_PP_STRINGIZE(BOOST_PFR_CORE_NAME_PARSING) << '\n'
|
||||
<< "BOOST_PFR_ENABLED == " << BOOST_PFR_ENABLED << '\n'
|
||||
<< "__cplusplus == " << __cplusplus << '\n'
|
||||
#ifdef __cpp_structured_bindings
|
||||
|
||||
@@ -43,6 +43,8 @@ project
|
||||
[ check-target-builds ../core_name//compiler_supports_cxx20_nontype_template_args : : [ check-target-builds ../core_name//compiler_supports_cxx20_clang_workaround : : <build>no ] ]
|
||||
;
|
||||
|
||||
local ENABLED_ENGINE = <define>BOOST_PFR_ENABLE_GET_NAME_STATIC=1 ;
|
||||
local DISABLED_ENGINE = <define>BOOST_PFR_ENABLE_GET_NAME_STATIC=0 ;
|
||||
|
||||
|
||||
|
||||
@@ -54,12 +56,20 @@ actions invoke_python_generator
|
||||
make fields_names_nonascii.cpp : generate_fields_names_nonascii.cpp.py : @invoke_python_generator ;
|
||||
make fields_names_big.cpp : generate_fields_names_big.cpp.py : @invoke_python_generator ;
|
||||
|
||||
test-suite pfr_tests
|
||||
test-suite pfr_name_tests
|
||||
:
|
||||
[ run fields_names.cpp : : : : ]
|
||||
[ run fields_names_constexpr.cpp : : : : ]
|
||||
[ run fields_names_nonascii.cpp : : : <toolset>msvc:<cxxflags>"/utf-8" : ]
|
||||
[ run fields_names_big.cpp : : : <toolset>msvc:<cxxflags>"/bigobj" : ]
|
||||
[ run print_name.cpp : : : <test-info>always_show_run_output ]
|
||||
;
|
||||
|
||||
for local source_file in [ glob ./compile-fail/*.cpp ]
|
||||
{
|
||||
local target_name = $(source_file[1]:B) ;
|
||||
pfr_name_tests += [ compile-fail $(source_file) : $(ENABLED_ENGINE) : $(target_name)_on ] ;
|
||||
pfr_name_tests += [ compile-fail $(source_file) : $(DISABLED_ENGINE) : $(target_name)_off ] ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// Copyright (c) 2023 Bela Schaum, X-Ryl669, Denis Mikhailov.
|
||||
//
|
||||
// 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)
|
||||
|
||||
|
||||
// Initial implementation by Bela Schaum, https://github.com/schaumb
|
||||
// The way to make it union and UB free by X-Ryl669, https://github.com/X-Ryl669
|
||||
//
|
||||
|
||||
#define BOOST_PFR_FUNCTION_SIGNATURE ""
|
||||
#include <boost/pfr/core_name.hpp>
|
||||
|
||||
struct A { int field; };
|
||||
|
||||
int main() {
|
||||
(void)boost::pfr::get_name<0, A>(); // Must be a compile time error
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
// Copyright (c) 2023 Bela Schaum, X-Ryl669, Denis Mikhailov.
|
||||
//
|
||||
// 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)
|
||||
|
||||
|
||||
// Initial implementation by Bela Schaum, https://github.com/schaumb
|
||||
// The way to make it union and UB free by X-Ryl669, https://github.com/X-Ryl669
|
||||
//
|
||||
|
||||
#define BOOST_PFR_FUNCTION_SIGNATURE "dummy"
|
||||
#define BOOST_PFR_CORE_NAME_PARSING (0,0,"")
|
||||
#include <boost/pfr/core_name.hpp>
|
||||
|
||||
struct A { int field; };
|
||||
|
||||
int main() {
|
||||
(void)boost::pfr::get_name<0, A>(); // Must be a compile time error
|
||||
}
|
||||
|
||||
|
||||
33
test/core_name/print_name.cpp
Normal file
33
test/core_name/print_name.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
// Copyright (c) 2023 Bela Schaum, X-Ryl669, Denis Mikhailov.
|
||||
//
|
||||
// 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)
|
||||
|
||||
|
||||
// Initial implementation by Bela Schaum, https://github.com/schaumb
|
||||
// The way to make it union and UB free by X-Ryl669, https://github.com/X-Ryl669
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
|
||||
// This cpp file:
|
||||
// * tests BOOST_PFR_CORE_NAME_PARSING macro
|
||||
// * outputs full name of the function so that PFRs extraction of field name could be adjust to new compiler without requesting regression tester's help
|
||||
#define BOOST_PFR_CORE_NAME_PARSING (0,0,false,"")
|
||||
#include <boost/pfr/core_name.hpp>
|
||||
|
||||
namespace user_defined_namespace {
|
||||
struct user_defined_class { int user_defined_field; };
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace boost::pfr;
|
||||
|
||||
std::cout << "user_defined_namespace::user_defined_class::user_defined_field: "
|
||||
<< get_name<0, user_defined_namespace::user_defined_class>() << '\n';
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user