[Development] C++11 decltype magic with a container?
Olivier Goffart
olivier at woboq.com
Thu May 23 17:36:14 CEST 2013
On Thursday 23 May 2013 17:24:35 Stephen Kelly wrote:
> On Thursday, May 23, 2013 07:56:16 Thiago Macieira wrote:
> > On quinta-feira, 23 de maio de 2013 16.12.27, Stephen Kelly wrote:
> > > I was not referring to the patch in gerrit. I was referring to the code
> > > I
> > > pasted. It contains a struct called 'A', and I made a note and a comment
> > > about enable_if.
> >
> > Oh! Somehow I missed that!
>
> Yes, I guessed that, which is why I asked you to re-read it several times
> :).
> > Yes, you need to add those enable_ifs. Or concepts :-)
>
> I guess you also missed where I wrote "I also tried an enable_if, but that
> doesn't solve the problem either."
>
> So, I was looking for other ideas, but I don't think there is any workable
> solution. Maybe looking for mapped_type, key_type and value_type on the
> T::value_type (recursively) might work, but it would be so ugly and only
> really partially working that I don't think I'll even try.
>
> Thanks,
First, the operator== should be outside of the class. (or as a friend
function)
It probably would becomes something like
struct Container {
friend auto operator==(const T &c1, const T&c2) -> decltype(c1.t == c2.t)
-> decltype(std::declval<T::&>() == std::declval<T&>()) { ... }
...
}
--
Olivier
Woboq - Qt services and support - http://woboq.com - http://code.woboq.org
More information about the Development
mailing list