const?? When and why? This is ugly!

Burton Radons burton.radons at shaw.ca
Fri Mar 6 16:04:10 PST 2009


Andrei Alexandrescu Wrote:

> This is a known problem for hich we will provide a solution.

If you have something which works everywhere please tell us because we've been trying to find one for a long time, but as far as I know there is no solution. The best I've ever gotten to is:

   // "A" means that the constness of the return type depends upon the constness of the argument. There are dozens of ways to specify the same thing.
   const (A) mstring match (const (A) mstring text, RE expression);

But setting aside whether that helps or hinders self-documentation, that's far from the only place at which you put mutable data through a const section that you need to modify later. What if the function were instead:

   struct REMatch
   {
      string match; /// The matched string.
      size_t offset; /// Offset within the string where the match occurs.
      string [] groups; /// Matched groups.

      this (string text);
   }

What am I going to do about this now without using templates? If you define a special syntax to make this work, then I can give you something even further which won't.



More information about the Digitalmars-d mailing list