Skip to content

remove const from <random>:distribution::operator()#2732

Merged
StephanTLavavej merged 7 commits into
microsoft:mainfrom
fsb4000:fix1912
May 24, 2022
Merged

remove const from <random>:distribution::operator()#2732
StephanTLavavej merged 7 commits into
microsoft:mainfrom
fsb4000:fix1912

Conversation

@fsb4000
Copy link
Copy Markdown
Contributor

@fsb4000 fsb4000 commented May 19, 2022

Fixes #1912

normal_distribution didn't have the const

STL/stl/inc/random

Lines 2938 to 2947 in 1a20fe1

template <class _Engine>
_NODISCARD result_type operator()(_Engine& _Eng) {
return _Eval(_Eng, _Par);
}
template <class _Engine>
_NODISCARD result_type operator()(_Engine& _Eng, const param_type& _Par0) {
reset();
return _Eval(_Eng, _Par0, false);
}

$ type main.cpp
#include <random>

int main() {
    std::default_random_engine random;
    const /*<-*/ std::uniform_int_distribution<int> dist;
    return dist(random);
}
cl /EHsc /W4 /WX /nologo main.cpp
main.cpp
main.cpp(6): error C3848: expression having type 'const std::uniform_int_distribution<int>' would lose some const-volatile qualifiers in order to call 'int std::uniform_int<_Ty>::operator ()<std::default_random_engine>(_Engine &)'
        with
        [
            _Ty=int,
            _Engine=std::default_random_engine
        ]
cl /EHsc /W4 /WX /nologo /D_ALLOW_RANDOM_DISTRIBUTION_CONST_OPERATOR main.cpp
main.cpp

@fsb4000 fsb4000 requested a review from a team as a code owner May 19, 2022 18:38
@CaseyCarter CaseyCarter added the enhancement Something can be improved label May 19, 2022
Comment thread stl/inc/yvals_core.h Outdated
Comment thread stl/inc/yvals_core.h Outdated
Co-authored-by: Casey Carter <[email protected]>
Copy link
Copy Markdown
Contributor

@CaseyCarter CaseyCarter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, Igor - thanks!

@StephanTLavavej
Copy link
Copy Markdown
Member

Verified that all distributions are tested, and all operator()s changed except for the internal _Small_poisson_distribution and _Beta_distribution which is good.

@StephanTLavavej StephanTLavavej self-assigned this May 21, 2022
@StephanTLavavej
Copy link
Copy Markdown
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej StephanTLavavej merged commit f539c0e into microsoft:main May 24, 2022
@StephanTLavavej
Copy link
Copy Markdown
Member

Thanks for making it easier for users to write portable code! 🚢 📦 😸

@fsb4000 fsb4000 deleted the fix1912 branch May 24, 2022 05:16
fsb4000 added a commit to fsb4000/STL that referenced this pull request Aug 13, 2022
brianferguson referenced this pull request in rainmeter/rainmeter Sep 1, 2022
Is this is a bug with "const std::uniform_int_distribution" ?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Something can be improved

Projects

None yet

Development

Successfully merging this pull request may close these issues.

<random>: distribution::operator() is erroneously const

3 participants