1 #pragma once 2 // @lint-ignore-every CLANGTIDY facebook-hte-LocalUncheckedArrayBounds 3 #ifdef USE_VULKAN_API 4 5 #include <exception> 6 #include <ostream> 7 #include <sstream> 8 #include <string> 9 #include <vector> 10 11 namespace at { 12 namespace native { 13 namespace vulkan { 14 namespace api { 15 16 namespace detail { 17 18 struct CompileTimeEmptyString { 19 operator const std::string&() const { 20 static const std::string empty_string_literal; 21 return empty_string_literal; 22 } 23 operator const char*() const { 24 return ""; 25 } 26 }; 27 28 template <typename T> 29 struct CanonicalizeStrTypes { 30 using type = const T&; 31 }; 32 33 template <size_t N> 34 struct CanonicalizeStrTypes<char[N]> { 35 using type = const char*; 36 }; 37 38 inline std::ostream& _str(std::ostream& ss) { 39 return ss; 40 } 41 42 template <typename T> 43 inline std::ostream& _str(std::ostream& ss, const T& t) { 44 ss << t; 45 return ss; 46 } 47 48 template <> 49 inline std::ostream& _str<CompileTimeEmptyString>( 50 std::ostream& ss, 51 const CompileTimeEmptyString&) { 52 return ss; 53 } 54 55 template <typename T, typename... Args> 56 inline std::ostream& _str(std::ostream& ss, const T& t, const Args&... args) { 57 return _str(_str(ss, t), args...); 58 } 59 60 template <typename... Args> 61 struct _str_wrapper final { 62 static std::string call(const Args&... args) { 63 std::ostringstream ss; 64 _str(ss, args...); 65 return ss.str(); 66 } 67 }; 68 69 template <> 70 struct _str_wrapper<> final { 71 static CompileTimeEmptyString call() { 72 return CompileTimeEmptyString(); 73 } 74 }; 75 76 } // namespace detail 77 78 template <typename... Args> 79 inline std::string concat_str(const Args&... args) { 80 return detail::_str_wrapper< 81 typename detail::CanonicalizeStrTypes<Args>::type...>::call(args...); 82 } 83 84 } // namespace api 85 } // namespace vulkan 86 } // namespace native 87 } // namespace at 88 89 #endif /* USE_VULKAN_API */ 90