poco icon indicating copy to clipboard operation
poco copied to clipboard

Poco::Optional cannot hold classes that don't have a default constructor

Open siren186 opened this issue 1 year ago • 4 comments

Describe the bug

class A {
public:
    A(int n) {}
};

int main(int argc, char** argv)
{
    std::optional<A> a1; // ok
    Poco::Optional<A> a2; // compile error !!!
    return 0;
}

siren186 avatar Aug 21 '24 10:08 siren186

This is documented as such and appears to be by design. https://github.com/pocoproject/poco/blob/main/Foundation%2Finclude%2FPoco%2FOptional.h#L45

andrewauclair avatar Aug 22 '24 02:08 andrewauclair

This is documented as such and appears to be by design. https://github.com/pocoproject/poco/blob/main/Foundation%2Finclude%2FPoco%2FOptional.h#L45

In that way, I cannot replace std::optional/boost::optional to Poco::Optional. I hope Poco::Optional can do the same things like std::optional/boost::optional do.

siren186 avatar Aug 22 '24 03:08 siren186

Why would you replace std::optional with Poco::Optional?

andrewauclair avatar Aug 22 '24 10:08 andrewauclair

@andrewauclair I create a pull request to Poco with std::optional, but I got a compile error:

error: 'value' is unavailable: introduced in macOS 10.13
                                        r.value().get().run();
                                          ^
/Applications/Xcode_14.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/optional:959:27: note: 'value' has been explicitly marked unavailable here
    constexpr value_type& value() &
                          ^

It seems like macOS does not fully support the std::optional standard. So that I wanna replace std::optional with Poco::Optional.

See also: https://github.com/octobanana/peaclock/issues/2

siren186 avatar Aug 23 '24 01:08 siren186

The issue was solved by requesting newer macOS target. #4624

matejk avatar Aug 30 '24 12:08 matejk