如何在Mac上使用c ++ 2a编译生成器和协程

时间:2018-12-22 21:13:37

标签: c++ xcode macos generator c++-coroutine

我正在为C ++ 20设置MacBook,但无法编译代码。我已经安装了最新的Xcode,llvm和gcc。这是我要编译的代码

<div id="myCarousel" class="carousel slide" data-ride="carousel">
  <!-- Indicators -->
  <ol class="carousel-indicators">
    <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
    <li data-target="#myCarousel" data-slide-to="1"></li>
    <li data-target="#myCarousel" data-slide-to="2"></li>
  </ol>

  <!-- Wrapper for slides -->
  <div class="carousel-inner" role="listbox">
    <div class="item active">
      <img src="ny.jpg" alt="New York">
      <div class="carousel-caption">
        <h3>New York</h3>
        <p>The atmosphere in New York is lorem ipsum.</p>
      </div> 
    </div>

    <div class="item">
      <img src="chicago.jpg" alt="Chicago">
      <div class="carousel-caption">
        <h3>Chicago</h3>
        <p>Thank you, Chicago - A night we won't forget.</p>
      </div> 
    </div>

    <div class="item">
      <img src="la.jpg" alt="Los Angeles">
      <div class="carousel-caption">
        <h3>LA</h3>
        <p>Even though the traffic was a mess, we had the best time.</p>
      </div> 
    </div>
  </div>

  <!-- Left and right controls -->
  <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
    <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
    <span class="sr-only">Previous</span>
  </a>
  <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div>

但是我遇到以下错误:

#include <chrono>
#include <experimental/coroutine>
#include <future>
#include <iostream>

using namespace std;

generator<int> getInts(int first, int last) {
  for (auto i = first; i <= last; ++i) {
    co_yield i;
  }
}

int main() {
  for (auto i : getInts(5, 10)) {
    std::cout << i << " ";
  }
}

赞赏有识之士如何解决此编译问题。

1 个答案:

答案 0 :(得分:0)

Coroutines TS尚未获得C ++ 20的投票(实际上,已经有三张单独的票,但在所有票证中均未达成共识),因此,即使GCC实施了该投票( which it doesn't),则不会被-std=c++2a开关激活。

现在,Clang确实实现了协程TS,您必须使用-fcoroutines-ts将其打开。显然,您必须使用libc ++。