Я пытаюсь понять код шаблона.
Я сократил код до самого необходимого. Но я не понимаю значения параметра шаблона, предоставленного функции mangledName().
#include
struct MYS
{
int data = 345;
};
namespace TA
{
extern MYS externalX;
struct ptr_tX final
{
const int& ptr;
};
constexpr auto get_ptrX(MYS& t) noexcept
{
auto& p0 = t.data;
return ptr_tX{p0};
}
template
std::string_view mangledName()
{
return "Stuff";
}
}
int main()
{
// Here we are calling `mangledName()`
// But the call `get_ptrX()` is done to get the template parameter
// So I "think" this is done at compile time.
// But I don't understand what is being given as the parameter.
// Is it the type of the result?
// Is it the type of the function?
// Neither seem to be true and I don't understand what is going on.
// I can't seem to manually validate it. The `` is totally confusing me.
std::string_view key = TA::mangledName();
}
Для некоторого контекста: этот код в полной форме используется для создания имен полей как string_view во время компиляции (в данном случае данных в MYS). . Но я удалил эту часть, поскольку она не является частью того, что я пытаюсь понять. Это используется для создания анализатора JSON.
Я пытаюсь понять код шаблона. Я сократил код до самого необходимого. Но я не понимаю значения параметра шаблона, предоставленного функции mangledName(). [code] #include
int main() { // Here we are calling `mangledName()` // But the call `get_ptrX()` is done to get the template parameter // So I "think" this is done at compile time. // But I don't understand what is being given as the parameter. // Is it the type of the result? // Is it the type of the function? // Neither seem to be true and I don't understand what is going on. // I can't seem to manually validate it. The `` is totally confusing me. std::string_view key = TA::mangledName(); } [/code] Для некоторого контекста: этот код в полной форме используется для создания имен полей как string_view во время компиляции (в данном случае данных в MYS). . Но я удалил эту часть, поскольку она не является частью того, что я пытаюсь понять. Это используется для создания анализатора JSON.