Program Listing for File applicator.hpp

Return to documentation for file (cosm/controller/operations/applicator.hpp)

#pragma once

/*******************************************************************************
 * Includes
 ******************************************************************************/
#include "cosm/cosm.hpp"

/*******************************************************************************
 * Namespaces/Decls
 ******************************************************************************/
namespace cosm::controller::operations {

/*******************************************************************************
 * Class Definitions
 ******************************************************************************/
template<class TBaseController,
         template <class TDerivedController, class...> class TOperation,
         class ...Args>
class applicator {
 public:
  explicit applicator(TBaseController* const c) : m_controller(c) {}

  template <typename TDerivedController, typename ...OpArgs>
  auto operator()(const TOperation<TDerivedController, Args...>& op,
                  OpArgs&& ...args) const -> decltype(op(std::declval<TDerivedController*>(), args...)) {
    return op(static_cast<TDerivedController*>(m_controller),
              std::forward<OpArgs>(args)...);
  }

 private:
  /* clang-format off */
  TBaseController* const m_controller;
  /* clang-format on */
};

} /* namespace cosm::controller::operations */