diff options
author | robot-contrib <robot-contrib@yandex-team.com> | 2023-12-09 02:21:42 +0300 |
---|---|---|
committer | robot-contrib <robot-contrib@yandex-team.com> | 2023-12-09 02:46:25 +0300 |
commit | d28ef937b78102c2d1d8a8eb0ee782cf0bee5b68 (patch) | |
tree | 0ff7790c3ebf3406208bac3b917a163176944e16 | |
parent | c1d40b98e1b0bfa1c6e838bc5d7d7e4f1820dede (diff) | |
download | ydb-d28ef937b78102c2d1d8a8eb0ee782cf0bee5b68.tar.gz |
Update contrib/libs/pfr to 2.2.0
-rw-r--r-- | contrib/libs/pfr/README.md | 58 | ||||
-rw-r--r-- | contrib/libs/pfr/include/pfr/config.hpp | 148 | ||||
-rw-r--r-- | contrib/libs/pfr/include/pfr/detail/config.hpp | 91 | ||||
-rw-r--r-- | contrib/libs/pfr/include/pfr/detail/fields_count.hpp | 2 | ||||
-rw-r--r-- | contrib/libs/pfr/include/pfr/detail/make_integer_sequence.hpp | 2 | ||||
-rw-r--r-- | contrib/libs/pfr/include/pfr/detail/sequence_tuple.hpp | 53 | ||||
-rw-r--r-- | contrib/libs/pfr/include/pfr/detail/size_t_.hpp | 2 | ||||
-rw-r--r-- | contrib/libs/pfr/include/pfr/detail/unsafe_declval.hpp | 5 | ||||
-rw-r--r-- | contrib/libs/pfr/include/pfr/tuple_size.hpp | 6 | ||||
-rw-r--r-- | contrib/libs/pfr/ya.make | 6 |
10 files changed, 281 insertions, 92 deletions
diff --git a/contrib/libs/pfr/README.md b/contrib/libs/pfr/README.md index 0a83f4b983..b51baed036 100644 --- a/contrib/libs/pfr/README.md +++ b/contrib/libs/pfr/README.md @@ -45,11 +45,13 @@ Outputs: Edgar Allan Poe was born in 1809 ``` +[Run the above sample](https://godbolt.org/z/PfYsWKb7v) + ### Motivating Example #1 ```c++ #include <iostream> -#include "pfr/precise.hpp" +#include "pfr.hpp" struct my_struct { // no ostream operator defined! int i; @@ -74,7 +76,7 @@ my_struct has 3 fields: {100, H, 3.14159} ```c++ #include <iostream> -#include "pfr/precise.hpp" +#include "pfr.hpp" struct my_struct { // no ostream operator defined! std::string s; @@ -94,6 +96,58 @@ Outputs: my_struct has 2 fields: {"Das ist fantastisch!", 100} ``` +### Motivating Example #3 + +```c++ +#include <iostream> +#include <string> + +#include <boost/config/warning_disable.hpp> +#include <boost/spirit/home/x3.hpp> +#include <boost/fusion/include/adapt_boost_pfr.hpp> + +#include "pfr/io.hpp" + +namespace x3 = boost::spirit::x3; + +struct ast_employee { // No BOOST_FUSION_ADAPT_STRUCT defined + int age; + std::string forename; + std::string surname; + double salary; +}; + +auto const quoted_string = x3::lexeme['"' >> +(x3::ascii::char_ - '"') >> '"']; + +x3::rule<class employee, ast_employee> const employee = "employee"; +auto const employee_def = + x3::lit("employee") + >> '{' + >> x3::int_ >> ',' + >> quoted_string >> ',' + >> quoted_string >> ',' + >> x3::double_ + >> '}' + ; +BOOST_SPIRIT_DEFINE(employee); + +int main() { + std::string str = R"(employee{34, "Chip", "Douglas", 2500.00})"; + ast_employee emp; + x3::phrase_parse(str.begin(), + str.end(), + employee, + x3::ascii::space, + emp); + std::cout << pfr::io(emp) << std::endl; +} + +``` +Outputs: +``` +(34 Chip Douglas 2500) +``` + ### Requirements and Limitations diff --git a/contrib/libs/pfr/include/pfr/config.hpp b/contrib/libs/pfr/include/pfr/config.hpp new file mode 100644 index 0000000000..d8441a6f19 --- /dev/null +++ b/contrib/libs/pfr/include/pfr/config.hpp @@ -0,0 +1,148 @@ +// Copyright (c) 2016-2023 Antony Polukhin +// Copyright (c) 2022 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) + +#ifndef PFR_CONFIG_HPP +#define PFR_CONFIG_HPP +#pragma once + +#if __cplusplus >= 201402L || (defined(_MSC_VER) && defined(_MSVC_LANG) && _MSC_VER > 1900) +#include <type_traits> // to get non standard platform macro definitions (__GLIBCXX__ for example) +#endif + +/// \file pfr/config.hpp +/// Contains all the macros that describe Boost.PFR configuration, like PFR_ENABLED +/// +/// \note This header file doesn't require C++14 Standard and supports all C++ compilers, even pre C++14 compilers (C++11, C++03...). + +// Reminder: +// * MSVC++ 14.2 _MSC_VER == 1927 <- Loophole is known to work (Visual Studio ????) +// * MSVC++ 14.1 _MSC_VER == 1916 <- Loophole is known to NOT work (Visual Studio 2017) +// * MSVC++ 14.0 _MSC_VER == 1900 (Visual Studio 2015) +// * MSVC++ 12.0 _MSC_VER == 1800 (Visual Studio 2013) + +#ifdef PFR_NOT_SUPPORTED +# error Please, do not set PFR_NOT_SUPPORTED value manually, use '-DPFR_ENABLED=0' instead of it +#endif + +#if defined(_MSC_VER) +# if !defined(_MSVC_LANG) || _MSC_VER <= 1900 +# define PFR_NOT_SUPPORTED 1 +# endif +#elif __cplusplus < 201402L +# define PFR_NOT_SUPPORTED 1 +#endif + +#ifndef PFR_USE_LOOPHOLE +# if defined(_MSC_VER) +# if _MSC_VER >= 1927 +# define PFR_USE_LOOPHOLE 1 +# else +# define PFR_USE_LOOPHOLE 0 +# endif +# elif defined(__clang_major__) && __clang_major__ >= 8 +# define PFR_USE_LOOPHOLE 0 +# else +# define PFR_USE_LOOPHOLE 1 +# endif +#endif + +#ifndef PFR_USE_CPP17 +# ifdef __cpp_structured_bindings +# define PFR_USE_CPP17 1 +# elif defined(_MSVC_LANG) +# if _MSVC_LANG >= 201703L +# define PFR_USE_CPP17 1 +# else +# define PFR_USE_CPP17 0 +# endif +# else +# define PFR_USE_CPP17 0 +# endif +#endif + +#if (!PFR_USE_CPP17 && !PFR_USE_LOOPHOLE) +# if (defined(_MSC_VER) && _MSC_VER < 1916) ///< in Visual Studio 2017 v15.9 PFR library with classic engine normally works +# define PFR_NOT_SUPPORTED 1 +# endif +#endif + +#ifndef PFR_USE_STD_MAKE_INTEGRAL_SEQUENCE +// Assume that libstdc++ since GCC-7.3 does not have linear instantiation depth in std::make_integral_sequence +# if defined( __GLIBCXX__) && __GLIBCXX__ >= 20180101 +# define PFR_USE_STD_MAKE_INTEGRAL_SEQUENCE 1 +# elif defined(_MSC_VER) +# define PFR_USE_STD_MAKE_INTEGRAL_SEQUENCE 1 +//# elif other known working lib +# else +# define PFR_USE_STD_MAKE_INTEGRAL_SEQUENCE 0 +# endif +#endif + +#ifndef PFR_HAS_GUARANTEED_COPY_ELISION +# if defined(__cpp_guaranteed_copy_elision) && (!defined(_MSC_VER) || _MSC_VER > 1928) +# define PFR_HAS_GUARANTEED_COPY_ELISION 1 +# else +# define PFR_HAS_GUARANTEED_COPY_ELISION 0 +# endif +#endif + +#ifndef PFR_ENABLE_IMPLICIT_REFLECTION +# if defined(__cpp_lib_is_aggregate) +# define PFR_ENABLE_IMPLICIT_REFLECTION 1 +# else +// There is no way to detect potential ability to be reflectable without std::is_aggregare +# define PFR_ENABLE_IMPLICIT_REFLECTION 0 +# endif +#endif + +#ifndef PFR_CORE_NAME_ENABLED +# if (__cplusplus >= 202002L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 202002L)) +# if (defined(__cpp_nontype_template_args) && __cpp_nontype_template_args >= 201911) \ + || (defined(__clang_major__) && __clang_major__ >= 12) +# define PFR_CORE_NAME_ENABLED 1 +# else +# define PFR_CORE_NAME_ENABLED 0 +# endif +# else +# define PFR_CORE_NAME_ENABLED 0 +# endif +#endif + + +#ifndef PFR_CORE_NAME_PARSING +# if defined(_MSC_VER) +# define PFR_CORE_NAME_PARSING (sizeof("auto __cdecl pfr::detail::name_of_field_impl<") - 1, sizeof(">(void) noexcept") - 1, backward("->")) +# elif defined(__clang__) +# define PFR_CORE_NAME_PARSING (sizeof("auto pfr::detail::name_of_field_impl() [MsvcWorkaround = ") - 1, sizeof("}]") - 1, backward(".")) +# elif defined(__GNUC__) +# define PFR_CORE_NAME_PARSING (sizeof("consteval auto pfr::detail::name_of_field_impl() [with MsvcWorkaround = ") - 1, sizeof(")]") - 1, backward("::")) +# else +// Default parser for other platforms... Just skip nothing! +# define PFR_CORE_NAME_PARSING (0, 0, "") +# endif +#endif + +#if defined(__has_cpp_attribute) +# if __has_cpp_attribute(maybe_unused) +# define PFR_MAYBE_UNUSED [[maybe_unused]] +# endif +#endif + +#ifndef PFR_MAYBE_UNUSED +# define PFR_MAYBE_UNUSED +#endif + +#ifndef PFR_ENABLED +# ifdef PFR_NOT_SUPPORTED +# define PFR_ENABLED 0 +# else +# define PFR_ENABLED 1 +# endif +#endif + +#undef PFR_NOT_SUPPORTED + +#endif // PFR_CONFIG_HPP diff --git a/contrib/libs/pfr/include/pfr/detail/config.hpp b/contrib/libs/pfr/include/pfr/detail/config.hpp index ec2143d9ba..9a0b10b4ef 100644 --- a/contrib/libs/pfr/include/pfr/detail/config.hpp +++ b/contrib/libs/pfr/include/pfr/detail/config.hpp @@ -1,4 +1,5 @@ -// Copyright (c) 2016-2021 Antony Polukhin +// Copyright (c) 2016-2023 Antony Polukhin +// Copyright (c) 2022 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) @@ -7,85 +8,19 @@ #define PFR_DETAIL_CONFIG_HPP #pragma once -#include <type_traits> // to get non standard platform macro definitions (__GLIBCXX__ for example) +#include <pfr/config.hpp> -// Reminder: -// * MSVC++ 14.2 _MSC_VER == 1927 <- Loophole is known to work (Visual Studio ????) -// * MSVC++ 14.1 _MSC_VER == 1916 <- Loophole is known to NOT work (Visual Studio 2017) -// * MSVC++ 14.0 _MSC_VER == 1900 (Visual Studio 2015) -// * MSVC++ 12.0 _MSC_VER == 1800 (Visual Studio 2013) +#if !PFR_ENABLED -#if defined(_MSC_VER) -# if !defined(_MSVC_LANG) || _MSC_VER <= 1900 -# error Boost.PFR library requires more modern MSVC compiler. -# endif -#elif __cplusplus < 201402L -# error Boost.PFR library requires at least C++14. -#endif - -#ifndef PFR_USE_LOOPHOLE -# if defined(_MSC_VER) -# if _MSC_VER >= 1927 -# define PFR_USE_LOOPHOLE 1 -# else -# define PFR_USE_LOOPHOLE 0 -# endif -# elif defined(__clang_major__) && __clang_major__ >= 8 -# define PFR_USE_LOOPHOLE 0 -# else -# define PFR_USE_LOOPHOLE 1 -# endif -#endif - -#ifndef PFR_USE_CPP17 -# ifdef __cpp_structured_bindings -# define PFR_USE_CPP17 1 -# elif defined(_MSVC_LANG) -# if _MSVC_LANG >= 201703L -# define PFR_USE_CPP17 1 -# else -# define PFR_USE_CPP17 0 -# endif -# else -# define PFR_USE_CPP17 0 -# endif -#endif - -#if (!PFR_USE_CPP17 && !PFR_USE_LOOPHOLE) -# if (defined(_MSC_VER) && _MSC_VER < 1916) ///< in Visual Studio 2017 v15.9 PFR library with classic engine normally works -# error Boost.PFR requires /std:c++latest or /std:c++17 flags on your compiler. -# endif -#endif - -#ifndef PFR_USE_STD_MAKE_INTEGRAL_SEQUENCE -// Assume that libstdc++ since GCC-7.3 does not have linear instantiation depth in std::make_integral_sequence -# if defined( __GLIBCXX__) && __GLIBCXX__ >= 20180101 -# define PFR_USE_STD_MAKE_INTEGRAL_SEQUENCE 1 -# elif defined(_MSC_VER) -# define PFR_USE_STD_MAKE_INTEGRAL_SEQUENCE 1 -//# elif other known working lib -# else -# define PFR_USE_STD_MAKE_INTEGRAL_SEQUENCE 0 -# endif -#endif - -#ifndef PFR_HAS_GUARANTEED_COPY_ELISION -# if defined(__cpp_guaranteed_copy_elision) && (!defined(_MSC_VER) || _MSC_VER > 1928) -# define PFR_HAS_GUARANTEED_COPY_ELISION 1 -# else -# define PFR_HAS_GUARANTEED_COPY_ELISION 0 -# endif -#endif - -#if defined(__has_cpp_attribute) -# if __has_cpp_attribute(maybe_unused) -# define PFR_MAYBE_UNUSED [[maybe_unused]] -# endif -#endif - -#ifndef PFR_MAYBE_UNUSED -# define PFR_MAYBE_UNUSED -#endif +#error Boost.PFR library is not supported in your environment. \ + Try one of the possible solutions: \ + 1. try to take away an '-DPFR_ENABLED=0', if it exists \ + 2. enable C++14; \ + 3. enable C++17; \ + 4. update your compiler; \ + or disable this error by '-DPFR_ENABLED=1' if you really know what are you doing. +#endif // !PFR_ENABLED #endif // PFR_DETAIL_CONFIG_HPP + diff --git a/contrib/libs/pfr/include/pfr/detail/fields_count.hpp b/contrib/libs/pfr/include/pfr/detail/fields_count.hpp index d4ad82353a..666d6ae171 100644 --- a/contrib/libs/pfr/include/pfr/detail/fields_count.hpp +++ b/contrib/libs/pfr/include/pfr/detail/fields_count.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 Antony Polukhin +// Copyright (c) 2016-2023 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) diff --git a/contrib/libs/pfr/include/pfr/detail/make_integer_sequence.hpp b/contrib/libs/pfr/include/pfr/detail/make_integer_sequence.hpp index b1af047d2f..4c6a07c442 100644 --- a/contrib/libs/pfr/include/pfr/detail/make_integer_sequence.hpp +++ b/contrib/libs/pfr/include/pfr/detail/make_integer_sequence.hpp @@ -1,5 +1,5 @@ // Copyright (c) 2018 Sergei Fedorov -// Copyright (c) 2019-2021 Antony Polukhin +// Copyright (c) 2019-2023 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) diff --git a/contrib/libs/pfr/include/pfr/detail/sequence_tuple.hpp b/contrib/libs/pfr/include/pfr/detail/sequence_tuple.hpp index 3ccd130914..50b796151a 100644 --- a/contrib/libs/pfr/include/pfr/detail/sequence_tuple.hpp +++ b/contrib/libs/pfr/include/pfr/detail/sequence_tuple.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 Antony Polukhin +// Copyright (c) 2016-2023 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) @@ -50,30 +50,74 @@ struct tuple_base<std::index_sequence<> > { template <std::size_t N, class T> constexpr T& get_impl(base_from_member<N, T>& t) noexcept { + // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn) return t.value; } template <std::size_t N, class T> constexpr const T& get_impl(const base_from_member<N, T>& t) noexcept { + // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn) return t.value; } template <std::size_t N, class T> constexpr volatile T& get_impl(volatile base_from_member<N, T>& t) noexcept { + // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn) return t.value; } template <std::size_t N, class T> constexpr const volatile T& get_impl(const volatile base_from_member<N, T>& t) noexcept { + // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn) return t.value; } template <std::size_t N, class T> constexpr T&& get_impl(base_from_member<N, T>&& t) noexcept { + // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn) return std::forward<T>(t.value); } +template <class T, std::size_t N> +constexpr T& get_by_type_impl(base_from_member<N, T>& t) noexcept { + // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn) + return t.value; +} + +template <class T, std::size_t N> +constexpr const T& get_by_type_impl(const base_from_member<N, T>& t) noexcept { + // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn) + return t.value; +} + +template <class T, std::size_t N> +constexpr volatile T& get_by_type_impl(volatile base_from_member<N, T>& t) noexcept { + // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn) + return t.value; +} + +template <class T, std::size_t N> +constexpr const volatile T& get_by_type_impl(const volatile base_from_member<N, T>& t) noexcept { + // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn) + return t.value; +} + +template <class T, std::size_t N> +constexpr T&& get_by_type_impl(base_from_member<N, T>&& t) noexcept { + // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn) + return std::forward<T>(t.value); +} + +template <class T, std::size_t N> +constexpr const T&& get_by_type_impl(const base_from_member<N, T>&& t) noexcept { + // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn) + return std::forward<T>(t.value); +} + + + + template <class ...Values> struct tuple: tuple_base< detail::index_sequence_for<Values...>, @@ -83,6 +127,9 @@ struct tuple: tuple_base< detail::index_sequence_for<Values...>, Values... >::tuple_base; + + constexpr static std::size_t size() noexcept { return sizeof...(Values); } + constexpr static bool empty() noexcept { return size() == 0; } }; @@ -121,6 +168,10 @@ using tuple_element = std::remove_reference< decltype( ::pfr::detail::sequence_tuple::get<I>( std::declval<T>() ) ) >; +template <class... Args> +constexpr auto make_sequence_tuple(Args... args) noexcept { + return ::pfr::detail::sequence_tuple::tuple<Args...>{ args... }; +} }}} // namespace pfr::detail::sequence_tuple diff --git a/contrib/libs/pfr/include/pfr/detail/size_t_.hpp b/contrib/libs/pfr/include/pfr/detail/size_t_.hpp index da54096b0e..93896d445e 100644 --- a/contrib/libs/pfr/include/pfr/detail/size_t_.hpp +++ b/contrib/libs/pfr/include/pfr/detail/size_t_.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 Antony Polukhin +// Copyright (c) 2016-2023 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) diff --git a/contrib/libs/pfr/include/pfr/detail/unsafe_declval.hpp b/contrib/libs/pfr/include/pfr/detail/unsafe_declval.hpp index 3742abcd2a..1b1a587be1 100644 --- a/contrib/libs/pfr/include/pfr/detail/unsafe_declval.hpp +++ b/contrib/libs/pfr/include/pfr/detail/unsafe_declval.hpp @@ -1,10 +1,11 @@ -// Copyright (c) 2019-2021 Antony Polukhin. +// Copyright (c) 2019-2023 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) #ifndef PFR_DETAIL_UNSAFE_DECLVAL_HPP #define PFR_DETAIL_UNSAFE_DECLVAL_HPP +#pragma once #include <pfr/detail/config.hpp> @@ -24,7 +25,7 @@ template <class T> constexpr T unsafe_declval() noexcept { report_if_you_see_link_error_with_this_function(); - typename std::remove_reference<T>::type* ptr = 0; + typename std::remove_reference<T>::type* ptr = nullptr; ptr += 42; // suppresses 'null pointer dereference' warnings return static_cast<T>(*ptr); } diff --git a/contrib/libs/pfr/include/pfr/tuple_size.hpp b/contrib/libs/pfr/include/pfr/tuple_size.hpp index 7ad8f08993..fe7b8e44dd 100644 --- a/contrib/libs/pfr/include/pfr/tuple_size.hpp +++ b/contrib/libs/pfr/include/pfr/tuple_size.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 Antony Polukhin +// Copyright (c) 2016-2023 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) @@ -23,7 +23,7 @@ namespace pfr { /// Has a static const member variable `value` that contains fields count in a T. -/// Works for any T that supports aggregate initialization. +/// Works for any T that satisfies \aggregate. /// /// \b Example: /// \code @@ -34,7 +34,7 @@ using tuple_size = detail::size_t_< pfr::detail::fields_count<T>() >; /// `tuple_size_v` is a template variable that contains fields count in a T and -/// works for any T that supports aggregate initialization. +/// works for any T that satisfies \aggregate. /// /// \b Example: /// \code diff --git a/contrib/libs/pfr/ya.make b/contrib/libs/pfr/ya.make index cdf2bfde6c..39fc5830db 100644 --- a/contrib/libs/pfr/ya.make +++ b/contrib/libs/pfr/ya.make @@ -1,4 +1,4 @@ -# Generated by devtools/yamaker from nixpkgs 22.05. +# Generated by devtools/yamaker from nixpkgs 22.11. LIBRARY() @@ -9,9 +9,9 @@ LICENSE( LICENSE_TEXTS(.yandex_meta/licenses.list.txt) -VERSION(2.0.3) +VERSION(2.2.0) -ORIGINAL_SOURCE(https://github.com/apolukhin/pfr_non_boost/archive/2.0.3.tar.gz) +ORIGINAL_SOURCE(https://github.com/apolukhin/pfr_non_boost/archive/2.2.0.tar.gz) ADDINCL( GLOBAL contrib/libs/pfr/include |