Boost logo

Boost :

Subject: Re: [boost] Boost review of the Convert library is ongoing
From: alex (alexhighviz_at_[hidden])
Date: 2014-05-23 07:36:55

>> 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.

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
  { }

  bool check_password(const std::string& password){}

  std::string m_encrypted;

Now I can write a converter:

struct password_converter
  void operator()(const std::string& in,
boost::optional<password_encryption>& out)
    try {
       out = password_encryption(in);
    } catch(...) {
       out = boost::none;

Boost list run by bdawes at, gregod at, cpdaniel at, john at