Indiana Unversity logo[ConceptGCC]

ConceptGCC :

Re: FAQ 7. Is it possible to adapt member functions using concept maps?

From: Sebastian Gesemann (s.gesemann_at_[hidden])
Date: 2009-08-04 02:29:27


Helmut Zeisel wrote:
> As I understand, the main reason that concept maps cannot adapt members are only syntactic problems. I agree that in many situations, non-member functions are a good solution. There are, however, examples where a member function is IMHO a much better solution. Consider e.g. a template functions that uses a Matrix concept:
>
> template<Matrix a> void f(Matrix& a)
> {
> ...
> a(i,j) = ...
> }
>
> How should I access the elements of a matrix? In C++, two options are frequentliy used, either a(i,j) or a[i][j]. So the template code must use some nonmember-function like
>
> ele(a,i,j)
>
> which is ugly and unintiutive.

Yes, it is. But you don't need to write this. If there is an
appropriate concept requirement for operator() you can invoke it via
a(i,j) even though the requirement is written as "reference
operator()(M&m, unsigned i, unsigned j)" or something like that.

Cheers!
SG