does `const auto` have any meaning?

前端 未结 4 552
无人及你
无人及你 2020-12-23 16:06

I think the question is clear enough. Will the auto keyword auto-detect const-ness, or always return a non-const type, even if there are eg. two versions of a f

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-23 16:28

    const auto x = expr;
    

    differs from

    auto x = expr;
    

    as

    const X x = expr;
    

    differs from

    X x = expr;
    

    So use const auto and const auto& a lot, just like you would if you didn't have auto.

    Overload resolution is not affected by return type: const or no const on the lvalue x does not affect what functions are called in expr.

提交回复
热议问题