#include #include #include #include #include using namespace std; #define T printf("%s [%d]\n", __PRETTY_FUNCTION__, val) struct foo { foo(int x = 0) : val(x) { T; } ~foo() { T; } void print() const { cout << "foo{" << val << "}\n"; } int val; }; std::optional find(std::vector> const &v) { if (v.size() > 0) return v[0]; else std::nullopt; } int main() { std::vector> v(5); v[0] = optional(4); auto f = find(v); if (f) printf("found\n"); else printf("not found\n"); }