public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 1/2] vec: Add array_slice constructors from non-const and gc vectors
@ 2022-08-26 16:38 Martin Jambor
  2022-08-26 18:22 ` Richard Biener
  0 siblings, 1 reply; 13+ messages in thread
From: Martin Jambor @ 2022-08-26 16:38 UTC (permalink / raw)
  To: GCC Patches; +Cc: Richard Biener, Richard Sandiford

Hi,

This patch adds constructors of array_slice that are required to
create them from non-const (heap or auto) vectors or from GC vectors.

The use of non-const array_slices is somewhat limited, as creating one
from const vec<some_type> still leads to array_slice<const some_type>,
so I eventually also only resorted to having read-only array_slices.
But I do need the constructor from the gc vector.

Bootstrapped and tested along code that actually uses it on
x86_64-linux.  OK for trunk?

Thanks,

Martin


gcc/ChangeLog:

2022-08-08  Martin Jambor  <mjambor@suse.cz>

	* vec.h (array_slice): Add constructors for non-const reference to
	heap vector and pointers to heap vectors.
---
 gcc/vec.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/gcc/vec.h b/gcc/vec.h
index eed075addc9..b0477e1044c 100644
--- a/gcc/vec.h
+++ b/gcc/vec.h
@@ -2264,6 +2264,18 @@ public:
   array_slice (const vec<OtherT> &v)
     : m_base (v.address ()), m_size (v.length ()) {}
 
+  template<typename OtherT>
+  array_slice (vec<OtherT> &v)
+    : m_base (v.address ()), m_size (v.length ()) {}
+
+  template<typename OtherT>
+  array_slice (const vec<OtherT, va_gc> *v)
+    : m_base (v ? v->address () : nullptr), m_size (v ? v->length () : 0) {}
+
+  template<typename OtherT>
+  array_slice (vec<OtherT, va_gc> *v)
+    : m_base (v ? v->address () : nullptr), m_size (v ? v->length () : 0) {}
+
   iterator begin () { return m_base; }
   iterator end () { return m_base + m_size; }
 
-- 
2.37.2


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-08-30  8:01 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-26 16:38 [PATCH 1/2] vec: Add array_slice constructors from non-const and gc vectors Martin Jambor
2022-08-26 18:22 ` Richard Biener
2022-08-26 20:05   ` Martin Jambor
2022-08-29  8:09     ` Richard Biener
2022-08-29  8:09       ` Richard Biener
2022-08-29  8:31       ` Martin Jambor
2022-08-29 10:27       ` Martin Jambor
2022-08-29 11:26         ` Richard Biener
2022-08-29 11:26           ` Richard Biener
2022-08-29 11:50           ` Martin Jambor
2022-08-29 12:34             ` Richard Biener
2022-08-29 12:34               ` Richard Biener
2022-08-30  8:01               ` Richard Sandiford

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).