]>
Commit | Line | Data |
---|---|---|
20effc67 TL |
1 | #!/usr/bin/python |
2 | ||
1e59de90 | 3 | # Copyright (c) 2016-2022 Antony Polukhin |
20effc67 TL |
4 | # |
5 | # Distributed under the Boost Software License, Version 1.0. (See accompanying | |
6 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
7 | ||
8 | ############################################################################################################################ | |
9 | ||
10 | import sys | |
11 | import string | |
12 | ||
13 | # Skipping some letters that may produce keywords or are hard to read, or shadow template parameters | |
14 | ascii_letters = string.ascii_letters.replace("o", "").replace("O", "").replace("i", "").replace("I", "").replace("T", "") | |
15 | ||
16 | PROLOGUE = """// Copyright (c) 2016-2020 Antony Polukhin | |
17 | // | |
18 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |
19 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
20 | ||
21 | ||
22 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
23 | //////////////// THIS HEADER IS AUTO GENERATED BY misc/generate_cpp17.py //////////////// | |
24 | //////////////// MODIFY AND RUN THE misc/generate_cpp17.py INSTEAD OF DIRECTLY MODIFYING THE GENERATED FILE //////////////// | |
25 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
26 | ||
27 | #ifndef BOOST_PFR_DETAIL_CORE17_GENERATED_HPP | |
28 | #define BOOST_PFR_DETAIL_CORE17_GENERATED_HPP | |
29 | #pragma once | |
30 | ||
31 | #include <boost/pfr/detail/config.hpp> | |
32 | #if !BOOST_PFR_USE_CPP17 | |
33 | # error C++17 is required for this header. | |
34 | #endif | |
35 | ||
36 | #include <boost/pfr/detail/sequence_tuple.hpp> | |
37 | #include <boost/pfr/detail/size_t_.hpp> | |
38 | ||
39 | namespace boost { namespace pfr { namespace detail { | |
40 | ||
41 | template <class... Args> | |
42 | constexpr auto make_tuple_of_references(Args&&... args) noexcept { | |
43 | return sequence_tuple::tuple<Args&...>{ args... }; | |
44 | } | |
45 | ||
46 | template <class T> | |
47 | constexpr auto tie_as_tuple(T& /*val*/, size_t_<0>) noexcept { | |
48 | return sequence_tuple::tuple<>{}; | |
49 | } | |
50 | ||
51 | template <class T> | |
52 | constexpr auto tie_as_tuple(T& val, size_t_<1>, std::enable_if_t<std::is_class< std::remove_cv_t<T> >::value>* = 0) noexcept { | |
53 | auto& [a] = val; // ====================> Boost.PFR: User-provided type is not a SimpleAggregate. | |
54 | return ::boost::pfr::detail::make_tuple_of_references(a); | |
55 | } | |
56 | ||
57 | ||
58 | template <class T> | |
59 | constexpr auto tie_as_tuple(T& val, size_t_<1>, std::enable_if_t<!std::is_class< std::remove_cv_t<T> >::value>* = 0) noexcept { | |
60 | return ::boost::pfr::detail::make_tuple_of_references( val ); | |
61 | } | |
62 | ||
63 | """ | |
64 | ||
65 | ############################################################################################################################ | |
66 | EPILOGUE = """ | |
67 | template <class T, std::size_t I> | |
68 | constexpr void tie_as_tuple(T& /*val*/, size_t_<I>) noexcept { | |
69 | static_assert(sizeof(T) && false, | |
70 | "====================> Boost.PFR: Too many fields in a structure T. Regenerate include/boost/pfr/detail/core17_generated.hpp file for appropriate count of fields. For example: `python ./misc/generate_cpp17.py 300 > include/boost/pfr/detail/core17_generated.hpp`"); | |
71 | } | |
72 | ||
73 | }}} // namespace boost::pfr::detail | |
74 | ||
75 | #endif // BOOST_PFR_DETAIL_CORE17_GENERATED_HPP | |
76 | """ | |
77 | ||
78 | ############################################################################################################################ | |
79 | ||
80 | ||
81 | indexes = " a" | |
82 | print(PROLOGUE) | |
83 | funcs_count = 100 if len(sys.argv) == 1 else int(sys.argv[1]) | |
84 | max_args_on_a_line = len(ascii_letters) | |
85 | for i in range(1, funcs_count): | |
86 | if i % max_args_on_a_line == 0: | |
87 | indexes += ",\n " | |
88 | else: | |
89 | indexes += "," | |
90 | ||
91 | if i >= max_args_on_a_line: | |
92 | indexes += ascii_letters[i // max_args_on_a_line - 1] | |
93 | indexes += ascii_letters[i % max_args_on_a_line] | |
94 | ||
95 | print("template <class T>") | |
96 | print("constexpr auto tie_as_tuple(T& val, size_t_<" + str(i + 1) + ">) noexcept {") | |
97 | if i < max_args_on_a_line: | |
98 | print(" auto& [" + indexes.strip() + "] = val; // ====================> Boost.PFR: User-provided type is not a SimpleAggregate.") | |
99 | print(" return ::boost::pfr::detail::make_tuple_of_references(" + indexes.strip() + ");") | |
100 | else: | |
101 | print(" auto& [") | |
102 | print(indexes) | |
103 | print(" ] = val; // ====================> Boost.PFR: User-provided type is not a SimpleAggregate.") | |
104 | print("") | |
105 | print(" return ::boost::pfr::detail::make_tuple_of_references(") | |
106 | print(indexes) | |
107 | print(" );") | |
108 | ||
109 | print("}\n") | |
110 | ||
111 | print(EPILOGUE) |