• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <iostream>
18 
19 // Generates constexpr code for intrinsic_utils.h
20 //
21 // To dump the constexpr code to stdout:
22 //
23 // $ clang++ -std=c++2a generate_constexpr_constructible.cpp
24 // $ ./a.out
25 //
26 
27 using namespace std;
28 
main()29 int main() {
30   const std::string indent("    ");
31   constexpr size_t kElements = 32;
32   // vapply
33   for (size_t i = kElements; i >= 1; --i) {
34     cout << indent << indent;
35     if (i != kElements) cout << "} else ";
36     cout << "if constexpr (is_braces_constructible<VT,\n";
37     for (size_t j = 0; j < i; ) {
38       cout << indent << indent << indent << indent;
39       for (size_t k = 0; k < 8 && j < i; ++k, ++j) {
40         if (k > 0) cout << " ";
41         cout << "any_type";
42         if (j < i - 1) {
43           cout << ",";
44         } else {
45           if (k == 7) {
46             cout << "\n" << indent << indent << indent << indent;
47           }
48           cout << ">()) {";
49         }
50       }
51       cout << "\n";
52     }
53     for (size_t j = 0; j < i; ) {
54       cout << indent << indent << indent;
55       if (j == 0) {
56         cout << "auto& [";
57       } else {
58         cout << indent << indent;
59       }
60       for (size_t k = 0; k < 8 && j < i; ++k, ++j) {
61         if (k > 0) cout << " ";
62         cout << "v" << (j + 1) <<  (j < i - 1 ? "," : "] = vv;");
63       }
64       cout << "\n";
65     }
66 
67     for (size_t j = 0; j < i; ++j) {
68       cout << indent << indent << indent;
69       cout << "vapply(f, v" << (j + 1) << ");\n";
70     }
71   }
72   cout << indent << indent;
73   cout << "} else {\n";
74   cout << indent << indent << indent;
75   cout << "static_assert(false, \"Currently supports up to "
76       << kElements << " members only.\");\n";
77   cout << indent << indent;
78   cout << "}\n";
79   return 0;
80 }
81