简体   繁体   English

Visual Studio 2019 c++latest generic URNG function 最新更新后编译失败

[英]Visual Studio 2019 c++latest generic URNG function fails to compile after latest update

I have the following generic C++ generic URNG function:我有以下通用 C++ 通用 URNG function:

template<class URNG> 
void TestURNG(URNG& urng)
{
    // Uniform distribution used with vector
    // Distribution is [-5, 5] inclusive
    uniform_int_distribution<long> dist(-5, 5);
    vector<long> v;
    v.resize(20);
    generate(v.begin(), v.end(), [&] { return dist(urng); });
    cout << "Randomized vector: ";
    copy(v.begin(), v.end(), ostream_iterator<long>(cout, " "));
    cout << endl;

    // Shuffle an array.
    // Notice that shuffle() takes an URNG, not a distribution
    vector<string> strings = { { "H", "He", "Li", "Be", "B", "C", "N", "O", "F",
        "Ne", "Na", "Mg", "Al", "Si", "P", "S", "Cl", "Ar", "K", "Ca", "Sc",
        "Ti", "V", "Cr", "Mn", "Fe" } };
    shuffle(strings.begin(), strings.end(), urng);
    cout << "Randomized vector<string>: ";
    copy(strings.begin(), strings.end(), ostream_iterator<string>(cout, " "));
    cout << endl;
}

And I call the function from the following test function:我从以下测试 function 中调用 function:

void TestRandom()
{
    // First run: non-seedable, non-deterministic URNG random_device
    // Slower but crypto-secure and non-repeatable.
    random_device device;
    cout << "Using random_device URNG:" << endl;
    TestURNG(device);

    // Second run: simple integer seed. Repeatable results
    cout << "Using constant-seed mersene twister engine URNG:" << endl;
    mt19937_64 constant_seed_mersene_twister_engine(mt19937_64(12345));
    TestURNG(constant_seed_mersene_twister_engine);

    // Third run: random_device as seed; different each run.
    // Desirable for most purposes
    cout << "Using non-deterministic-seed mersene twister engine URNG:" << endl;
    mt19937_64 non_deterministic_seed_mersene_twister_engine(mt19937_64(device()));
    TestURNG(non_deterministic_seed_mersene_twister_engine);

    // Fourth run: "warm-up" sequence as as seed; different each run.
    // Advanced uses. Allows more than 32 bits of randomness.
    cout << "Using non-deterministic-seed \"warm-up\" sequence mersene twister engine URNG" << endl;
    vector<unsigned int> seeds;
    cout << "mt19937_64::state_size: " << mt19937_64::state_size << endl;
    seeds.resize(mt19937_64::state_size);
    generate_n(seeds.begin(), mt19937_64::state_size, ref(device));
    seed_seq sequence(begin(seeds), end(seeds));
    mt19937_64 non_deterministic_seed_sequence_mersene_twister_engine(mt19937_64(sequence));
    TestURNG(non_deterministic_seed_sequence_mersene_twister_engine);
}

Using c++latest in Visual Studio 2019 results in the following compilation errors:在 Visual Studio 2019 中使用c++latest会导致以下编译错误:

Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\xutility(5911,27): error C2825: '_Urng': must be a class or namespace when followed by '::' (compiling source file urng.cpp)
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\algorithm(5468): message : see reference to class template instantiation 'std::_Rng_from_urng<int,_Urng0>' being compiled (compiling source file urng.cpp)
1>C:\Projects\C++\urng\urng\urng.cpp(9205): message : see reference to function template instantiation 'void std::shuffle<std::_Vector_iterator<std::_Vector_val<std::_Simple_types<_Ty>>>,URNG(__cdecl &)>(_RanIt,_RanIt,_Urng)' being compiled
1>        with
1>        [
1>            _Ty=std::string,
1>            URNG=std::mt19937_64 (std::mt19937_64),
1>            _RanIt=std::_Vector_iterator<std::_Vector_val<std::_Simple_types<std::string>>>,
1>            _Urng=std::mersenne_twister_engine<unsigned __int64,64,312,156,31,13043109905998158313,29,6148914691236517205,17,8202884508482404352,37,18444473444759240704,43,6364136223846793005> (__cdecl &)(std::mt19937_64)
1>        ]
1>C:\Projects\C++\urng\urng\urng.cpp(9238): message : see reference to function template instantiation 'void TestURNG<std::mt19937_64(std::mt19937_64)>(URNG (__cdecl &))' being compiled
1>        with
1>        [
1>            URNG=std::mt19937_64 (std::mt19937_64)
1>        ]
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\xutility(5911,34): error C2510: '_Urng': left of '::' must be a class/struct/union (compiling source file urng.cpp)
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\xutility(5911,1): error C2061: syntax error: identifier 'result_type' (compiling source file urng.cpp)
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\xutility(5913,41): error C2065: '_Ty1': undeclared identifier (compiling source file urng.cpp)
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\xutility(5913,3): error C2065: '_Ty1': undeclared identifier (compiling source file urng.cpp)
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\xutility(5913,20): error C2923: 'std::conditional_t': '_Ty1' is not a valid template type argument for parameter '_Ty2' (compiling source file urng.cpp)

It used to work but recent VS2019 update caused it to fail.它曾经可以工作,但最近的 VS2019 更新导致它失败。 What do I miss?我想念什么?

Most vexing parse problem.最令人头疼的解析问题。

You have to write:你必须写:

mt19937_64 non_deterministic_seed_sequence_mersene_twister_engine{mt19937_64(sequence)};

now, you defines a function declaration.现在,您定义了一个 function 声明。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Visual Studio 2019 c++latest random_device uniform_int_distribution 抛出未处理的异常 - Visual Studio 2019 c++latest random_device uniform_int_distribution throws unhandled exception Visual Studio 2019 - 如何手动编辑.props/solution 文件强制 c++17/c++latest 标准? - Visual Studio 2019 - how to manually edit .props/solution file to force c++17/c++latest standard? 如何在 cmake 中启用`/std:c++latest`? - How to enable `/std:c++latest` in cmake? 在模板函数中包装 std::format 无法使用最新的 MSVC 编译器更新进行编译 - Wrapping std::format in a template function fails to compile with the latest MSVC compiler update 使用/ std:c ++最新版(或C ++ 17 / N4190)使用MSVC2015编译boost - Compiling boost with MSVC2015 with /std:c++latest (or C++17/N4190) Visual Studio 2019 编译构建 - Visual studio 2019 compile and build 以 Visual Studio 为目标的 Windows XP 的最新 C++ 标准是什么? - What is the latest C++ standard to target Windows XP with Visual Studio? 热修复客户站点时,最新的Visual Studio 2005安全更新是否会导致C运行时库问题? - Does the latest Visual Studio 2005 Security Update cause C runtime library issues when hot fixing customer sites C++ 模板 function 在 Visual Studio 2019 中不起作用 [错误 2668] - C++ Template function not working in Visual Studio 2019 [Error 2668] 用 CMake 和 Visual Studio 2019 编译 GLEW? - Compile GLEW with CMake and Visual Studio 2019?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM