Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get std::optional support in Xcode?

I'm trying to use std::optional in an Xcode 12.0 Mac OS project. I'm getting the error: No template named 'optional' in namespace 'std'

#include <optional>

std::optional<int> o;

My settings are (I need libc++ for project):

enter image description here

like image 975
bhartsb Avatar asked Aug 31 '25 17:08

bhartsb


1 Answers

The version of libc++ that Apple ships as part of Xcode 12 (and 11) includes support for many C++17 features, including optional. See the Xcode 11 release notes.

The text in Xcode that says that libc++ "supports C++11" is in contrast to the standard library (libstdc++ v 4.2.1) that Apple used to ship - that did not support C++11. It does not mean that it only supports C++11 to the exclusion of C++14/17/20/etc.

The OP mentioned in a comment that he had a -std=gnu++11 in the "Other flags" that was causing the problem.

like image 107
Marshall Clow Avatar answered Sep 02 '25 14:09

Marshall Clow