// ---------------------------------------------------------------------------- // - Open3D: www.open3d.org - // ---------------------------------------------------------------------------- // Copyright (c) 2018-2023 www.open3d.org // SPDX-License-Identifier: MIT // ---------------------------------------------------------------------------- #pragma once namespace open3d { namespace utility { /// Generic functor for overloading (lambda) functions. /// See Overload(...) function on how to use it. /// /// \note In C++17, this could be simplified to: /// /// \code /// template /// struct Overloaded : Ts... { /// using Ts::operator()...; /// }; /// \endcode template struct Overloaded; template struct Overloaded : T1, Overloaded { Overloaded(T1 t1, Ts... ts) : T1(t1), Overloaded(ts...) {} using T1::operator(); using Overloaded::operator(); }; template struct Overloaded : T1 { Overloaded(T1 t1) : T1(t1) {} using T1::operator(); }; /// Overloads an arbitrary set of (lambda) functions. /// /// Example: /// /// \code /// auto Func = utility::Overload( /// [&](int i) { utility::LogInfo("Got int {}", i); }, /// [&](float f) { utility::LogInfo("Got float {}", f); }); /// /// Func(1); // Prints: Got int 1 /// Func(2.4f); // Prints: Got float 2.4 /// \endcode template Overloaded Overload(Ts... ts) { return Overloaded(ts...); } } // namespace utility } // namespace open3d