In this post, we will see how to resolve std::unexpected constructor constraint
Question:
I am reading the cpp 23 standard and I stumbled uponstd::unexpected
.Section expected.un.cons defines
Best Answer:
unexpected
is the injected-class-name in the scope of the class template. It refers to the current specialization of the template. It does not refer to the template itself as the same name would outside the class scope.For example if you write
X<T>::x
is of type X<T>
. You don’t have to repeat the template argument list in the declaration of x
. If none is given, then it resolves to the injected-class-name which refers to the current specialization of the template with the same template argument list.The constraint is there so that the constructor can’t be chosen over the copy constructor in overload resolution, which may otherwise happen for non-
const
lvalue arguments.If you have better answer, please add a comment about this, thank you!
Source: Stackoverflow.com
Leave a Review