comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen_leake@stephe-leake.org>
Subject: container cursor type cannot be tagged
Date: Thu, 28 Aug 2014 14:21:35 -0500
Date: 2014-08-28T14:21:35-05:00	[thread overview]
Message-ID: <85ppfkxvwg.fsf@stephe-leake.org> (raw)

In trying to build my own container package, I ran into a problem; the
Cursor type cannot be tagged. Which means we can't use "Cursor.op"
notation, which I've grown to really like.

The reason it can't be tagged is these two functions defined by
Ada.Iterator_Interfaces (and similar ones for reverse iteration):

   overriding function First (Object : Iterator) return Cursor;
   overriding function Next
     (Object   : Iterator;
      Position : Cursor)
     return Cursor;

Iterator is a tagged type, so Cursor can't be; Ada 2012 doesn't support
dispatching on multiple tagged types (LRM 3.9.3 12).

One solution to this is to define a new aspect Controlling_Type:

   overriding function First (Object : Iterator) return Cursor
   with Controlling_Type => Iterator;

which says to not use Cursor to dispatch calls to this subprogram. That
would be useful in other similar situations. I didn't find an AI on this
issue; would this be worth a proposal?

Another solution would be to provide another version of
Ada.Iterator_Interfaces, where Cursor is explicitly tagged, and these
functions use Cursor'Class. That seems more of a kludge.

-- 
-- Stephe


             reply	other threads:[~2014-08-28 19:21 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-28 19:21 Stephen Leake [this message]
2014-08-28 20:25 ` container cursor type cannot be tagged Randy Brukardt
2014-08-29  7:28   ` Dmitry A. Kazakov
2014-08-29  7:59     ` J-P. Rosen
2014-08-29  8:46       ` Dmitry A. Kazakov
2014-08-29 23:08     ` Randy Brukardt
2014-08-29 14:50   ` Stephen Leake
2014-08-29 23:00     ` Randy Brukardt
2014-08-30 15:16       ` Stephen Leake
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox