Skip to content

Autodeclaring constructors for ToolHandle and DataObjectHandle

Added autodeclaring constructors (a la Gaudi::Property) to ToolHandle and DataObjectHandle.

This allow removal of constructors in most common cases, replacing them with in-header constructors, like in:

struct MyAlg: Algorithm {
  MyAlg(const std::string& s, ISvcLocator* l): Algorithm{s, l} {}

  Gaudi::Property<bool> m_flag{this, "Flag", true, "a flag"};

  ToolHandle<IMyTool> m_tool{this, "MyToolName", "MyToolType", "the tool I use"};
  PublicToolHandle<IMyOtherTool> m_pubtool{this, "MyOtherToolName",
   "MyOtherToolType", "the public tool I use"};

  DataObjectReadHandle<Tracks> m_tracks{this, "Tracks", "/Event/Rec/Tracks",
    "where I get tracks from"};
  DataObjectWriteHandle<Vertices> m_tracks{this, "Vertices", "/Event/Rec/Vertices",
    "where I store vertices"};
};

Ideally the constructor should be just inherited from the base class with using Algorithm::Algorithm;, but that does not work is one of the data members does not have a default constructor. This, for example, does not compile:

struct Base {
  Base(int) {}
};
struct NonTrivial {
  NonTrivial(int) {}
};
struct Derived: Base {
  using Base::Base;
  NonTrivial d{10};
};
int main() {
  Derived{42};
}

(@graven, any idea?)

Edited by Marco Clemencic

Merge request reports