TLDR: I have two templatized classes Outer
and Inner
. Inner
can be implicitly constructed from X
Your first example requires two user defined conversions to compile — SomeType -> Inner -> Outer
. However, at most one user defined conversion can be applied implicitly.
Quoting N3337, §12.3 [class.conv]
1 Type conversions of class objects can be specified by constructors and by conversion functions. These conversions are called user-defined conversions and are used for implicit type conversions (Clause 4), for initialization (8.5), and for explicit type conversions (5.4, 5.2.9).
4 At most one user-defined conversion (constructor or conversion function) is implicitly applied to a single value.
If the goal is to avoid having to mention Inner<SomeType>
in the return statement, you can use list initialization.
Outer<Inner<SomeType>> DoSomethingWorks2() {
SomeType value;
return {std::move(value)};
}