diff options
Diffstat (limited to 'gdbsupport/array-view.h')
-rw-r--r-- | gdbsupport/array-view.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/gdbsupport/array-view.h b/gdbsupport/array-view.h index edf6655..5f1f46b 100644 --- a/gdbsupport/array-view.h +++ b/gdbsupport/array-view.h @@ -19,6 +19,7 @@ #define COMMON_ARRAY_VIEW_H #include "traits.h" +#include <algorithm> #include <type_traits> /* An array_view is an abstraction that provides a non-owning view @@ -206,6 +207,20 @@ private: size_type m_size; }; +/* Copy the contents referenced by the array view SRC to the array view DEST. + + The two array views must have the same length. */ + +template <typename U, typename T> +void copy (gdb::array_view<U> src, gdb::array_view<T> dest) +{ + gdb_assert (dest.size () == src.size ()); + if (dest.data () < src.data ()) + std::copy (src.begin (), src.end (), dest.begin ()); + else if (dest.data () > src.data ()) + std::copy_backward (src.begin (), src.end (), dest.end ()); +} + /* Compare LHS and RHS for (deep) equality. That is, whether LHS and RHS have the same sizes, and whether each pair of elements of LHS and RHS at the same position compares equal. */ |