asio-tr2 icon indicating copy to clipboard operation
asio-tr2 copied to clipboard

Reconsider address_cast

Open chriskohlhoff opened this issue 10 years ago • 1 comments

One option is to go back to what asio does now, but this does not allow user extension.

Another option is to simplify address_cast by using a primary template rather than deleting it. E.g. primary template returns void and then we don't need to check that it is a valid expression in the address constructor.

chriskohlhoff avatar Feb 27 '15 10:02 chriskohlhoff

Pre-Lenexa Summary

[internet.address.cast]

Asio's original ip::address design has simple constructors and accessors:

class address
{
public:
  ...
  constexpr address(const address_v4& v4_addr) noexcept;
  constexpr address(const address_v6& v6_addr) noexcept;
  ...
  constexpr address_v4 to_v4() const;
  constexpr address_v6 to_v6() const;
};

address_cast was created to address SG4's request that the version-independent ip::address type's public interface not contain the version-specific address types.

The disadvantages of address_cast are that it makes the specification more complex and perhaps impenetrable to the casual user. It also makes some uses more verbose, e.g.:

if (ip::address_cast<ip::address_v6>(addr).is_multicast_link_local())
  ...

rather than

if (addr.to_v6().is_multicast_link_local())
  ...

The advantages of address_cast are that it makes the version-dependent types less obvious as a way of encouraging users to only use the version-independent types. It also enables extensibility to cover user-defined version-specific address types.

The question for LEWG is whether to keep address_cast or return to Asio's original design.

chriskohlhoff avatar May 05 '15 09:05 chriskohlhoff