C++ Logo

std-proposals

Advanced search

Re: [std-proposals] [[pure]] attribute

From: Ell <ell_se_at_[hidden]>
Date: Tue, 4 Mar 2025 12:59:42 +0200
On 3/4/25 12:20, Tymi via Std-Proposals wrote:
> Yes, the compiler might assume that the function produces the same
> effect for the same arguments.
    int sum (const std::vector<int>& v) [[pure]];

    void f () {
        std::vector<int> v = {1, 2, 3};

        int s1 = sum (v);

        v.push_back (4);

        int s2 = sum (v); // is this the same argument?
    }

    void g () {
        std::vector<int> v = {1, 2, 3};
        std::vector<int> w = {1, 2, 3};

        int s1 = sum (v);
        int s2 = sum (w); // is this the same argument?
    }

Received on 2025-03-04 10:59:52