From 004c48c0d8c943f366b94651e5a75f5e568f8a57 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Mon, 17 Sep 2018 23:39:37 +0200 Subject: [PATCH] common: Provide helper for getting member function traits Add a new header funchelpers.h that contains helpers for dealing with member function traits. MemberFunction provides the class, return and argument types of the given Callable, as well as a compatible std::function type. --- src/common/CMakeLists.txt | 1 + src/common/funchelpers.h | 55 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 src/common/funchelpers.h diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 1683d266..90f64e9a 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -18,6 +18,7 @@ target_sources(${TARGET} PRIVATE eventmanager.cpp expressionmatch.cpp # expressionmatchtests.cpp + funchelpers.h highlightrulemanager.cpp identity.cpp ignorelistmanager.cpp diff --git a/src/common/funchelpers.h b/src/common/funchelpers.h new file mode 100644 index 00000000..6c7aeb63 --- /dev/null +++ b/src/common/funchelpers.h @@ -0,0 +1,55 @@ +/*************************************************************************** + * Copyright (C) 2005-2018 by the Quassel Project * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) version 3. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#pragma once + +#include +#include + +namespace detail { + +/// @cond DOXYGEN_CANNOT_PARSE_THIS + +// Primary template +template +struct FuncHelper : public FuncHelper {}; + +// Overload for member function with const call operator +template +struct FuncHelper : public FuncHelper {}; + +// Overload for member function with non-const call operator +template +struct FuncHelper { + using ClassType = C; + using FunctionType = std::function; + using ReturnType = R; + using ArgsTuple = std::tuple; +}; + +/// @endcond + +} // detail + +/** + * Provides traits for the given callable. + */ +template +using MemberFunction = detail::FuncHelper; -- 2.20.1