Skip to content
Snippets Groups Projects
Visitor.h 1.31 KiB
// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
// SPDX-License-Identifier: LGPL-3.0-or-later
#pragma once

namespace ChimeraTK {

  /********************************************************************************************************************/

  /*
   * Losely based on
   * https://stackoverflow.com/questions/11796121/implementing-the-visitor-pattern-using-c-templates#11802080
   */

  /********************************************************************************************************************/

  template<typename... Types>
  class Visitor;

  /********************************************************************************************************************/

  template<typename T>
  class Visitor<T> {
   public:
    virtual void dispatch(const T& t) = 0;
  };

  /********************************************************************************************************************/

  template<typename T, typename... Types>
  class Visitor<T, Types...> : public Visitor<T>, public Visitor<Types...> {
   public:
    using Visitor<Types...>::dispatch;
    using Visitor<T>::dispatch;
  };

  /********************************************************************************************************************/

} // namespace ChimeraTK