alex
The benefit is that it defers initialization and thus passes that responsibility from the generic function to the specific converters.
Let's try staying with mainstream usage examples meaningful for the majority of users. I'll unlikely be persuaded by an esoteric academic (even a real but corner-case) example that will have negative impact on the real users. Thoughts?..
The convert contract you are proposing is quite abstract, so I think academic arguments are relevant. But your question can be translated to: are there real examples of classes that are expensive to construct but cheap to move? Moreover, these classes need to be potential candidates for being converted to.
The example you have been using is encryption. Consider the following class for an encrypted password:
struct encrypted_password { encrypted_password(const std::string& password) { // connect to random number device // do all kinds of arithmetic to encrypt // send email to NSA // m_encrypted will have a minimum size of 128. } encrypted_password (password_encryption&& rhs) : m_encrypted (std::move(rhs.m_encrypted)) { }
bool check_password(const std::string& password){}
private: std::string m_encrypted; };
Now I can write a converter:
struct password_converter { void operator()(const std::string& in, boost::optional
& out) { try { out = password_encryption(in); } catch(...) { out = boost::none; } } }; _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost