Xcode 10 call to unavailable function std::visit

前端 未结 3 1793
自闭症患者
自闭症患者 2020-12-29 05:56

When compiling following program with Xcode 10 GM:

#include 
#include 
#include 

void hello(int) {
    std::cou         


        
3条回答
  •  一个人的身影
    2020-12-29 06:25

    Even though templates generally come from headers, doesn't mean the runtime target doesn't matter. Those templates are part of a wider library, and they compile to code that must still be compatible with the rest of that library. It makes sense for the whole standard library to be of one, single version, and it makes sense for that version to be the one that'll work on the target machine. Can you imagine the chaos that would ensue otherwise?

    Some of the others here have given some low-level, practical reasons why in this particular case that version unity is important. Personally I think it's best to forget about implementation details like "templates go in headers" in situations like this; you shouldn't need to care about it, plus you risk making abstraction-breaking assumptions for little benefit. Just code to contract and you'll be fine.

提交回复
热议问题