diff options
author | Simon Marchi <simon.marchi@polymtl.ca> | 2018-04-09 15:45:39 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@ericsson.com> | 2018-04-09 15:47:12 -0400 |
commit | d5f4488f09b811b0ca44e687da2acbc286d84d4a (patch) | |
tree | 077a671661fadfb1f52c9e58b23b841c6378baba /gdb/common/array-view.h | |
parent | b24531ed171b5751a3a64c461728c9ad62092c8a (diff) | |
download | binutils-d5f4488f09b811b0ca44e687da2acbc286d84d4a.zip binutils-d5f4488f09b811b0ca44e687da2acbc286d84d4a.tar.gz binutils-d5f4488f09b811b0ca44e687da2acbc286d84d4a.tar.bz2 |
Add selftests for range_contains and insert_into_bit_range_vector
Add some selftests for these two functions. To to make it easier to
compare sequences of ranges, add operator== and operator!= to compare
two gdb::array_view, and add operator== in struct range.
gdb/ChangeLog:
* value.c: Include "selftest.h" and "common/array-view.h".
(struct range) <operator ==>: New.
(test_ranges_contain): New.
(check_ranges_vector): New.
(test_insert_into_bit_range_vector): New.
(_initialize_values): Register selftests.
* common/array-view.h (operator==, operator!=): New.
Diffstat (limited to 'gdb/common/array-view.h')
-rw-r--r-- | gdb/common/array-view.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/gdb/common/array-view.h b/gdb/common/array-view.h index 3a09ec7..319ea99 100644 --- a/gdb/common/array-view.h +++ b/gdb/common/array-view.h @@ -174,6 +174,33 @@ private: size_type m_size; }; +/* 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. */ + +template <typename T> +bool +operator== (const gdb::array_view<T> &lhs, const gdb::array_view<T> &rhs) +{ + if (lhs.size () != rhs.size ()) + return false; + + for (size_t i = 0; i < lhs.size (); i++) + if (!(lhs[i] == rhs[i])) + return false; + + return true; +} + +/* Compare two array_views for inequality. */ + +template <typename T> +bool +operator!= (const gdb::array_view<T> &lhs, const gdb::array_view<T> &rhs) +{ + return !(lhs == rhs); +} + } /* namespace gdb */ #endif |