Search code examples
c++llvm-clangusing-declaration

Cannot use "using" declaration for std::tuple on Apple LLVM 7.3.0


I'm attempting to use tuple in my program, and for some reason I am not able to simplify the call with a using declaration. For example:

#include <tuple>

using std::tuple;

...

This throws an error when attempting to compile it:

error: no member named 'tuple' in namespace 'std'

I'm able to use using declarations for other things (like std::string, std::get, etc.) just fine. I think I've narrowed it down to a compiler issue, but I don't have control over which compiler I get to use (university server) and I can't find anything online showing a lack of support for this header or anything. Here is my compiler information:

$ clang++ -v

Apple LLVM version 7.3.0 (clang-703.0.31)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Any thoughts? Here's an example of it working elsewhere: http://cpp.sh/5bofm


Solution

  • Because the include did not give a preprocessor error, it is likely that the tuple header does exist and that this is not a case of a messed-up/out-of-date C++ standard library install.

    However tuple not being defined in std is expected for all the C++ standards before C++11.

    With a standard installation and without additional flags your Clang's version should be using C++14, however this seems to have been modified by whoever is maintaining that system or some package maintainer.

    To make sure you are using the most recent C++ language standard add -std=c++17 to the compiler invocation or at least -std=c++14 if C++17 is too recent for some reason, e.g. compatibility with older compiler installations. In particular if your are coding for a university class, you might want to ask to clarify up to which C++ standard is acceptable to use.