This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.

4371. Container adaptor's empty/size should be noexcept

Section: 23.6.3.1 [queue.defn], 23.6.4.1 [priqueue.overview], 23.6.6.2 [stack.defn] Status: New Submitter: Hewill Kang Opened: 2025-09-09 Last modified: 2025-09-16

Priority: Not Prioritized

View all other issues in [queue.defn].

View all issues with New status.

Discussion:

C++23 container adaptors flat_meow all have noexcept size/empty members.

However, the size/empty members of other container adaptors are not mark noexcept, even though they behave the same as flat_meow that returning the size/empty of the underlying container.

It makes sense to make them noexcept as well for consistency. Although the standard doesn't explicitly say those two members of the container must not throw, the fact that all standard containers and common third-party containers mark them as unconditionally noexcept implies that it's perfectly reasonable to assume that they never will.

Proposed resolution:

This wording is relative to N5014.

  1. Modify 23.6.3.1 [queue.defn] as indicated:

    namespace std {
      template<class T, class Container = deque<T>>
      class queue {
      public:
        […]
        constexpr bool              empty() const noexcept { return c.empty(); }
        constexpr size_type         size()  const noexcept { return c.size(); }
        […]
      };
      […]
    }
    
  2. Modify 23.6.4.1 [priqueue.overview] as indicated:

    namespace std {
      template<class T, class Container = vector<T>,
               class Compare = less<typename Container::value_type>>
      class priority_queue {
      public:
        […]
        constexpr bool            empty() const noexcept { return c.empty(); }
        constexpr size_type       size()  const noexcept { return c.size(); }
        […]
      };
      […]
    }
    
  3. Modify 23.6.6.2 [stack.defn] as indicated:

    namespace std {
      template<class T, class Container = deque<T>>
      class stack {
      public:
        […]
        constexpr bool              empty() const noexcept { return c.empty(); }
        constexpr size_type         size()  const noexcept { return c.size(); }
        […]
      };
      […]
    }