This snippet demonstrates how to use deduction guides to allow source_location::current
together with parameter packs (see https://stackoverflow.com/a/57548488/1421332):
template <typename... Params>
struct Test
{
Test(Params&&... params,
const std::source_location& loc = std::source_location::current());
};
template <typename ...Params>
Test(Params&&...) -> Test<Params...>;
Which is used like this:
Test(5, 'A', 3.14f, "foo");
Now I want to extend the struct Test by an additional Type T that shall be specified explicitly. I tried the following but the deduction guide is not accepted:
template <typename T, typename... Params>
struct Test
{
Test(Params&&... params,
const std::source_location& loc = std::source_location::current());
};
template <typename T, typename ...Params>
Test(Params&&...) -> Test<T, Params...>;
Compiler says:
deduction guide template contains a template parameter that cannot be deduced.
I need the additional T to allow struct Test
to internally build an object of a user specified type.
It should be used like this:
Test<MyType>(5, 'A', 3.14f, "foo");
Is it possible to define a deduction guide including the additional T?