Import CStringView from the Babeltrace tree
[lttng-tools.git] / src / common / container-wrapper.hpp
index 5ee20dfeab3b2b3f92d94539ddf25dd156fae0e1..25385fc43837961ec4301dd9f7254f0b89ccc3b6 100644 (file)
@@ -60,6 +60,11 @@ class random_access_container_wrapper {
                        return *this;
                }
 
+               ptrdiff_t operator-(const _iterator& other) const
+               {
+                       return _index - other._index;
+               }
+
                bool operator==(const _iterator& other) const noexcept
                {
                        return _index == other._index;
@@ -99,7 +104,7 @@ public:
 
        iterator end()
        {
-               return iterator(*this, ContainerOperations::size(_container));
+               return iterator(*this, size());
        }
 
        const_iterator begin() const noexcept
@@ -109,14 +114,19 @@ public:
 
        const_iterator end() const
        {
-               return const_iterator(*this, ContainerOperations::size(_container));
+               return const_iterator(*this, size());
        }
 
-       std::size_t size() const noexcept
+       std::size_t size() const
        {
                return ContainerOperations::size(_container);
        }
 
+       bool empty() const
+       {
+               return size() == 0;
+       }
+
        typename std::conditional<std::is_pointer<ElementType>::value, ElementType, ElementType&>::type
        operator[](std::size_t index)
        {
@@ -130,7 +140,7 @@ public:
                 *
                 * For more information, see Item 3 of Effective C++.
                 */
-               const auto& const_this = static_cast<const decltype(*this)&>(*this);
+               const auto& const_this = static_cast<const random_access_container_wrapper&>(*this);
 
                /* NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast) */
                return const_cast<typename std::conditional<std::is_pointer<ElementType>::value,
@@ -144,7 +154,7 @@ public:
        operator[](std::size_t index) const
        {
                if (index >= ContainerOperations::size(_container)) {
-                       LTTNG_THROW_INVALID_ARGUMENT_ERROR(fmt::format(
+                       throw std::invalid_argument(lttng::format(
                                "Out of bound access through random_access_container_wrapper: index={}, size={}",
                                index,
                                size()));
This page took 0.02401 seconds and 4 git commands to generate.