The issues are with functions that have to return several values. In this
case using non-const refs or non-const pointers are required. You could
argue that's bad design, I would argue the opposite way and say that it's
probably the best design we have for stuff like error handling (return an
error code by value + the value itself in a non-const pointer).


On Sun, May 25, 2014 at 9:31 PM, galop1n <notifications@github.com> wrote:

> In Contributing.md:
>
> > +    inline void Clamp(T& val, const T& min, const T& max)
> > +    {
> > +        if (val < min)
> > +            val = min;
> > +        else if (val > max)
> > +            val = max;
> > +    }
> > +    ```
> > +
> > +    Example call: `Clamp(var, 1000, 5000);`
> > +
> > +  - What to do:
> > +
> > +    ```c++
> > +    template<class T>
> > +    inline void Clamp(T* val, const T& min, const T& max)
>
> The attribute do not catch runtime cases.
>
> Copy elision is well mastered now and most of the "fill or modify a value
> for me" should be a return by value or an object constructor. The rare
> functions that are still capable of be better than return by value are
> those like std::getline as it allow to remove an allocation at each call (
> and that one still have good solution now if you dare ).
>
> To me, a rule against non const reference do not have to ask for non const
> pointer instead but ask for a better code design…
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/dolphin-emu/dolphin/pull/410/files#r13032423>
> .
>



-- 
Pierre "delroth" Bourdon <delroth@gmail.com>
Software Engineer @ Zürich, Switzerland
http://code.delroth.net/