Question Details

No question body available.

Tags

c++ language-lawyer

Answers (1)

April 30, 2025 Score: 8 Rep: 47,279 Quality: High Completeness: 80%

My question is this: Is this just a defect of the standard, or is there a fundamental reason why projections returning values of non-movable types should not be supported?

This could arguably be seen as a standard defect, as currently indirectlyregularunaryinvocable is spelled as:

template
  concept indirectlyregularunaryinvocable =
    indirectlyreadable &&
    copyconstructible &&
    regularinvocable &&
    regularinvocable &&
    commonreferencewith<
      invokeresultt,
      invokeresultt>;

However, based on facts that most algorithms are constrained by those indirectlyunarymeow concept such as ranges::foreach do not actually need to construct the valuetype , which suggests that requirements regarding indirect-value-t seem to be overly stringent.

Another related example is:

std::vector v; 

// the following not working, constraints not satisfied std::ranges::foreach( v | std::views::asrvalue, [](std::string&& s) { } );

The above is ill-formed because ranges::foreach requires indirectlyunaryinvocable which requires invocable, which means the lambda must be able to take string&, but... there is no need to make a string in the algorithm, so why do we need lambda support for this in the first place?

I believe this requirement may be inherited from binary counterparts indirectbinarymeow (e.g. indirectequivalencerelation, indirectstrictweakorder...) since algorithms they constrain such as ranges::uniquecopy do need construct valuetype temporarily for comparison, and the corresponding common_reference part makes it possible to define the signature of the comparator more generally as bool operator