Код: Выделить всё
namespace sft
{
template
auto safe_cast(From from) -> To
{
// assert cast
return static_cast(from);
}
} // namespace sft
< /code>
Теперь я хочу донести эту функцию шаблона в локальное пространство имен (в этом примере для глобального пространства имен). Я пытаюсь сделать это с помощью указателя по шаблонной функции. < /P>
template
constexpr To (*safe_cast)(From) = &sft::safe_cast;
auto main() -> int
{
return safe_cast(-300);
}
< /code>
I have a problem with template deduction using GCC 14.2
: In function 'int main()':
:16:26: error: wrong number of template arguments (1, should be 2)
16 | return safe_cast(-300);
| ^
:12:16: note: provided for 'template constexpr To (* const safe_cast)(From)'
12 | constexpr To (*safe_cast)(From) = &sft::safe_cast;
< /code>
How can it be done or is there any other way how to bring function template to local namespace without using namespace prefix?
see Godbolt
Подробнее здесь: https://stackoverflow.com/questions/795 ... f-namespac