From f82ebc0d9ae7d5e6bfffb2b9c8c1ad3629cdc0e4 Mon Sep 17 00:00:00 2001 From: Eric Cousineau Date: Fri, 16 Mar 2018 04:07:09 -0400 Subject: [PATCH 1/3] detail/inference: Add rudimentary function signature inference utilities --- include/pybind11/detail/inference.h | 141 ++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 include/pybind11/detail/inference.h diff --git a/include/pybind11/detail/inference.h b/include/pybind11/detail/inference.h new file mode 100644 index 0000000000..aceb5f2f61 --- /dev/null +++ b/include/pybind11/detail/inference.h @@ -0,0 +1,141 @@ +/* + pybind11/detail/inference.h -- Simple inference for generic functions + + Copyright (c) 2018 Eric Cousineau + + All rights reserved. Use of this source code is governed by a + BSD-style license that can be found in the LICENSE file. +*/ + +#pragma once + +#include "common.h" + +NAMESPACE_BEGIN(PYBIND11_NAMESPACE) +NAMESPACE_BEGIN(detail) + +// SFINAE for functors. +// N.B. This *only* distinguished between function / method pointers and +// lambda objects. It does *not* distinguish among other types. +template +using enable_if_lambda_t = enable_if_t>::value, T>; + +template +struct type_at_impl { + using type = typename type_at_impl::type; +}; + +template +struct type_at_impl { + using type = T; +}; + +// Convenient mechanism for passing sets of arguments. +template +struct type_pack { + static constexpr int size = sizeof...(Ts); + + template