overloaded.h raw

   1  // Copyright (c) 2021-present The Limenka developers
   2  // Distributed under the MIT software license, see the accompanying
   3  // file COPYING or http://www.opensource.org/licenses/mit-license.php.
   4  
   5  #ifndef LIMENKA_UTIL_OVERLOADED_H
   6  #define LIMENKA_UTIL_OVERLOADED_H
   7  
   8  namespace util {
   9  //! Overloaded helper for std::visit. This helper and std::visit in general are
  10  //! useful to write code that switches on a variant type. Unlike if/else-if and
  11  //! switch/case statements, std::visit will trigger compile errors if there are
  12  //! unhandled cases.
  13  //!
  14  //! Implementation comes from and example usage can be found at
  15  //! https://en.cppreference.com/w/cpp/utility/variant/visit#Example
  16  template<class... Ts> struct Overloaded : Ts... { using Ts::operator()...; };
  17  
  18  //! Explicit deduction guide (not needed after clang-17)
  19  template<class... Ts> Overloaded(Ts...) -> Overloaded<Ts...>;
  20  } // namespace util
  21  
  22  #endif // LIMENKA_UTIL_OVERLOADED_H
  23