Syntax errors from Sy's Demo from DotNet Conf when using C++ 20 Pipes (Ranges)

Siegfried Heintze 1,861 Reputation points
2021-11-10T21:07:59.653+00:00

I'm using VS2022 that I downloaded yesterday (2021 Nov 9 Version 17.0.0)

I'm trying to follow along in with Sy to create a demonstration of a few new C++ 20 features and I'm getting some syntax errors.

#include <iostream>
#include <conio.h>
#include <tl/generator.hpp>
#include <ranges>
import xorshift;

int main(int argc, char**argv)
{
    auto random_numbers = launch::xorshift(4)
        | std::views::transform([](auto i) { return i % 100; })
        //| std::views::take(5)
        ;
    for (auto i : random_numbers) {
        std::cout << i << std::endl;
    }
    std::cout << "any key to exit:  " <<std::flush;
    _getch();
    return 0;
}

I'm getting this error (oops, looks like my source code contain a few blank lines at the beginning that I failed to paste so the line numbers in the error messages are incorrect). The errors are occurring on the lines with pipes).

Severity Code Description Project File Line Suppression State Detail Description
Error (active) E0349 no operator "!=" matches these operands ModulesRangesVS2022Demo C:...\C++\c++20\ModulesRangesVS2022Demo\ModulesRangesVS2022Demo\ModulesRangesVS2022Demo.cpp 16 operand types are: std::ranges::transform_view<tl::generator<unsigned long long>, std::remove_reference_t<type &>>::_Iterator<false> != std::ranges::transform_view<tl::generator<unsigned long long>, std::remove_reference_t<type &>>::_Sentinel<false>

When I remove the comment I get a different error:

Severity Code Description Project File Line Suppression State
Error (active) E0349 no operator "|" matches these operands ModulesRangesVS2022Demo C:...\C++\c++20\ModulesRangesVS2022Demo\ModulesRangesVS2022Demo\ModulesRangesVS2022Demo.cpp 14

Here is the xorshift.ixx file:

module;
#include <cstdint>
#include <tl/generator.hpp>
export module xorshift;

export namespace launch {
 tl::generator<std::uint64_t> xorshift(std::uint64_t seed) {
 while (true) {
 seed ^= seed >> 13;
 seed ^= seed << 17;
 seed ^= seed >> 7;
 co_yield seed;
 }

 }
}

Here is the vcpkg.json

{
  "name": "launch",
  "version-string": "1.0.0",
  "dependencies": [
    "tl-generator"
  ]
}

** Sat Nov 13 2021 Update**

Yahoo!

I was getting an error about being unable to start the program... This was solved by following the instructions to automatically close the console...
Hot reload works after all! Yahoo! Very impressive!

Thanks MinxinYu! you have answered my original question. Is it OK to broaden the scope of the question?

  1. Where is the exe file? it does not appear in the debug directory with windows explorer (or emacs or cmd.exe/dir or bash/ls). It does appear in the output window however. I know it is there because my program is running and the full path appears in the output window of Visual Studio 2022! I would like to run the executable from the command line but I cannot find it!

Oops, I figured out the answers to my other questions myself...

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,519 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Minxin Yu 9,866 Reputation points Microsoft Vendor
    2021-11-12T03:15:39.183+00:00

    Hi, @Siegfried Heintze

    I followed the video and received the same error, but the program ran successfully. This is an issue of IntelliSense and you can report it to Developer Community.

    Best regards,

    Minxin Yu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.