Search code examples
c++compiler-errorsstdtuple

no template named 'tuple' in C++


I am not allowed to initialise a tuple in C++. When I compile it comes up the following error while pointen at tuple: no template named 'tuple'. I am using Mac and have specified my tasks.json as shown in the bottom of the page.

Code

#include <tuple>
#include <iostream>
using namespace std;
int main() {

    tuple<int,int> f;

    return 0;
}

Error message:

error: no template named 'tuple'
tuple<int,int> f;
^

1 error generated.

tasks.json (taken from https://code.visualstudio.com/docs/cpp/config-clang-mac where I have followed their guidelines):

{
"version": "2.0.0",
"tasks": [
    {
        "type": "shell",
        "label": "clang++ build active file",
        "command": "/usr/bin/clang++",
        "args": [
            "-std=c++17",
            "-stdlib=libc++",
            "-g",
            "${file}",
            "-o",
            "${fileDirname}/${fileBasenameNoExtension}"
        ],
        "options": {
            "cwd": "${workspaceFolder}"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": "build"
    },
    {
        "type": "cppbuild",
        "label": "C/C++: clang++ build active file",
        "command": "/usr/bin/clang++",
        "args": [
            "-g",
            "${file}",
            "-o",
            "${fileDirname}/${fileBasenameNoExtension}"
        ],
        "options": {
            "cwd": "${workspaceFolder}"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        },
        "detail": "Task generated by Debugger."
    }
]

}

Compiler

% clang --version
Apple clang version 11.0.3 (clang-1103.0.32.59)
Target: x86_64-apple-darwin19.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Solution

  • Based on the comments, the problem was, that the task cppbuild was used instead of shell, and for that task, no c++ version was defined. Due to that default version for that compiler was used which does not support tuple.

    Adding "-std=c++17", to the args of cppbuild solves that problem.