Using C ++ 17 "any" with Xcode 8.1

I am using C ++ in Xcode version 8.1. I need to use boost::any functionality, but I am categorically against pulling any part of Boost into our project (let them not discuss it, please).

I see that std::any "merged in C ++ 17" here .

I want to use this in my Xcode 8.1 project. I tried using -std=c++1z as a custom flag in the project, but I cannot find a title for it.

How can I use std::any or std::experimental::any in my Xcode project?

Is it possible to download the appropriate headers from the implementation and throw them into the project source code? Or, better yet, is it actually available now in my version of Xcode / Clang / C ++?

+6
source share
4 answers

You cannot say "I need the default Xcode compiler (which does not support any ]" and at the same time asked it to support any . You also cannot mix standard library headers for different versions of the compiler.

You can either

  • use a compiler version that provides std::any or
  • use any third-party library that provides a different type of any .
+6
source

Your installation does not have the C ++ 17 standard installed. std::any simply not available to you unless you get a compiler with at least experimental support for what you want.

Clang Cxx Status

You would be much better off just using boost::any .

If you are really determined not to add a third-party library to the game, the reality is that creating your own any not that difficult. I do not recommend reinventing the wheel, but in this case it is not so difficult.

Here is an SO question with an answer showing a way to do "any . "

+2
source

You cannot enter new types in std through a third-party library. You can upgrade your compiler, get a separate std library that your compiler supports, or use a third-party library that provides any in a different namespace, or write your own.

The first thing you said no.

The second is tricky, since xcode doesn't advertise what its compiler is. Typically, there are two common std libraries that work with clang-llvm compilers; lib ++ and libstd ++. Such an exchange tends to be very expensive, even if the other has the function you want.

The third basically "uses boost " or the equivalent.

The latter is not difficult; for several days of work (mainly errors after the fact), based on writing types of similar complexity, provided that "good enough" is good enough (that is, they do not fall into ideal guarantees of exclusion or exactly correspond to the standard, etc.) . Naturally, hyperbolic effort will be required to achieve perfection.

+2
source

Xcode 9.0 beta can now be downloaded ( https://developer.apple.com/download/ ). It supports the C ++ 17 flag flag.

Edit: Xcode 9.2 is publicly available with std :: any support.

+2
source

Source: https://habr.com/ru/post/1013078/


All Articles