/*************************************************************************** * Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * * Copyright (c) QuantStack * * * * Distributed under the terms of the BSD 3-Clause License. * * * * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ #ifndef XTENSOR_VECTORIZE_HPP #define XTENSOR_VECTORIZE_HPP #include #include #include "xfunction.hpp" #include "xutils.hpp" namespace xt { /*************** * xvectorizer * ***************/ template class xvectorizer { public: template using xfunction_type = xfunction...>; template , xvectorizer>::value>> xvectorizer(Func&& f); template xfunction_type operator()(E&&... e) const; private: typename std::remove_reference::type m_f; }; namespace detail { template using get_function_type = remove_class_t::operator())>; } template xvectorizer vectorize(R (*f)(Args...)); template xvectorizer vectorize(F&& f, R (*)(Args...)); // Workaround for Visual Studio 15.7.1. // Error C2668 (ambiguous call to overloaded function) mistaking a declarations // for the definition of another overload. #ifndef _MSC_VER template auto vectorize(F&& f) -> decltype(vectorize(std::forward(f), std::declval*>())); #endif /****************************** * xvectorizer implementation * ******************************/ template template inline xvectorizer::xvectorizer(Func&& f) : m_f(std::forward(f)) { } template template inline auto xvectorizer::operator()(E&&... e) const -> xfunction_type { return xfunction_type(m_f, std::forward(e)...); } template inline xvectorizer vectorize(R (*f)(Args...)) { return xvectorizer(f); } template inline xvectorizer vectorize(F&& f, R (*)(Args...)) { return xvectorizer(std::forward(f)); } template inline auto vectorize(F&& f) -> decltype(vectorize(std::forward(f), std::declval*>())) { return vectorize(std::forward(f), static_cast*>(nullptr)); } } #endif