0

I'm trying to use class template argument deduction while having non-deducible argument, kinda expected that it would work automatically/implicitly, but it doesn't, seems so simple but i just can't make it to work, deduction guides are new to me.

template<typename T>
class Basic {
public:
    T& _obj;
    Basic(T& obj) : _obj(obj){}
};

template<size_t nond, typename T>
class Example {
public:
    static const size_t _nond = nond;
    T& _obj;
    Example(T& obj) : _obj(obj){}
};

int var = 1;
auto basic = Basic(var); // works
auto example = Example<1>(var); // do not work, Error: "Too few template arguments for class template"

Tried deduction guide something like:

template<size_t nond, typename T>
Example(T) -> Example<nond, T>;

But don't even see how that should help, tried few variations without luck. Error: "Deduction guide template contains a template parameter that cannot be deduced" - does that mean i cannot use non-deducible arguments together with deduction ?

Kazz
  • 1,030
  • 8
  • 16
  • @tkausl I dont expect `nond` to be deduced, i'm providing that argument `Example<1>(var)` i only need the type to be deduced – Kazz Apr 24 '22 at 04:13
  • @RaymondChen It does, hoped that it could be solved differently then using template specialization or make_ function but it works with these. thank you – Kazz Apr 24 '22 at 04:54

0 Answers0