'optional' in namespace 'std' does not name a template type

Hello,

Some time ago I successfully developed a sketch for the ESP8266 board, which was using std::optional.
I'm now trying to port it to Arduino Uno, using an Ethernet W5500 shield.

Unfortunately the compiler keeps complaining with the message:
'optional' in namespace 'std' does not name a template type
std::optional ethernetClient_SC;

This same behavior occurs on both Arduino IDE 1.8.x and 2.0.x fresh install.

#include <Ethernet.h>
#include <EthernetUdp.h>
#include <SPI.h>
#include <Dns.h>
#include <Dhcp.h>
#include <NtpClientLib.h>
#include <TimeLib.h>
std::optional<EthernetClient> ethernetClient_SC;

Afaik, std::optional is part of the C++17 standard.
So, does IDE 2.0.x for Arduino Uno fully supports the C++17 standard? Or perhaps it only supports part of the standard?...

Anyway, is there a (simple :-)) way for me to keep using std::optional?

Thank you!

PS-Not sure this question is in the right category... perhaps it should have been in Arduino IDE category instead?...

AVR boards are compiled with -std=g++11
And AVR lacks libc++ and STL, so might not support std::optional even if the std was updated.

So, probably there's no workaround for me to keep using std::optional, right?

a.) get back to ESP chips – they are much better anyway
b.) find/write a polyfill for optional

i'd just keep using esp chips :stuck_out_tongue: they are cheap and powerful.

@ Daveet: Thanks for the tip. I will consider it.

Anyway, as my original question was how to use std::optional in Arduino Uno, I'm going to mark @westfw solution as the right answer.
Thank you all!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.