Skip to content

The convert<T>::decode() and Node::as<T>() signature inconsistency. #506

Description

@leni536
template <typename T> inline T Node::as() const;
template <typename T> bool convert<T>::decode(const YAML::Node&, T&);

decode() needs a reference for an already constructed object's reference that it can mutate to decode the Node's contents into it. as() returns a brand new T object, it works by default constructing a T object then calling decode() on it. It is problematic if:

  • T is not default constructible.
  • It is impossible or expensive to mutate T.

I suggest to use the same signature as Node::as(). In case of an error a client can just throw an exception, preferebly TypedBadConversion. It could have the added benefit of marking the error's location more precisely if it happens at a nested subnode.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions