How to get alternative value from function that gives wanted data via non-const output parameter for assigning reference-to-const variable to it?
问题 The commented code works, but it is not a reference, so it has more computational cost. void CClass::Function(const CArray<CItem*>* ItemsInput) const { /* CArray<CItem*> Items; if (ItemsInput != nullptr) Items.Copy(*ItemsInput); else GetContainer().GetInnerItems(Items, NULL, true); */ const CArray<CItem*>& Items= (ItemsInput!= nullptr)? *ItemsInput : [this] () -> const CArray<CItem*> { CArray<CItem*> InnerItems; GetContainer().GetInnerItems(InnerItems, NULL, true); return const_cast <const