I am using C++ in Xcode version 8.1. I need to use the functionality of boost::any
but am strongly opposed to pulling any part of Boost into our project (let's not debate it please).
I see that std::any
is "merged into C++17" here.
I want to use this in my Xcode 8.1 project. I have tried using -std=c++1z
as a custom flag on the project, but I can't seem to find a header for it.
How can I use std::any
or std::experimental::any
in my Xcode project?
Can I download the appropriate headers from an implementation and throw them into my project's sourcecode? Or, even better, is actually available to now in my version of Xcode/Clang/C++?
Your installation setup does not have the c++17 standard. std::any
simply is not available to you unless you get a compiler with at least experimental support for what you want.
Clang Cxx Status
You'd have a lot better luck just using boost::any
probably.
If you're really set on not bringing a third party library into play, the reality is that creating your own any
isn't that difficult. I don't recommend reinventing the wheel but in this case it's not that difficult.
Here's a SO question with an answer showing a way to do 'any'.
You can't say "I want the default Xcode compiler [which has no support for any
]" and at the same time request it to support any
. You also can't mix standard library headers for different compiler versions.
You can either
std::any
orany
-like type.It is illegal to inject new types into std
via a third party library. You can upgrade your compiler, get a distinct std library your compiler supports, or use a 3rd party library that provides any
in another namespace, or write your own.
The first you said no to.
The second is hard, as xcode does not advertise what its compiler actually is. There are generally two common std libraries that work with clang-llvm derived compilers; libc++ and libstdc++. That kind of swap tends to be very expensive even if the other one has the feature you want.
The third is basically "use boost
" or equivalent.
The last isn't hard; a few days work (mostly bugs after the fact), based on writing types of similar complexity, assuming "good enough" is good enough (ie, not getting caught up in ideal exception guarantees, or matching standard exactly, etc). An implementation will require hyperbolic effort to approach perfection, naturally.
Xcode 9.0 beta can now be downloaded (https://developer.apple.com/download/). It supports the c++17 flag option.
Edit: Xcode 9.2 is publically available with std::any support.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With