Can not overload template method function with const. Bug?

kenji hara k.hara.pg at gmail.com
Wed Aug 8 08:00:49 PDT 2012


In the declaration of std.typecons.Tuple:

    bool opEquals(R)(R rhs) if (isTuple!R)
    {
        // [snip]
    }

    bool opEquals(R)(R rhs) const if (isTuple!R)
    {
        // same as non-const version
    }

Adding const version works correctly.
What's the problem?

Kenji Hara

2012/8/8 Tobias Pankrath <tobias at pankrath.net>:
> You currently can't use Tuples with std.container.Array (Bug #8284)
>
> To fix this, I tried to overload the opEquals(R)(R rhs) of Tuple with
> a const version opEquals(R)(R rhs) const. But the compiler does not use the
> overload if opEquals is called on a const tuple instance.
>
> See this thread in d.learn
> http://forum.dlang.org/thread/vghlctzlpqxhoeojqqxt@forum.dlang.org
>
> The orignal bug is solved, if you mark the current opEquals const, but I
> don't know if this would brake code outside of phobos, so I tried the
> overload.
>
> Coming to the question: Is it a bug that the const overload is not
> considered and what is the correct way to fix std.typecons.Tuple?
>
>
>


More information about the Digitalmars-d mailing list