Where Online Learning is simpler!
The C and C++ Include Header Files
cat -n /usr/include/wabt/string-util.h
1 /* 2 * Copyright 2017 WebAssembly Community Group participants 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 #ifndef WABT_STRING_UTIL_H_ 18 #define WABT_STRING_UTIL_H_ 19 20 #include <string> 21 #include <string_view> 22 23 namespace wabt { 24 25 inline std::string& operator+=(std::string& x, std::string_view y) { 26 x.append(y.data(), y.size()); 27 return x; 28 } 29 30 inline std::string operator+(std::string_view x, std::string_view y) { 31 std::string s; 32 s.reserve(x.size() + y.size()); 33 s.append(x.data(), x.size()); 34 s.append(y.data(), y.size()); 35 return s; 36 } 37 38 inline std::string operator+(const std::string& x, std::string_view y) { 39 return std::string_view(x) + y; 40 } 41 42 inline std::string operator+(std::string_view x, const std::string& y) { 43 return x + std::string_view(y); 44 } 45 46 inline std::string operator+(const char* x, std::string_view y) { 47 return std::string_view(x) + y; 48 } 49 50 inline std::string operator+(std::string_view x, const char* y) { 51 return x + std::string_view(y); 52 } 53 54 inline void cat_concatenate(std::string&) {} 55 56 template <typename T, typename... Ts> 57 void cat_concatenate(std::string& s, const T& t, const Ts&... args) { 58 s += t; 59 cat_concatenate(s, args...); 60 } 61 62 inline size_t cat_compute_size() { 63 return 0; 64 } 65 66 template <typename T, typename... Ts> 67 size_t cat_compute_size(const T& t, const Ts&... args) { 68 return std::string_view(t).size() + cat_compute_size(args...); 69 } 70 71 // Is able to concatenate any combination of string/string_view/char* 72 template <typename... Ts> 73 std::string cat(const Ts&... args) { 74 std::string s; 75 s.reserve(cat_compute_size(args...)); 76 cat_concatenate(s, args...); 77 return s; 78 } 79 80 } // namespace wabt 81 82 #endif // WABT_STRING_UTIL_H_