3000. monotonic_memory_resource::do_is_equal uses dynamic_cast unnecessarily

Section: 23.12.6.2 [mem.res.monotonic.buffer.mem] Status: Tentatively Ready Submitter: Pablo Halpern Opened: 2017-07-14 Last modified: 2017-11-01

Priority: 0

View all issues with Tentatively Ready status.

Discussion:

Section [mem.res.monotonic.buffer.mem], paragraph 11 says

bool do_is_equal(const memory_resource& other) const noexcept override;

Returns: this == dynamic_cast<const monotonic_buffer_resource*>(&other).

The dynamic_cast adds nothing of value. It is an incorrect cut-and-paste from an example do_is_equal for a more complex resource.

[2017-07-16, Tim Song comments]

The pool resource classes appear to also have this issue.

[2017-09-18, Casey Carter expands PR to cover the pool resources.]

Previous resolution: [SUPERSEDED]
  1. Edit 23.12.6.2 [mem.res.monotonic.buffer.mem] as indicated:

    bool do_is_equal(const memory_resource& other) const noexcept override;
    

    Returns: this == dynamic_cast<const monotonic_buffer_resource*>(&other).

[ 2017-11-01 Moved to Tentatively Ready after 7 positive votes for P0 on c++std-lib. ]

Proposed resolution:

This resolution is relative to N4687.

  1. Edit 23.12.5.4 [mem.res.pool.mem] as indicated:

    bool synchronized_pool_resource::do_is_equal(const memory_resource& other) const noexcept override;
        const memory_resource& other) const noexcept override;
    

    Returns: this == dynamic_cast<const synchronized_pool_resource*>(&other).

  2. Strike 23.12.5.4 [mem.res.pool.mem] paragraph 10, and the immediately preceding declaration of unsynchronized_pool_resource::do_is_equal.

  3. Edit 23.12.6.2 [mem.res.monotonic.buffer.mem] as indicated:

    bool do_is_equal(const memory_resource& other) const noexcept override;
    

    Returns: this == dynamic_cast<const monotonic_buffer_resource*>(&other).